Last active
June 11, 2017 15:29
-
-
Save rmasters/2d14dddc26529a607cf8 to your computer and use it in GitHub Desktop.
Bare-bones ngrok SysV init script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: ngrok | |
# Required-Start: $local_fs $remote_fs $network $syslog $named | |
# Required-Stop: $local_fs $remote_fs $network $syslog $named | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the ngrok connection | |
# Description: starts ngrok using start-stop-daemon | |
### END INIT INFO | |
# Override these variables in /etc/sysconfig/ngrok | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/local/bin/ngrok | |
DAEMON_ARGS="" | |
NAME=`/bin/basename $DAEMON` | |
DESC=ngrok | |
PIDFILE=/var/run/ngrok.pid | |
LOCK=/var/lock/subsys/ngrok | |
LOGFILE=/var/log/ngrok | |
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME | |
. /etc/init.d/functions | |
do_start() | |
{ | |
if [ -s $PIDFILE ]; then | |
RETVAL=1 | |
echo "Already running!" | |
else | |
echo "Starting $DESC" | |
nohup $DAEMON $DAEMON_ARGS >$LOGFILE 2>&1 & | |
RETVAL=$? | |
PID=$! | |
[ $RETVAL -eq 0 ] && touch $LOCK | |
echo $PID > $PIDFILE | |
fi | |
return $RETVAL | |
} | |
do_stop() | |
{ | |
killproc -p $PIDFILE $NAME | |
RETVAL="$?" | |
echo | |
[ $RETVAL = 0 ] && rm -rf $LOCK $PIDFILE | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
echo "Stopping $DESC" | |
do_stop | |
;; | |
status) | |
if [ ! -s $PIDFILE ]; then | |
echo "Not running" | |
else | |
PID=`cat $PIDFILE` | |
if [[ -n $PID && -n "`ps -p $PID | grep $PID`" ]]; then | |
echo "Running (${PID})" | |
else | |
echo "Not running, yet ${PIDFILE} exists (stop ngrok will fix this)" | |
fi | |
fi | |
;; | |
*) | |
echo "Usage: $NAME (start|stop|status)" | |
exit 3 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment