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.

136 lines
3.9 KiB

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