You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/bin/bash
  2. #
  3. # Script to run Shadowsocks in daemon mode at boot time.
  4. # ScriptAuthor: icyboy
  5. # Revision 1.0 - 14th Sep 2013
  6. #====================================================================
  7. # Run level information:
  8. # chkconfig: 2345 99 99
  9. # Description: lightweight secured scoks5 proxy
  10. # processname: ss-server
  11. # Author: Max Lv <max.c.lv@gmail.com>;
  12. # Run "/sbin/chkconfig --add shadowsocks" to add the Run levels.
  13. #====================================================================
  14. #====================================================================
  15. # Paths and variables and system checks.
  16. # Source function library
  17. . /etc/rc.d/init.d/functions
  18. # Check that networking is up.
  19. #
  20. [ ${NETWORKING} ="yes" ] || exit 0
  21. # Daemon
  22. NAME=shadowsocks-server
  23. DAEMON=/usr/local/bin/ss-server
  24. # Path to the configuration file.
  25. #
  26. CONF=/etc/shadowsocks/config.json
  27. #USER="nobody"
  28. #GROUP="nobody"
  29. # Take care of pidfile permissions
  30. mkdir /var/run/$NAME 2>/dev/null || true
  31. #chown "$USER:$GROUP" /var/run/$NAME
  32. # Check the configuration file exists.
  33. #
  34. if [ ! -f $CONF ] ; then
  35. echo "The configuration file cannot be found!"
  36. exit 0
  37. fi
  38. # Path to the lock file.
  39. #
  40. LOCK_FILE=/var/lock/subsys/shadowsocks
  41. # Path to the pid file.
  42. #
  43. PID=/var/run/$NAME/pid
  44. #====================================================================
  45. #====================================================================
  46. # Run controls:
  47. RETVAL=0
  48. # Start shadowsocks as daemon.
  49. #
  50. start() {
  51. if [ -f $LOCK_FILE ]; then
  52. echo "$NAME is already running!"
  53. exit 0
  54. else
  55. echo -n $"Starting ${NAME}: "
  56. #daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null"
  57. daemon $DAEMON -c $CONF -f $PID
  58. fi
  59. RETVAL=$?
  60. [ $RETVAL -eq 0 ] && success
  61. echo
  62. [ $RETVAL -eq 0 ] && touch $LOCK_FILE
  63. return $RETVAL
  64. }
  65. # Stop shadowsocks.
  66. #
  67. stop() {
  68. echo -n $"Shutting down ${NAME}: "
  69. killproc -p ${PID}
  70. RETVAL=$?
  71. [ $RETVAL -eq 0 ]
  72. rm -f $LOCK_FILE
  73. rm -f ${PID}
  74. echo
  75. return $RETVAL
  76. }
  77. # See how we were called.
  78. case "$1" in
  79. start)
  80. start
  81. ;;
  82. stop)
  83. stop
  84. ;;
  85. restart)
  86. stop
  87. start
  88. ;;
  89. condrestart)
  90. if [ -f $LOCK_FILE ]; then
  91. stop
  92. start
  93. RETVAL=$?
  94. fi
  95. ;;
  96. status)
  97. status $DAEMON
  98. RETVAL=$?
  99. ;;
  100. *)
  101. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  102. RETVAL=1
  103. esac
  104. exit $RETVAL