Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. BIN=/usr/local/bin/kcptun
  4. TUNBASE=1000
  5. CFG_PATH=/etc/kcptun
  6. LOG_PATH=/var/log
  7.  
  8. do_clean_work() {
  9. for f in $(ls $CFG_PATH/*.enable); do
  10. pid=$(cat $f)
  11. echo kill $pid
  12. if [ -n "$pid" ]; then
  13. kill $pid
  14. echo > $f
  15. fi
  16. done
  17. }
  18.  
  19. trap "do_clean_work; exit" HUP INT TERM EXIT
  20.  
  21. for f in $(ls $CFG_PATH/*.enable); do
  22. port=$(echo $(basename $f) | sed 's/\.enable//')
  23. logpath=$LOG_PATH"/kcptun."$port".log"
  24. let tunport=port+TUNBASE
  25. echo starting kcptun on port $port
  26. if [ -e $CFG_PATH/${port}.cfg ]; then
  27. extra_param=$(cat $CFG_PATH/${port}.cfg)
  28. else
  29. extra_param=
  30. fi
  31. $BIN -t "127.0.0.1:"$port -l ":"$tunport --log $logpath $extra_param &
  32. pid=$!
  33. echo $pid > $f
  34. done
  35.  
  36. while true; do
  37. sleep 1
  38. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement