Skip to content

Instantly share code, notes, and snippets.

@maicong
Last active October 23, 2017 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maicong/358938242a0c2beb069865923e9250e7 to your computer and use it in GitHub Desktop.
Save maicong/358938242a0c2beb069865923e9250e7 to your computer and use it in GitHub Desktop.
/etc/init.d/kcptun
#!/bin/bash
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
kcptun="/usr/bin/kcptun_server"
prog=$(basename $kcptun)
KCPTUN_CONF_FILE="/etc/kcptun-config.json"
start() {
[ -x $kcptun ] || exit 5
echo -n $"Starting $prog: "
nohup $kcptun -c $KCPTUN_CONF_FILE >/dev/null 2>&1 &
retval=$?
[ $retval -eq 0 ] && echo '[OK]' && return $retval
}
stop() {
echo -n $"Stopping $prog: "
pgrep $prog | xargs -r kill
retval=$?
[ $retval -eq 0 ] && echo '[OK]' && return $retval
}
restart() {
stop
sleep 1
start
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment