Recently, I encountered the challenge to run a shell script of an internal program from our team on a RedHat machine. I had to choose a solution which was easy to maintain and a well-known standard to developers.
Besides some alternative ideas, like running the script from a Jenkins job, to make it more visible or executing it in a virtual console (screen), I came to the conclusion that running the script as a service would make the program better maintainable and it can be launched at start-up. You can easily kill the program and you do not have to look after its PID (process id). You can find an example service script at Write a System V Script. Copy the shell script on the bottom to /etc/init.d/ and rename it to the name of your program, in the example below I use your-service-name.
Add the script to your services with:
chkconfig –add your-service-name
Enable the service with:
chkconfig your-service-name on
Now you can start your service with:
service your-service-name start
Other options for controlling your service are stop, restart and status. With service –status-all you can see if your service is listed.
Feel free to use this template script your-service-name.sh, which is under the WTFPL License for your own and give suggestions to improve it. Make sure you use correct permissions for your application and for the service.