Skip to content

Instantly share code, notes, and snippets.

@mitio
Last active August 9, 2018 14:01
Show Gist options
  • Save mitio/10004453 to your computer and use it in GitHub Desktop.
Save mitio/10004453 to your computer and use it in GitHub Desktop.
A simple init.d script for the psdash tool

Installation (on a Debian machine):

  1. Install psdash
  2. Save the contents of the init.d script in /etc/init.d/psdash and edit it to fit your OS and paths
  3. Make it exectutable: chmod a+rx /etc/init.d/psdash
  4. Run update-rc.d psdash defaults
  5. Start the daemon with /etc/init.d/psdash start

Optionally, setup a proxy pass to psdash's port (TCP 5000) and add some form of authentication there.

#!/bin/bash
#
# This script is for a Debian-based operating system.
# You might need to adjust it for your OS and needs.
# Source function library.
test -f /etc/init.d/functions && . /etc/init.d/functions
test -f /lib/lsb/init-functions && . /lib/lsb/init-functions
set -e
NAME="psdash"
DAEMON="/usr/local/bin/psdash"
LOGS_PATH="/var/log/**/*.log"
BIND_HOST="127.0.0.1"
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"
LOGFILE="/var/log/$NAME.log"
PIDFILE="/var/run/$NAME.pid"
start() {
echo -n "Starting: "
start-stop-daemon --start -m --oknodo --pidfile $PIDFILE --exec $DAEMON -- --log "$LOGS_PATH" --bind "$BIND_HOST" >> $LOGFILE 2>&1 &
echo "$NAME."
return
}
stop() {
echo -n "Shutting down: "
start-stop-daemon --stop --pidfile $PIDFILE
echo "$NAME."
return
}
status() {
PID=`cat $PIDFILE 2>/dev/null` || true
if [ ! -f $PIDFILE ] || [ -z "${PID}" ]
then
echo "${NAME} is not running"
return 3
fi
if ps "${PID}" >/dev/null 2>&1
then
echo "${NAME} is running"
return 0
else
echo "${NAME} is NOT running"
return 1
fi
}
case "$1" in
start)
status > /dev/null && status && exit 0 || true
start
sleep 1
status
;;
stop)
stop
;;
status)
status
;;
restart)
stop || true
sleep 1
start
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment