Open following file in a Terminal (Ctrl+Alt+t)
$ sudo gedit /etc/init.d/tomcat (on Cloud server $ sudo nano /etc/init.d/tomcat)
Add following lines in the file,
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat9
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
start() {
sh /opt/tomcat/bin/startup.sh
}
stop() {
sh /opt/tomcat/bin/shutdown.sh
}
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac
save and close the file.
Apply the following commands too;
sudo chmod +x /etc/init.d/tomcat
sudo update-rc.d tomcat defaults
Start Tomcat server,
sudo service tomcat start
Now you can start and stop Tomcat server using the following commands;
sudo service tomcat start
sudo service tomcat stop
sudo service tomcat restart
$ sudo gedit /etc/init.d/tomcat (on Cloud server $ sudo nano /etc/init.d/tomcat)
Add following lines in the file,
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat9
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
start() {
sh /opt/tomcat/bin/startup.sh
}
stop() {
sh /opt/tomcat/bin/shutdown.sh
}
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac
save and close the file.
Apply the following commands too;
sudo chmod +x /etc/init.d/tomcat
sudo update-rc.d tomcat defaults
Start Tomcat server,
sudo service tomcat start
Now you can start and stop Tomcat server using the following commands;
sudo service tomcat start
sudo service tomcat stop
sudo service tomcat restart