How to create a service on Linux
It took me a while to figure this out so I post it here in case I need to refer to it in the future.These instructions apply to linux distros which have systemd. To find out if this applies to your distro run this command:
ps -q 1 -o comm=If the output is
systemd then your distro is one with systemd, so you can continue with these instructions.
- Create a shell file called test-service or whatever in /etc/init.d/. The shell file has to follow a pattern. Have a look at /etc/init.d/mountall-bootclean.sh for a concise example which conforms to this pattern.
- Enter this command to have your service start every time the host starts.
sudo systemctl enable test-service
- Enter this command to have your service start now.
sudo systemctl start test-service
No comments:
Post a Comment