Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  52] [ 0]  / answers: 1 / hits: 119169  / 3 Years ago, sat, june 5, 2021, 11:05:36

I have installed Tomcat 7 on Ubuntu 12.04 LTS which runs on an Amzon EC2 instance. Now I wish tomcat should restart automatically on system reboot.



I read this blog which suggest adding below script to /etc/init.d/tomcat7:



# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

case $1 in
start)
sh /usr/share/tomcat7/bin/startup.sh
;;
stop)
sh /usr/share/tomcat7/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat7/bin/shutdown.sh
sh /usr/share/tomcat7/bin/startup.sh
;;
esac
exit 0


and issue the following commands:



sudo chmod 755 /etc/init.d/tomcat7

sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat

sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat

sudo /etc/init.d/tomcat7 restart


My Questions




  1. The tomcat7 already has script in it, where do we have to paste the suggested script?

  2. Is the suggested procedure correct?


More From » scripts

 Answers
6

Create the init script in /etc/init.d/tomcat7 with the contents as per below (your script should work too but I think this one adheres more closely to the standards).



This way Tomcat will start only after network interfaces have been configured.



Init script contents:



#!/bin/bash

### BEGIN INIT INFO
# Provides: tomcat7
# 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 /usr/share/tomcat7/bin/startup.sh
}

stop() {
sh /usr/share/tomcat7/bin/shutdown.sh
}

case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac


Change its permissions and add the correct symlinks automatically:



chmod 755 /etc/init.d/tomcat7
update-rc.d tomcat7 defaults


And from now on it will be automatically started and shut down upon entering the appropriate runlevels. You can also control it with service tomcat7 <stop|start|restart>


[#34065] Monday, June 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
issfullus

Total Points: 264
Total Questions: 126
Total Answers: 107

Location: Comoros
Member since Mon, Dec 19, 2022
1 Year ago
;