I am trying to make a linux executable as a service
I execute my program like this below
java -jar mytestprogram.jar
creates a process that runs continuously and serves REST requests. But I want to run it as a service where I can do
service mytestprogram start
service mytestprogram stop
service mytestprogram status
chkconfig mytestprogram on
etc. What is the most simple way of doing it?
That depends on your system manager
the most common way to do that on debian/ubuntu is to build an initscript and place it in
/etc/init.d
or/etc/rc/init.d
and place a script namedmytestprogram
in that.this is an example initscript:
I suggest you to look some scripts in that directory, It's simple if you know bash a little ;)
Here is a sample shell script (make sure you replace the MAT name with the name of the your application):
I create one GitHubGist with the latest version of my script and a brief explanation to help those who need it. GitHub Gist link