Skip to content

Instantly share code, notes, and snippets.

@pjobson
Last active May 6, 2024 19:41
Show Gist options
  • Save pjobson/b52d8c415f2efe83b2fb097ec4790781 to your computer and use it in GitHub Desktop.
Save pjobson/b52d8c415f2efe83b2fb097ec4790781 to your computer and use it in GitHub Desktop.
glances notes
#!/bin/sh
### BEGIN INIT INFO
# Provides: glances
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start glances at boot time
# Description: Start glances at boot.
### END INIT INFO
# Author pjobson@gmail.com
# Last Modified 06 May 2023
# Files /etc/init.d/glances
# Required -- To be changed!
NAME=glances
USER=pjobson
PORT=61209
DAEMON="/usr/local/bin/glances"
DAEMON_ARGS="-w --config /home/$USER/.config/glances/glances.conf --port $PORT --bind 0.0.0.0"
PIDFile=/var/run/glances.pid
COMMON_OPTS="--quiet --chuid $USER --pidfile $PIDFile"
STOP_SIGNAL=INT
do_start(){
echo "Starting $NAME"
start-stop-daemon --start $COMMON_OPTS --make-pidfile --background --startas \
/bin/bash -- -c "exec $DAEMON $DAEMON_ARGS 2>&1"
}
do_stop(){
opt=${@:-}
start-stop-daemon --stop $COMMON_OPTS --signal $STOP_SIGNAL \
--oknodo $opt --remove-pidfile
}
do_status(){
start-stop-daemon --status $COMMON_OPTS && exit_status=$? || exit_status=$?
case "$exit_status" in
0)
echo "Program '$NAME' is running."
;;
1)
echo "Program '$NAME' is not running and the pid file exists."
;;
3)
echo "Program '$NAME' is not running."
;;
4)
echo "Unable to determine program '$NAME' status."
;;
esac
}
case "$1" in
status)
do_status
;;
start)
echo -n "Starting daemon: "$NAME
do_start
echo "."
;;
stop)
echo -n "Stopping daemon: "$NAME
do_stop
echo "."
;;
restart)
echo -n "Restarting daemon: "$NAME
do_stop --retry 30
do_start
echo "."
;;
*)
echo "Usage: "$1" {status|start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment