Skip to content

Instantly share code, notes, and snippets.

@fenying

fenying/frps.sh

Last active May 18, 2021
Embed
What would you like to do?
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