Systemd
Many Linux distributions (including Ubuntu) use systemd which manages system services.
(wikipedia.org)
In the following text an example service named vultrdata is used for illustrative purposes.
A service is defined in a file named like /etc/systemd/system/vultrdata.service. Unit files have a format like in this example:
1
[Unit]
2
Description=Vultr Instance Metadata Service
3
After=network.target
4
5
[Service]
6
User=vultrdata
7
WorkingDirectory=/opt/vultrdata
8
Restart=always
9
Environment=API_KEY=____________________________________
10
ExecStart=/opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata
11
12
[Install]
13
WantedBy=multi-user.target
Copied!
After creating the file in the /etc/systemd/system directory, issue this command to register it:
1
$ sudo systemctl daemon-reload
Copied!
Then you can check the status:
1
$ sudo systemctl status vultrdata
2
● vultrdata.service - Vultr Instance Data Service
3
Loaded: loaded (/etc/systemd/system/vultrdata.service; disabled; vendor preset: enabled)
4
Active: active (running) since Sun 2020-04-05 19:35:56 UTC; 1 weeks 0 days ago
5
Main PID: 19694 (vultrdata)
6
Tasks: 16 (limit: 4661)
7
CGroup: /system.slice/vultrdata.service
8
├─19496 /opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata
9
└─19509 /opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata
Copied!
Or start, stop, restart it:
1
$ sudo systemctl start vultrdata.service
2
$ sudo systemctl stop vultrdata.service
3
$ sudo systemctl restart vultrdata.service
Copied!
You can enable or disable starting the unit/service on system startup:
1
$ sudo systemctl enable vultrdata
2
$ sudo systemctl disable vultrdata
Copied!
You can see/tail all systemd logs, or just for your service (unit):
1
$ sudo journalctl -f
2
$ sudo journalctl -f -u vultrdata
Copied!
Last modified 1yr ago
Copy link