Skip to content

Instantly share code, notes, and snippets.

@yiichou
Last active June 21, 2017 06:40
Show Gist options
  • Save yiichou/1be8b15b1b41bf0ce2e9d939866bbfec to your computer and use it in GitHub Desktop.
Save yiichou/1be8b15b1b41bf0ce2e9d939866bbfec to your computer and use it in GitHub Desktop.
ngrokd manager shell
#!/bin/bash
# These setting need you to set.
TLSKEY=/path/to/your/domain.key
TLSCRT=/path/to/your/domain.crt
DOMAIN=your.domain
ADDR=listen_ip_or_empty
LOGFILE=/data/logs/ngrokd.log
PIDFILE=/var/run/ngrokd.pid
DESC=ngrokd
# you should use /lib/init.d/functions in centos
. /lib/lsb/init-functions
do_start()
{
if [ -s $PIDFILE ]; then
RETVAL=1
echo "Already running!"
else
echo "Starting $DESC"
# you need to modify the command as you needing
nohup ngrokd -tlsKey=$TLSKEY -tlsCrt=$TLSCRT -domain=$DOMAIN -httpAddr=$ADDR:80 -httpsAddr= -log=$LOGFILE -log-level=INFO >/dev/null 2>&1 &
RETVAL=$?
PID=$!
[ $RETVAL -eq 0 ] && echo $PID > $PIDFILE
sleep 0.5 && chmod 755 $LOGFILE
fi
return $RETVAL
}
do_stop()
{
killproc -p $PIDFILE ngrokd
RETVAL="$?"
echo
[ $RETVAL = 0 ] && rm -rf $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 ngrokd will fix this)"
fi
fi
;;
*)
echo "Usage: ngrokd (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