Run socat as a SysV service to write TCP stream contents to a file
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: foo | |
# Defalt-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Description: Writes TCP on port 8725 to a file | |
### END INIT INFO | |
source /etc/rc.d/init.d/functions | |
start() { | |
/usr/sbin/daemonize \ | |
-u foo \ | |
-p /var/run/foo.pid \ | |
-l /var/lock/subsys/foo \ | |
/usr/bin/socat -u \ | |
TCP4-LISTEN:8725,reuseaddr,fork \ | |
OPEN:/var/log/foo.log,creat,append | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
killproc foo | |
;; | |
status) | |
status foo | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment