Created
July 18, 2018 16:31
-
-
Save niamtokik/beedd74b1dfd3e2277f1913437deaaef to your computer and use it in GitHub Desktop.
FreeBSD socatd service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
###################################################################### | |
# socat daemon wrapper. This script use daemon(8) command and | |
# transform a standard socat process in daemon. This script stop | |
# the service by stopping daemon supervisor instead of socat process. | |
# | |
# PROVIDE: socatd | |
# REQUIRE: network | |
# KEYWORD: socat daemon | |
# | |
###################################################################### | |
. /etc/rc.subr | |
name="socatd" | |
desc="socat daemon wrapper" | |
rcvar="socatd_enable" | |
load_rc_config ${name} | |
: ${socatd_enable="NO"} | |
: ${socatd_mode="standalone"} | |
: ${socatd_user=""} | |
: ${socatd_pidfile="/var/run/socat/socat.pid"} | |
: ${socatd_args=""} | |
command="/usr/local/bin/socat" | |
command_args=${socatd_args} | |
pidfile="/var/run/socat/socat.pid" | |
prestart_cmd="socatd_prestart" | |
start_cmd="socatd_start" | |
stop_cmd="socatd_stop" | |
daemon_cmd="/usr/sbin/daemon -P ${socatd_pidfile}.sup -p ${socatd_pidfile}" | |
socatd_prestart() { | |
if [ "${socatd_user}" ] | |
then | |
getent passwd "${socatd_user}" | |
echo "Warning: user ${socatd_user} not present, using root instead." | |
else | |
daemon_cmd="${daemon_cmd} -u ${socatd_user}" | |
fi | |
} | |
socatd_start() { | |
if [ "_${socatd_mode}" = "_loop" ] | |
then | |
${daemon_cmd} -R 1 -- ${command} ${command_args} | |
else | |
${daemon_cmd} -- ${command} ${command_args} | |
fi | |
} | |
socatd_stop() { | |
rc_pid=$(cat ${pidfile}.sup) | |
kill $sig_stop $rc_pid | |
wait_for_pids $rc_pid | |
} | |
run_rc_command "${1}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment