需要给freebsd安装frpc 然后进程守护一下=
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
CMD_PATH=/usr/local/bin/frpc
CONF=/usr/local/etc/frpc.ini
MAP_PID='/var/log/frpc.pid'
MAP_LOG='/var/log/frpc.log'
check_status()
{
PID=`cat $MAP_PID`
if [ "$PID" = "" ]; then
return 0
fi
return $PID
}
case $1 in
start)
check_status
PID=$?
[ "$PID" -ne 0 ] && echo "!!no:server is uping" && exit
${CMD_PATH} -c ${CONF} 1>$MAP_LOG 2>&1 &
echo $! > $MAP_PID && echo "ok:server is up"
;;
stop)
check_status
PID=$?
[ "$PID" -eq 0 ] && echo "!!no:server don't up" && exit
[ "$PID" -ne 0 ] && kill $PID && `: > $MAP_PID` && echo "yes:server is down"
;;
restart)
$0 stop
$0 start
;;
*)
cat << HELP
$0 {start|stop|restart}
HELP
;;
esac
把脚本写入到
/etc/rc.d/frpc
使用
/etc/rc.d/frpc start #启动
/etc/rc.d/frpc stop #停止
/etc/rc.d/frpc restart #重启
这个脚本好像更好 转载的
#!/bin/sh
# PROVIDE: frpc
# REQUIRE: LOGIN
# KEYWORD: frpc
. /etc/rc.subr
name="frpc"
rcvar=frpc_enable
load_rc_config $name
: ${frpc_enable="NO"}
: ${frpc_user="nobody"}
: ${frpc_flags="-c /usr/local/opt/frp_0.48.0_freebsd_amd64/frpc.ini"}
daemon_pidfile="var/run/frpc_daemon.pid"
pidfile="/var/run/frpc.pid"
command="/usr/local/opt/frp_0.48.0_freebsd_amd64/frpc"
start_cmd="/usr/sbin/daemon -r -R 5 -u $frpc_user -P $daemon_pidfile -p $pidfile -t $name $command $frpc_flags"
start_postcmd="${name}_poststart"
stop_cmd="${name}_stop"
frpc_poststart()
{
echo "${name}_daemon running pid `cat ${daemon_pidfile}`."
echo "${name} running pid `cat ${pidfile}`."
}
frpc_stop()
{
if [ -f "$daemon_pidfile" ]; then
pid=`cat $daemon_pidfile`
echo "Stopping pid ${pid}."
kill $pid
else
echo "${name} not running?"
fi
}
run_rc_command "$1"
Comments | NOTHING