SOURCES: socat.init (NEW), socat.sysconfig (NEW) - rel.1.9 - introduced dae...
blues
blues at pld-linux.org
Wed Feb 4 18:14:36 CET 2009
Author: blues Date: Wed Feb 4 17:14:36 2009 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- rel.1.9 - introduced daemon script with multiple tunnel support. Not
working, yet.
---- Files affected:
SOURCES:
socat.init (NONE -> 1.1) (NEW), socat.sysconfig (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/socat.init
diff -u /dev/null SOURCES/socat.init:1.1
--- /dev/null Wed Feb 4 18:14:37 2009
+++ SOURCES/socat.init Wed Feb 4 18:14:30 2009
@@ -0,0 +1,137 @@
+#!/bin/sh
+#
+# socat Start/stop the socat channell.
+#
+# chkconfig: 2345 11 89
+#
+# description: Multipurpose relay
+#
+
+# Get service config
+[ -f /etc/sysconfig/socat ] && . /etc/sysconfig/socat
+
+[ -n "$2" ] && TUNNELS="$2"
+
+# no tunnels. exit silently
+if [ -z "$TUNNELS" ]; then
+ case "$1" in
+ start|stop|restart|reload|force-reload)
+ exit 0
+ ;;
+ esac
+fi
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# check if the tunnel $1 is up
+tunlup() {
+ local tun="$1"
+ local pidfile=/var/run/socat/$tun.pid
+ local pid=$(cat $pidfile 2>/dev/null)
+ kill -0 $pid 2>/dev/null
+ return $?
+}
+
+# check if all the configured tunnels are up
+tunlsup() {
+ ret=0
+ for tun in $TUNNELS; do
+ tunlup $tun && continue
+ ret=1
+ done
+ return $ret
+}
+
+start() {
+ # Check if the service is already running?
+ if ! tunlsup; then
+ msg_starting "socat"; started
+ for tun in $TUNNELS; do
+ # Clear vars:
+ unset OPTIONS
+ unset BIADDRESS1
+ unset BIADDRESS2
+ config="/etc/socat/$tun.conf"
+ if [ ! -f "$config" ]; then
+ nls "Invalid tunnel \`%s': missing config: %s" $tun "$config"
+ fail
+ RET=1
+ else
+ show "Starting socat tunnel %s" "$tun"
+ if tunlup $tun; then
+ started
+ continue
+ fi
+
+ # include configuration:
+ . $config
+ # FIXME: check if variables are set
+ daemon --fork --pidfile /var/run/socat/$tun.pid \
+ /usr/bin/socat ${SOCAT_OPT} ${OPTIONS} \
+ ${BIADDRESS1} ${BIADDRESS2}
+ RET=$?
+ fi
+ [ $RETVAL -eq 0 ] && RETVAL=$RET
+ done
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/socat
+ else
+ msg_already_running "socat"
+ fi
+}
+
+stop() {
+ if tunlsup; then
+ # Stop daemons.
+ msg_stopping "socat"; started
+ for tun in $TUNNELS; do
+ pidfile=/var/run/socat/$tun.pid
+ [ -f "$pidfile" ] || continue
+ pid=`cat "$pidfile"`
+ show "Stopping socat tunnel %s" "$tun"; busy
+ killproc --pidfile socat/$tun.pid || err=1
+ done
+ rm -f /var/lock/subsys/socat >/dev/null 2>&1
+ else
+ msg_not_running "socat"
+ fi
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ sleep 1
+ start
+ exit $?
+ ;;
+ status)
+ nls "Configured tunnels:"
+ echo " $TUNNELS"
+ nls "Currently active tunnels:"
+ for pidfile in /var/run/socat/*.pid; do
+ [ -f "$pidfile" ] || continue
+ tun=${pidfile#/var/run/socat/}
+ tun=${tun%.pid}
+ tunlup $tun && echo -n " $tun($(cat $pidfile))"
+ done
+ echo ""
+ tunlsup
+ exit $?
+ ;;
+ *)
+ msg_usage "$0 {start|stop|restart|status}"
+ exit 3
+ ;;
+esac
+
+exit $RETVAL
+
+
================================================================
Index: SOURCES/socat.sysconfig
diff -u /dev/null SOURCES/socat.sysconfig:1.1
--- /dev/null Wed Feb 4 18:14:37 2009
+++ SOURCES/socat.sysconfig Wed Feb 4 18:14:30 2009
@@ -0,0 +1,11 @@
+# Customized settings for socat
+
+# Nice level for sysconf
+SERVICE_RUN_NICE_LEVEL="+0"
+
+# Options for all tunnels
+#SOCAT_OPT="-ly"
+
+# Tunnels to set up. For each tunnel name, there should be config file in /etc/socat
+TUNNELS="mysql"
+#TUNNELS=""
================================================================
More information about the pld-cvs-commit
mailing list