Skip to content

Instantly share code, notes, and snippets.

@alvarow
Created March 3, 2016 15:25
Show Gist options
  • Save alvarow/c3466808a199692c9f6b to your computer and use it in GitHub Desktop.
Save alvarow/c3466808a199692c9f6b to your computer and use it in GitHub Desktop.
Tomcat init script - Tested on SuSE
#!/bin/sh
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $time $syslog
# Should-Start: $time
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Tomcat Daemon under /opt/tomcat
# Description: Starts Tomcat under /opt
### END INIT INFO
# cp tomcat-init.sh /etc/init.d/tomcat && chmod 755 /etc/init.d/tomcat && chkconfig tomcat on
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_failed <num> set local and overall rc status to <num><num>
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
. /etc/rc.status
# First reset status of this service
rc_reset
# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# Tomcat Init-Script
case $1 in
start)
su tomcat -s /bin/bash -c "/opt/tomcat/bin/startup.sh"
rc_status -v
;;
stop)
su tomcat -s /bin/bash -c "/opt/tomcat/bin/shutdown.sh"
rc_status -v
;;
restart)
$0 stop
sleep 3
$0 start
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 3
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment