Created
September 25, 2017 06:09
-
-
Save jemyzhang/3b918f9553a76a38fa5f125ea10c6132 to your computer and use it in GitHub Desktop.
service script for kcptun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BIN=/usr/local/bin/kcptun | |
TUNBASE=1000 | |
CFG_PATH=/etc/kcptun | |
LOG_PATH=/var/log | |
do_clean_work() { | |
for f in $(ls $CFG_PATH/*.enable); do | |
pid=$(cat $f) | |
echo kill $pid | |
if [ -n "$pid" ]; then | |
kill $pid | |
echo > $f | |
fi | |
done | |
} | |
trap "do_clean_work; exit" HUP INT TERM EXIT | |
for f in $(ls $CFG_PATH/*.enable); do | |
port=$(echo $(basename $f) | sed 's/\.enable//') | |
logpath=$LOG_PATH"/kcptun."$port".log" | |
let tunport=port+TUNBASE | |
echo starting kcptun on port $port | |
if [ -e $CFG_PATH/${port}.cfg ]; then | |
extra_param=$(cat $CFG_PATH/${port}.cfg) | |
else | |
extra_param= | |
fi | |
$BIN -t "127.0.0.1:"$port -l ":"$tunport --log $logpath $extra_param & | |
pid=$! | |
echo $pid > $f | |
done | |
while true; do | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment