I'm trying to daemonize a script. I followed a couple tutorials and came up with the following script (never done it before, just filled in a template, not sure what 345 70 30 mean):
#!/bin/bash
# parserservices Parser Services
#
# chkconfig: 345 70 30
# description: Parser Services
# processname: parserservices
# chkconfig --add parserservices
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog='ParserServices for CENTOS/UNIX'
start() {
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 1
echo -n $"Starting $prog: "
daemon --check parserservices nohup /home/centos/parserservices/start_dev_server_centos.sh &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/parserservices
return $RETVAL
}
stop() {
echo -n $"Shutting down $prog: "
killproc java
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/parserservices
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status parserservices
RETVAL=$?
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=3
esac
exit $RETVAL
This is just a test and there won't be any more java processes running, so killing java shouldn't be a problem (unless someone can provide a better alternative, this is intended to run another script that does some initialization and launches java with the Google App Engine development server).
I copied it to /etc/rc.d/init.d/parserservices
and initialized and started as shown below:
$ sudo chmod 755 /etc/rc.d/init.d/parserservices
$ sudo chkconfig --add parserservices
$ sudo systemctl daemon-reload
$ sudo service parserservices start
Starting parserservices (via systemctl): [ OK ]
But nothing gets started. When I run the script myself it all runs fine:
sudo nohup /home/centos/parserservices/start_dev_server_centos.sh &
root 21510 0.0 0.0 189372 2680 pts/1 S 21:18 0:00 sudo nohup /home/centos/parserservices/start_dev_server_centos.sh
root 21511 0.0 0.0 113116 1184 pts/1 S 21:18 0:00 /bin/bash /home/centos/parserservices/start_dev_server_centos.sh
root 21512 27.0 0.2 6619624 37596 pts/1 Sl 21:18 0:00 java -ea -cp /home/centos/gae/appengine-java-sdk-1.9.27/lib/appengine-tools-api.jar com.google.appengine.tools.KickStart com.google.appengine.tools.development.DevAppServ
root 21560 166 0.5 11041848 89188 pts/1 Sl 21:18 0:01 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java -Xmx8184m -javaagent:/home/centos/gae/appengine-java-sdk-1.9.27/lib/agent/appengine-agent.jar -Xboo
centos 21578 0.0 0.0 123356 1384 pts/1 R+ 21:18 0:00 ps au
By the way, the script's permissions:
-rwxrwxr-x. 1 centos centos 155 Jan 12 20:06 start_dev_server_centos.sh
This is the output of systemctl status parserservices
:
$ sudo systemctl status parserservices
parserservices.service - SYSV: Parser Services
Loaded: loaded (/etc/rc.d/init.d/parserservices)
Active: active (exited) since Tue 2016-01-12 21:05:06 UTC; 18h ago
Jan 12 21:05:06 curator.novalocal parserservices[21266]: Starting ParserServices for CENTOS/UNIX:
Jan 12 21:05:06 curator.novalocal parserservices[21266]: /etc/rc.d/init.d/parserservices: Usage: daemon [+/-nicelevel] {program}
Jan 12 21:05:06 curator.novalocal systemd[1]: Started SYSV: Parser Services.
Jan 12 21:10:13 curator.novalocal systemd[1]: Started SYSV: Parser Services.