ssrmu 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: ShadowsocksR
  4. # Required-Start: $network $local_fs $remote_fs
  5. # Required-Stop: $network $local_fs $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Lightweight SOCKS5 proxy tool
  9. # Description: Start or stop the ShadowsocksR mudbjson server
  10. ### END INIT INFO
  11. NAME="ShadowsocksR"
  12. NAME_BIN="server.py"
  13. FOLDER="/usr/local/shadowsocksr"
  14. BIN="/usr/local/shadowsocksr/server.py"
  15. Info_font_prefix="\033[32m" && Error_font_prefix="\033[31m" && Info_background_prefix="\033[42;37m" && Error_background_prefix="\033[41;37m" && Font_suffix="\033[0m"
  16. RETVAL=0
  17. check_running(){
  18. PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" |grep -v "init.d" |grep -v "service" |awk '{print $2}'`
  19. if [[ ! -z ${PID} ]]; then
  20. return 0
  21. else
  22. return 1
  23. fi
  24. }
  25. do_start(){
  26. check_running
  27. if [[ $? -eq 0 ]]; then
  28. echo -e "${Info_font_prefix}[Informasi]${Font_suffix} $NAME (PID ${PID}) Running..." && exit 0
  29. else
  30. cd ${FOLDER}
  31. #python_ver=$(ls /usr/bin|grep -e "^python[23]\.[1-9]\+$"|tail -1)
  32. python_ver="python"
  33. ulimit -n 512000
  34. nohup "${python_ver}" "$BIN" a >> ssserver.log 2>&1 &
  35. sleep 2s
  36. check_running
  37. if [[ $? -eq 0 ]]; then
  38. echo -e "${Info_font_prefix}[Info]${Font_suffix} $NAME Start Successfully !"
  39. else
  40. echo -e "${Error_font_prefix}[Info]${Font_suffix} $NAME Failed to Activate !"
  41. fi
  42. fi
  43. }
  44. do_stop(){
  45. check_running
  46. if [[ $? -eq 0 ]]; then
  47. kill -9 ${PID}
  48. RETVAL=$?
  49. if [[ $RETVAL -eq 0 ]]; then
  50. echo -e "${Info_font_prefix}[Info]${Font_suffix} $NAME Stopped Successfully !"
  51. else
  52. echo -e "${Error_font_prefix}[Info]${Font_suffix}$NAME Failed to Stop !"
  53. fi
  54. else
  55. echo -e "${Info_font_prefix}[Info]${Font_suffix} $NAME Not Running !"
  56. RETVAL=1
  57. fi
  58. }
  59. do_status(){
  60. check_running
  61. if [[ $? -eq 0 ]]; then
  62. echo -e "${Info_font_prefix}[Info]${Font_suffix} $NAME (PID ${PID}) Running.."
  63. else
  64. echo -e "${Info_font_prefix}[Info]${Font_suffix} $NAME Not Running !"
  65. RETVAL=1
  66. fi
  67. }
  68. do_restart(){
  69. do_stop
  70. do_start
  71. }
  72. case "$1" in
  73. start|stop|restart|status)
  74. do_$1
  75. ;;
  76. *)
  77. echo "使用方法: $0 { start | stop | restart | status }"
  78. RETVAL=1
  79. ;;
  80. esac
  81. exit $RETVAL