How to Use Systemd to Keep Programs Running ?Linux Tutorials
Systemd manages these services in
unit files like this.
[Unit] Description=Some Really Important Service [Service] Type=simple WorkingDirectory=/root ExecStart=/root/my_program.sh [Install] WantedBy=multi-user.target
The program that will start is.
#!/usr/bin/env bash while true; do echo 'service is working' sleep 3 done
If you don’t want to use this line
#!/usr/bin/env bash, then you should make sure to specify what is the program is dedicated to execute the script like this.
If you want to execute this service, you should store it in
/etc/systemd/system/. You can copy the unit file to that directory, or symlink it.
Now you can
disable the service.
|start the service or run it|
|stop the service|
|make the service start automatically on the system boot|
|the serice will not start when the system boot|
To see what the services output, run this command.
If we want to know the current status of the service, use this command.
systemctl status sample
If you want to list all services on your system, run this command.
Want to know more information about services and their units, read more here.