Skip to content

Instantly share code, notes, and snippets.

@fenying
Last active August 2, 2022 03:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fenying/7684afbe24f20e07201fa790aec1511c to your computer and use it in GitHub Desktop.
Save fenying/7684afbe24f20e07201fa790aec1511c to your computer and use it in GitHub Desktop.
The frp server service script /etc/init.d/frps
## File: /etc/init.d/frps
#!/bin/sh
#
# frps: FRP-Server Daemon
#
# description: FRP-Server Daemon
PID_FILE=/run/frps.pid
CONFIG_FILE=/etc/frps.ini
FRP_SERVER=/usr/local/frps/frps
start()
{
if [ ! -f $PID_FILE ]; then
echo -n $"Starting FRP server..."
nohup $FRP_SERVER -c $CONFIG_FILE < /dev/null > /dev/null 2> /dev/null &
echo $! > $PID_FILE
echo ""
else
PID=$(cat $PID_FILE)
if [ ! -f /proc/$PID/cmdline ]; then
echo -n $"Starting FRP server..."
nohup $FRP_SERVER -c $CONFIG_FILE < /dev/null > /dev/null 2> /dev/null &
echo $! > $PID_FILE
echo ""
else
echo "FRP server is already running..."
fi
fi;
}
stop()
{
if [[ -f $PID_FILE ]]; then
echo -n $"Shutting down FRP server..."
kill -9 $(cat $PID_FILE)
rm -f $PID_FILE
echo ""
else
echo "FRP server is not running..."
fi;
}
status()
{
if [ -f $PID_FILE ]; then
PID=$(cat $PID_FILE)
if [ -f /proc/$PID/cmdline ]; then
echo "FRP server is running..."
else
echo "FRP server is not running..."
rm -f $PID_FILE
fi
else
echo "FRP server is not running..."
fi;
}
[ -f $FRP_SERVER ] || exit 1
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment