我在sysVinit的debian 7.2上将socat与以下init脚本一起使用。它完美地工作:
#!/bin/bash
DESC=socat
DAEMON=/usr/bin/socat
LIB=/usr/lib/socat
SOCAT_ARGS="-d -d -lf /var/log/socat.log"
[ ! -f /etc/default/socat.conf ] || . /etc/default/socat.conf
. /lib/lsb/init-functions
PATH=/bin:/usr/bin:/sbin:/usr/sbin
[ -x $DAEMON ] || exit 0
#
# Try to increase the # of filedescriptors we can open.
#
maxfds () {
[ -n "$SOCAT_MAXFD" ] || return
[ -f /proc/sys/fs/file-max ] || return 0
[ $SOCAT_MAXFD -le 4096 ] || SQUID_MAXFD=4096
global_file_max=`cat /proc/sys/fs/file-max`
minimal_file_max=$(($SOCAT_MAXFD + 4096))
if [ "$global_file_max" -lt $minimal_file_max ]
then
echo $minimal_file_max > /proc/sys/fs/file-max
fi
ulimit -n $SOCAT_MAXFD
}
start_socat() {
start-stop-daemon --quiet --start \
--pidfile /var/run/socat.$NAME.pid \
--background --make-pidfile \
--exec $DAEMON -- $SOCAT_ARGS $ARGS < /dev/null
}
stop_socat() {
start-stop-daemon --stop --quiet --pidfile /var/run/socat.$NAME.pid --exec $DAEMON
rm -f /var/run/socat.$NAME.pid
}
start () {
echo "Starting $DESC:"
maxfds
umask 027
cd /tmp
if test "x$AUTOSTART" = "xnone" -o -z "x$AUTOSTART" ; then
echo "Autostart disabled."
exit 0
fi
for NAME in $AUTOSTART ; do
ARGS=`eval echo \\\$SOCAT_$NAME`
echo $ARGS
start_socat
echo " $NAME $ARGS"
done
return $?
}
stop () {
echo -n "Stopping $DESC:"
for PIDFILE in `ls /var/run/socat.*.pid 2> /dev/null`; do
NAME=`echo $PIDFILE | cut -c16-`
NAME=${NAME%%.pid}
stop_socat
echo -n " $NAME"
done
}
case "$1" in
start)
log_daemon_msg "Starting socat" "socat"
if start ; then
log_end_msg $?
else
log_end_msg $?
fi
;;
stop)
log_daemon_msg "Stopping socat" "socat"
if stop ; then
log_end_msg $?
else
log_end_msg $?
fi
;;
reload|force-reload|restart)
log_daemon_msg "Restarting socat" "socat"
stop
if start ; then
log_end_msg $?
else
log_end_msg $?
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart}"
exit 3
;;
esac
exit 0
但是,在升级到debian 7.4之后,系统更改为systemd。因此,为了在systemd上运行相同的脚本,我添加了包装/etc/init.d/socat脚本的服务:
[Unit]
Description=Socat
[Service]
ExecStart=/etc/init.d/socat start
ExecStop=/etc/init.d/socat stop
[Install]
WantedBy=multi-user.target
当我启动该服务时,它已启动但直接停止:
已加载:已加载(/usr/lib/systemd/system/socat.service;已启用)
活动:自2014年4月18日星期五14:09:46 +0200起处于非活动状态(已死);4秒钟前进程:5334 ExecStart = / etc / init.d / socat启动(代码=已退出,状态= 0 /成功)CGroup:名称= systemd:/system/socat.service
我想念什么吗?