To start any java application is enough to run one using java virtual machine:
$ java -jar tcp-server.jar
But in such case the java process has got stdout, stderr, stdin associated with termital where application has been started. And if terminal will be closed all running processes will be terminated too. To run process in background without any terminal the process should be demonized. Also all demonized processes must have convenient tools to start and to stop and can handle any signal to that process.
To manage Java apps on Unix we offer to use supervisor runit. There are all necessary files to set up and turn on supervisor in distributed directory. Just copy directory runit/etc to root (/) of your server’s filesystem:
# cp -a dist/runit/etc /
Then place dirs api-server, sms-server, tcp-server to /home/java/ by copying:
$ cp -a dist/sms-server /home/java/ $ cp -a dist/api-server /home/java/ $ cp -a dist/tcp-server /home/java/
How to manage services
The following services use runit:
Here are the simplest commands to manage services
# sv start api-server
Another possible way:
# sv u api-server
In Unix system V style
# /etc/init.d/api-server start
Here are how to stop service similar to start:
# sv stop api-server
Also there are possible ways:
# sv d api-server
In Unix style
# /etc/init.d/api-server stop
Send signal USR1 to process
# sv 1 mysql
Process may going to reload its configuration when receiving such signal if it is implemented (mysql has got such functionality).
Another useful commands are:
# sv t api-server
This command is sending TERM signal to process.
How to get status of process:
# sv s api-server
Note. To work with tcp-server using sv do specify name navixyserver instead tcp-server, thus the command above looks like
# sv u navixyserver
In addition to advantages above the supervisor logging stdout and stderr into a file. In our case all logs write to /var/log/nameservice/current and automatic rotate.
More information about supervisor runit can be found on http://smarden.org/runit/