I wrote the following script /etc/init.d/tomcat
in order to manage my manually-installed Apache Tomcat server as a service:
#!/bin/sh
#
# /etc/init.d/tomcat -- startup script for the Tomcat servlet engine
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
export CATALINA_HOME="/opt/tomcat"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
Then, I executed the following commands and now the service is working fine:
sudo chmod 755 /etc/init.d/tomcat
sudo update-rc.d tomcat defaults
sudo systemctl daemon-reload
As you can see, the tomcat
script supports only start
and stop
, no restart
case is present, but I noticed that if I launch sudo service tomcat restart
, the service is effectively restarted. How is it possible? I find no way to see which commands are issued behind the scenes.
As a counterproof, if I issue sudo service tomcat qwerty
I get Usage: /etc/init.d/tomcat {start|stop}
Thanks.