#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=stunnel PIDFILE="/var/run/$DAEMON-server.pid" case "$1" in ""|load|start|restart) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac is_running() { local pid [ -e "$PIDFILE" ] && read pid < "$PIDFILE" && kill -EXIT "$pid" 2> /dev/null } start() { { if [ -x "/tmp/flash/${DAEMON}-server_conf" ]; then /tmp/flash/${DAEMON}-server_conf else /mod/etc/default.$DAEMON/server_conf fi if [ -r "/tmp/flash/${DAEMON}-server.extra" ]; then cat /tmp/flash/${DAEMON}-server.extra fi if [ -r "/tmp/flash/stunnel_srvsvcs" ]; then cat /tmp/flash/stunnel_srvsvcs fi } > /mod/etc/${DAEMON}-server.conf echo -n 'Starting stunnel server...' $DAEMON /mod/etc/${DAEMON}-server.conf exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping stunnel server...' read pid < "$PIDFILE" && kill -USR1 "$pid" > /dev/null 2>&1 } case "$1" in ""|load) deffile="/mod/etc/default.$DAEMON/stunnel_srvsvcs.def" [ -r "/tmp/flash/stunnel_srvsvcs.def" ] && deffile='/tmp/flash/stunnel_srvsvcs.def' modreg file 'stunnel_srvsvcs' 'Stunnel services (srv)' 0 "$deffile" if [ "$STUNNEL_SERVERENABLED" != "yes" ]; then echo "$DEAMON server is disabled" 1>&2 exit 1; fi start ;; unload) stop modunreg file 'stunnel_srvsvcs' ;; start) start ;; stop) if ! is_running; then echo "$DAEMON is not running" >&2 exit 1 fi stop ;; restart) stop sleep 1 start ;; status) if is_running; then echo 'running' else echo 'stopped' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0