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.

137 lines
4.0 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
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: shadowsocks-libev
  4. # Required-Start: $network $local_fs $remote_fs
  5. # Required-Stop: $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: lightweight secured scoks5 proxy
  9. # Description: Shadowsocks-libev is a lightweight secured
  10. # socks5 proxy for embedded devices and low end boxes.
  11. #
  12. ### END INIT INFO
  13. # Author: Max Lv <max.c.lv@gmail.com>
  14. # PATH should only include /usr/ if it runs after the mountnfs.sh script
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. DESC=shadowsocks-libev # Introduce a short description here
  17. NAME=shadowsocks-libev # Introduce the short server's name here
  18. DAEMON=/usr/bin/ss-server # Introduce the server's location here
  19. DAEMON_ARGS="" # Arguments to run the daemon with
  20. PIDFILE=/var/run/$NAME/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. # Exit if the package is not installed
  23. [ -x $DAEMON ] || exit 0
  24. # Read configuration variable file if it is present
  25. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  26. [ "$START" = "yes" ] || exit 0
  27. : ${USER:="root"}
  28. : ${GROUP:="root"}
  29. # Load the VERBOSE setting and other rcS variables
  30. . /lib/init/vars.sh
  31. # Define LSB log_* functions.
  32. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  33. . /lib/lsb/init-functions
  34. #
  35. # Function that starts the daemon/service
  36. #
  37. do_start()
  38. {
  39. # Modify the file descriptor limit
  40. ulimit -n ${MAXFD}
  41. # Take care of pidfile permissions
  42. mkdir /var/run/$NAME 2>/dev/null || true
  43. chown "$USER:$GROUP" /var/run/$NAME
  44. # Return
  45. # 0 if daemon has been started
  46. # 1 if daemon was already running
  47. # 2 if daemon could not be started
  48. start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid root:$GROUP --exec $DAEMON --test > /dev/null \
  49. || return 1
  50. start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid root:$GROUP --exec $DAEMON -- \
  51. -c "$CONFFILE" -a "$USER" -u -f $PIDFILE $DAEMON_ARGS \
  52. || return 2
  53. }
  54. #
  55. # Function that stops the daemon/service
  56. #
  57. do_stop()
  58. {
  59. # Return
  60. # 0 if daemon has been stopped
  61. # 1 if daemon was already stopped
  62. # 2 if daemon could not be stopped
  63. # other if a failure occurred
  64. start-stop-daemon --stop --quiet --retry=KILL/5 --pidfile $PIDFILE --exec $DAEMON
  65. RETVAL="$?"
  66. [ "$RETVAL" = 2 ] && return 2
  67. # Wait for children to finish too if this is a daemon that forks
  68. # and if the daemon is only ever run from this initscript.
  69. # If the above conditions are not satisfied then add some other code
  70. # that waits for the process to drop all resources that could be
  71. # needed by services started subsequently. A last resort is to
  72. # sleep for some time.
  73. start-stop-daemon --stop --quiet --oknodo --retry=KILL/5 --exec $DAEMON
  74. [ "$?" = 2 ] && return 2
  75. # Many daemons don't delete their pidfiles when they exit.
  76. rm -f $PIDFILE
  77. return "$RETVAL"
  78. }
  79. case "$1" in
  80. start)
  81. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
  82. do_start
  83. case "$?" in
  84. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  85. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  86. esac
  87. ;;
  88. stop)
  89. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  90. do_stop
  91. case "$?" in
  92. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  93. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  94. esac
  95. ;;
  96. status)
  97. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  98. ;;
  99. restart|force-reload)
  100. log_daemon_msg "Restarting $DESC" "$NAME"
  101. do_stop
  102. case "$?" in
  103. 0|1)
  104. do_start
  105. case "$?" in
  106. 0) log_end_msg 0 ;;
  107. 1) log_end_msg 1 ;; # Old process is still running
  108. *) log_end_msg 1 ;; # Failed to start
  109. esac
  110. ;;
  111. *)
  112. # Failed to stop
  113. log_end_msg 1
  114. ;;
  115. esac
  116. ;;
  117. *)
  118. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  119. exit 3
  120. ;;
  121. esac
  122. :