Skip to content

Instantly share code, notes, and snippets.

@rbellamy
Forked from THemming/gist:2173037
Last active December 17, 2015 17:29
Show Gist options
  • Save rbellamy/5646611 to your computer and use it in GitHub Desktop.
Save rbellamy/5646611 to your computer and use it in GitHub Desktop.
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script - used by aergo-server
# processname: aergo
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/aergo
# chkconfig --add /etc/init.d/aergo
# chkconfig aergo on
#
# Usage: (as root)
# service aergo start
# service aergo stop
# service aergo status
#
# Remember, you need python 2.6 to run the aergo command, it doesn't come standard with RedHat/Centos 5.5
# Also, you may want to temporarily remove the >/dev/null for debugging purposes
# Path to the JVM
JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
# User running the process
USER=root
# Application information
APPLICATION_NAME=aergo
APPLICATION_PATH=/opt/aergo-server
APPLICATION_START=${APPLICATION_PATH}/target/start
APPLICATION_PIDFILE=${APPLICATION_PATH}/RUNNING_PID
APPLICATION_LOCKFILE=/var/lock/subsys/aergo
# source function library
. /etc/init.d/functions
RETVAL=0
start() {
[ -x ${APPLICATION_START} ] || exit 5
echo -n "Starting ${APPLICATION_NAME}: "
su - ${USER} -c "${APPLICATION_START} >/dev/null &"
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
touch ${APPLICATION_LOCKFILE}
echo_success
else
echo_failure
fi
echo
}
stop() {
echo -n "Shutting down ${APPLICATION_NAME}: "
if test -f "${APPLICATION_PIDFILE}"; then
APPLICATION_PID=`cat ${APPLICATION_PIDFILE}`
echo "Killing ${APPLICATION_PATH} with pid ${APPLICATION_PID}"
killproc -p ${APPLICATION_PIDFILE}
else
echo
fi
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
rm -f ${APPLICATION_LOCKFILE}
echo_success
else
echo_failure
fi
echo
}
restart() {
stop
sleep 10
start
}
td_status() {
status -p ${APPLICATION_PIDFILE} ${APPLICATION_NAME}
}
td_status_q() {
td_status >/dev/null 2>&1
}
clean() {
rm -f ${APPLICATION_PIDFILE}
}
case "$1" in
start)
clean
td_status_q && exit 0
$1
;;
stop)
td_status_q || exit 0
$1
;;
restart|reload)
restart
;;
status)
td_status
;;
clean)
clean
;;
*)
echo "Usage: $0 {start|stop|restart|status|clean}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment