At times you create a script and then you want to have the scripts controlled by systemd or in some cases you wish to have the scripts getting restarted by itself when it is killed due to some reason. In such cases systemd in Linux helps to configure services which can be managed. To do so follow the following steps.
cd /etc/systemd/system
[Unit]
Description=<description about this service>
[Service]
User=<user e.g. root>
WorkingDirectory=<directory_of_script e.g. /root>
ExecStart=<script which needs to be executed>
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start your-service.service
sudo systemctl status example.service
sudo systemctl enable example.service
sudo systemctl disable example.service
Article Number: 715
Posted: Mon, Dec 7, 2020 8:38 PM
Last Updated: Mon, Dec 7, 2020 8:38 PM
Online URL: http://kb.ictbanking.net/article.php?id=715