Skip to content

Instantly share code, notes, and snippets.

@SteelPangolin
Last active January 20, 2016 19:51
Show Gist options
  • Save SteelPangolin/72771e5a1f9b40401625 to your computer and use it in GitHub Desktop.
Save SteelPangolin/72771e5a1f9b40401625 to your computer and use it in GitHub Desktop.
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