MINOR: init: Review RH/CentOS init script

This is an update of the init scripts originally written by Andre
Krajnik. It is quite similar to other init scripts brought by common
packages in RH/CentOS. This commit also introduces a pretty straight
forward sysconfig file.
This commit is contained in:
Julien Thomas 2013-08-26 21:00:51 +02:00
parent 569c71f6b1
commit 5ae9ba184c
2 changed files with 76 additions and 41 deletions

View File

@ -1,56 +1,56 @@
#!/bin/bash #!/bin/bash
# #
# /etc/rc.d/init.d/sslh # sslh Startup script for the SSL/SSH multiplexer
# sslh This shell script takes care of starting and stopping
# sslh - a daemon switching incoming connection between SSH and SSL/HTTPS servers
# #
# Author: Andre Krajnik akrajnik@gmail.com # chkconfig: - 13 87
# 2010-03-20 # description: Sslh accepts connections on specified ports, and forwards
# them further based on tests performed on the first data
# packet sent by the remote client.
# processname: sslh
# config: /etc/sslh.cfg
# config: /etc/sysconfig/sslh
# pidfile: /var/run/sslh/sslh.pid
# #
# # Authors:
# chkconfig: 2345 13 87 # Andre Krajnik akrajnik@gmail.com - 2010-03-20
# # Julien Thomas julthomas@free.fr - 2013-08-25
# description: sslh - a daemon switching incoming connection between SSH and SSL/HTTPS servers
# Source function library. # Source function library.
. /etc/init.d/functions . /etc/init.d/functions
# ./sslh -p 0.0.0.0:8443 -l 127.0.0.1:443 -s 127.0.0.1:22
SSLH="/usr/local/sbin/sslh"
PIDFILE="/var/run/sslh"
OPTIONS="--user nobody --pidfile $PIDFILE -p 0.0.0.0:8443 --ssl 127.0.0.1:443 --ssh 127.0.0.1:22"
if [ -f /etc/sysconfig/sslh ]; then if [ -f /etc/sysconfig/sslh ]; then
. /etc/sysconfig/sslh . /etc/sysconfig/sslh
fi fi
PROGNAME=sslh
SSLH=${SSLH:-/usr/sbin/sslh-select}
SSLH_LANG=${SSLH_LANG:-C}
CONFIG=${CONFIG:-/etc/sslh.cfg}
PIDFILE=${PIDFILE:-/var/run/sslh/sslh.pid}
LOCKFILE=${LOCKFILE:-/var/lock/subsys/sslh}
STOP_TIMEOUT=${STOP_TIMEOUT:-10}
RETVAL=0
start() { start() {
echo -n "Starting SSL-SSH-Switch: " echo -n "Starting $PROGNAME: "
if [ -f $PIDFILE ]; then LANG=$SSLH_LANG daemon --pidfile="$PIDFILE" \
PID=`cat $PIDFILE` ${SSLH_USER:+--user="${SSLH_USER}"} \
echo sslh already running: $PID "$SSLH" ${CONFIG:+-F "$CONFIG"} "$OPTIONS"
exit 2;
else
daemon $SSLH $OPTIONS
RETVAL=$? RETVAL=$?
echo echo
[ $RETVAL -eq 0 ] && touch $PIDFILE [ $RETVAL = 0 ] && touch "$LOCKFILE"
return $RETVAL return $RETVAL
fi
} }
stop() { stop() {
echo -n "Shutting down SSL-SSH-Switch: " echo -n "Stopping $PROGNAME: "
killproc -p "$PIDFILE" -d "$STOP_TIMEOUT" "$SSLH"
RETVAL=$?
echo echo
killproc sslh [ $RETVAL = 0 ] && rm -f "$LOCKFILE" "$PIDFILE"
echo
rm -f $PIDFILE
return 0
} }
# See how we were called.
case "$1" in case "$1" in
start) start)
start start
@ -59,18 +59,17 @@ case "$1" in
stop stop
;; ;;
status) status)
status sslh status -p "$PIDFILE" "$SSLH"
RETVAL=$?
;; ;;
restart) restart)
stop stop
start start
;; ;;
*) *)
echo "Usage: {start|stop|status|restart}" echo "Usage: $PROGNAME {start|stop|status|restart}"
exit 1 RETVAL=2
;; ;;
esac esac
exit $?
exit $RETVAL

View File

@ -0,0 +1,36 @@
#
# The default processing model uses select
# A fork model is also available
#
#SSLH=/usr/sbin/sslh-select
#
# If transparent mode is enabled, the following
# is needed in order to run as sslh user
#
#SSLH_USER=sslh
#setcap cap_net_bind_service,cap_net_admin=+ep $SSLH
#
# Configuration file for sslh
# Set empty to disable configuration file support
#
#CONFIG=/etc/sslh.cfg
#
# Extra option to pass on comand line
# Those can supersede configuration file settings
#
#OPTIONS=
#
# The sslh process is started by default with the C
# locale, it can be changed here
#
#SSLH_LANG=C
#
# If an alternate location is specified in configuration
# file, it needs to be reported here
#
#PIDFILE=/var/run/sslh/sslh.pid