ubuntu - start-stop-daemon and java - how to do it right? -


i'm trying run java program service. requirements are:

1) start java program on machine startup

2) restart if java program crashes

3) execute in special directory special user

sidenotes: cannot assume being java process running , dangerous run service twice accident.

far, i've tried implementing start-stop-daemon. however, application not automatically restarted when crashes (i.e., terminates non-zero exit code). guess has do, need use --background and, thus, start-stop-daemon cannot determine exit code? correct? how resolve issue properly? (i prefer solution system functionality only, easier without third party tools due security restrictions)

my current script (dummy is, same says, dummy java application sleeps forever)

#!/bin/sh ### begin init info # provides:          ci master # required-start:    $all # required-stop:     $all # should-start:      $portmap # should-stop:       $portmap # default-start:     2 3 4 5 # default-stop:      0 1 6 # x-interactive:     false # short-description: ci master # description:       ci master ### end init info  service_name="ci master" pidfile=/var/run/ci_master.pid user=ci directory=./master/ executable=/usr/bin/java arguments="dummy"  . /lib/lsb/init-functions  case "$1" in start)     log_daemon_msg "starting $service_name" "$service_name"     start-stop-daemon --pidfile $pidfile --make-pidfile --background --chuid $user --chdir /home/$user/$directory/ --startas $executable --start -- $arguments     log_daemon_msg "$service_name started" "$service_name" ;; stop)     log_daemon_msg "stopping $service_name" "$service_name"     start-stop-daemon --pidfile $pidfile --remove-pidfile --stop     log_daemon_msg "$service_name stopped" "$service_name" ;; restart|reload|force-reload)     $0 stop     sleep 1     $0 start ;; status)     start-stop-daemon --pidfile $pidfile --status     case $! in         0)             log_daemon_msg "$service_name running" "$service_name"         ;;         1)             log_daemon_msg "$service_name not running (pid file exists)" "$service_name"         ;;         2)             log_daemon_msg "$service_name not running" "$service_name"         ;;         3)             log_daemon_msg "unable determine status of $service_name" "$service_name"         ;;     esac ;; esac exit 0 

thanks in advance!

i suggest daemontools + service/chkconfig.

daemontools maybe installed on platform, or can try apt-get. restart daemon automatically in @ 5 seconds.

you can linux user manual 8 more information service/chkconfig.

hope helpful.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -