Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
glances init.d script - does not work ... yet
#! /bin/sh
### BEGIN INIT INFO
# Provides: glances
# chkconfig: 2345 80 80
# Short-Description: Start and stop the Glances server
### END INIT INFO
##############
######### from https://github.com/moumoul/scripting/blob/master/initd/glances
######### adapted a bit, e.g. to amazon default user path
##############
PATHNAME=/home/ec2-user/env/glances/bin
DESC="Glances server"
NAME=glances
DAEMON=$PATHNAME/$NAME
DAEMON_ARGS=" -s"
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
# not needed, seemingly
# SCRIPTNAME=/etc/init.d/$NAME
# perhaps this helps. it was missing from the original script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
# Source function library
INITD=/etc/rc.d/init.d
. $INITD/functions
start(){
echo -n $"Starting $NAME: "
[ -x $DAEMON ] || exit 5
daemon --pidfile ${PIDFILE} $DAEMON $DAEMON_ARGS &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${LOCKFILE} && pgrep -f $NAME > ${PIDFILE}
}
stop(){
echo -n $"Stopping $NAME: "
if [ -f $PIDFILE ] ; then
killall $NAME
RETVAL=$?
echo
else
RETVAL=2
fi
if [ $RETVAL -eq 0 ]; then
rm -f ${PIDFILE} ${LOCKFILE}
fi
}
restart(){
stop
start
}
_status(){
status -p ${PIDFILE} ${NAME}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
_status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=2
;;
esac
exit $RETVAL
@drandreaskrueger

This comment has been minimized.

Copy link
Owner Author

@drandreaskrueger drandreaskrueger commented Jan 8, 2018

see nicolargo/glances#1215 for explanations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment