Skip to content

Instantly share code, notes, and snippets.

@azilber
Created June 12, 2014 06:18
Show Gist options
  • Save azilber/430dbe1ca50724d70f54 to your computer and use it in GitHub Desktop.
Save azilber/430dbe1ca50724d70f54 to your computer and use it in GitHub Desktop.
quick and dirty Init.d for sshutout for Ubuntu (Works with 14.x)
#!/bin/sh
#
# chkconfig: 345 99 1
# description: Start and stop script for sshutout
#
### BEGIN INIT INFO
# Provides: sshutout
# Required-Start: $local_fs $network +splash_late
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: sshutout security
# Description: sshutout
### END INIT INFO
#
SSHOUT_RUNNING=1
chk_running() {
if [ "x$SSHOUT_PID" != "x" ]
then
ps -p $SSHOUT_PID >/dev/null 2>&1
if [ $? -eq 0 ]
then
SSHOUT_RUNNING=1
else
SSHOUT_RUNNING=0
fi
else
SSHOUT_RUNNING=0
fi
}
OP=${1:-"start"}
case "$OP" in
start)
echo "Starting sshutout:"
/usr/local/sbin/sshutout
if [ -d /var/lock/subsys ]
then
touch /var/lock/subsys/sshutout
fi
echo
;;
stop)
echo "Stopping sshutout:"
if [ -f "/var/run/sshutout.pid" ]
then
SSHOUT_PID=`cat /var/run/sshutout.pid`
kill $SSHOUT_PID
fi
while [ $SSHOUT_RUNNING -eq 1 ]
do
echo " waiting for program termination..."
sleep 5
chk_running
done
rm -f /var/lock/subsys/sshutout
echo
;;
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "Usage $0 {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