v2ray 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: v2ray
  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: V2Ray proxy services
  9. # Description: V2Ray proxy services
  10. ### END INIT INFO
  11. # Acknowledgements: Isulew Li <netcookies@gmail.com>
  12. DESC=v2ray
  13. NAME=v2ray
  14. DAEMON=/usr/bin/v2ray/v2ray
  15. PIDFILE=/var/run/$NAME.pid
  16. SCRIPTNAME=/etc/init.d/$NAME
  17. DAEMON_OPTS="-config /etc/v2ray/config.json"
  18. # Exit if the package is not installed
  19. [ -x $DAEMON ] || exit 0
  20. # Read configuration variable file if it is present
  21. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  22. # Load the VERBOSE setting and other rcS variables
  23. . /lib/init/vars.sh
  24. # Define LSB log_* functions.
  25. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  26. . /lib/lsb/init-functions
  27. #
  28. # Function that starts the daemon/service
  29. #
  30. do_start()
  31. {
  32. mkdir -p /var/log/v2ray
  33. # Return
  34. # 0 if daemon has been started
  35. # 1 if daemon was already running
  36. # 2 if daemon could not be started
  37. # 3 if configuration file not ready for daemon
  38. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  39. || return 1
  40. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background -m -- $DAEMON_OPTS \
  41. || return 2
  42. # Add code here, if necessary, that waits for the process to be ready
  43. # to handle requests from services started subsequently which depend
  44. # on this one. As a last resort, sleep for some time.
  45. }
  46. #
  47. # Function that stops the daemon/service
  48. #
  49. do_stop()
  50. {
  51. # Return
  52. # 0 if daemon has been stopped
  53. # 1 if daemon was already stopped
  54. # 2 if daemon could not be stopped
  55. # other if a failure occurred
  56. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  57. RETVAL="$?"
  58. [ "$RETVAL" = 2 ] && return 2
  59. # Wait for children to finish too if this is a daemon that forks
  60. # and if the daemon is only ever run from this initscript.
  61. # If the above conditions are not satisfied then add some other code
  62. # that waits for the process to drop all resources that could be
  63. # needed by services started subsequently. A last resort is to
  64. # sleep for some time.
  65. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  66. [ "$?" = 2 ] && return 2
  67. # Many daemons don't delete their pidfiles when they exit.
  68. rm -f $PIDFILE
  69. return "$RETVAL"
  70. }
  71. #
  72. # Function that sends a SIGHUP to the daemon/service
  73. #
  74. do_reload() {
  75. #
  76. # If the daemon can reload its configuration without
  77. # restarting (for example, when it is sent a SIGHUP),
  78. # then implement that here.
  79. #
  80. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
  81. return 0
  82. }
  83. case "$1" in
  84. start)
  85. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
  86. do_start
  87. case "$?" in
  88. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  89. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  90. esac
  91. ;;
  92. stop)
  93. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  94. do_stop
  95. case "$?" in
  96. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  97. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  98. esac
  99. ;;
  100. status)
  101. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  102. ;;
  103. reload|force-reload)
  104. #
  105. # If do_reload() is not implemented then leave this commented out
  106. # and leave 'force-reload' as an alias for 'restart'.
  107. #
  108. log_daemon_msg "Reloading $DESC" "$NAME"
  109. do_reload
  110. log_end_msg $?
  111. ;;
  112. restart|force-reload)
  113. #
  114. # If the "reload" option is implemented then remove the
  115. # 'force-reload' alias
  116. #
  117. log_daemon_msg "Restarting $DESC" "$NAME"
  118. do_stop
  119. case "$?" in
  120. 0|1)
  121. do_start
  122. case "$?" in
  123. 0) log_end_msg 0 ;;
  124. 1) log_end_msg 1 ;; # Old process is still running
  125. *) log_end_msg 1 ;; # Failed to start
  126. esac
  127. ;;
  128. *)
  129. # Failed to stop
  130. log_end_msg 1
  131. ;;
  132. esac
  133. ;;
  134. *)
  135. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  136. echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart|force-reload}" >&2
  137. exit 3
  138. ;;
  139. esac