Skip to content

Instantly share code, notes, and snippets.

@Terkwood
Forked from hoegertn/init script
Last active June 21, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Terkwood/1ee93edb6ea61cf8c2f7f1d311fcc9ca to your computer and use it in GitHub Desktop.
Save Terkwood/1ee93edb6ea61cf8c2f7f1d311fcc9ca to your computer and use it in GitHub Desktop.
stunnel init script
#!/bin/sh
#
# stunnel Start/Stop the stunnel daemons
#
# description: stunnel is a script that runs stunnel daemons
# version 1.00
#
# chkconfig: 345 40 60
#
# processname: stunnel
# pidfile: /var/run/stunnel/stunnel.pid
#
progname=stunnel
pidfile=/var/run/stunnel/stunnel.pid
do_start() {
if [ -f $pidfile ]
then
echo "$progname already running!";
exit 1;
fi
/usr/bin/stunnel /etc/stunnel/stunnel.conf
if [ $? -gt 0 ]; then
echo "Start failed with exit code $?"
exit $?;
fi
pid=`cat $pidfile`
if [ `ps --pid $pid 2> /dev/null | grep -c $pid 2> /dev/null` -eq '0' ]; then
echo "Process did not start!"
rm -f $pidfile
exit 1;
fi
echo "Started with PID: $pid"
exit 0;
}
do_stop() {
if [ -f $pidfile ]
then
pid=`cat $pidfile`
echo "Stopping $pid"
kill -s TERM $pid > /dev/null
rm -f $pidfile
count=0;
until [ `ps --pid $pid 2> /dev/null | grep -c $pid 2> /dev/null` -eq '0' ] || [ $count -gt 10 ]
do
sleep 1
let count=$count+1;
done
if [ $count -gt 10 ]; then
echo "Force stop of $progname"
kill -9 $pid
fi
echo "Stopped"
exit 0;
fi
}
do_status() {
if [ -f $pidfile ]
then
pid=`cat $pidfile`
echo "$progname is running with PID $pid"
else
echo "$progname is not running"
fi
}
case "$1" in
start) echo "Starting $progname"
do_start
;;
stop) echo "Stopping $progname"
do_stop
;;
status)
do_status
;;
*) echo "Usage: service $progname start|stop|status"
exit 1
;;
esac
exit 0
; Protocol version (all, SSLv2, SSLv3, TLSv1)
sslVersion = SSLv3
chroot = /var/run/stunnel/
setuid = nobody
;setgid = nogroup
pid = /stunnel.pid
debug = local1.info
; Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
;compression = rle
cert = /etc/stunnel/stunnel.pem
; Service-level configuration
[acceptor]
accept = 443
connect = localhost:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment