Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: PlexRequests
  4. # Required-Start: $local_fs $remote_fs $network
  5. # Required-Stop: $local_fs $remote_fs $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: PlexRequests
  9. # Description: PlexRequests for streamlined Plex sharing
  10. ### END INIT INFO
  11.  
  12.  
  13. # Documentation available at
  14. # http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
  15. # Debian provides some extra functions though
  16. . /lib/lsb/init-functions
  17.  
  18. DAEMON_NAME="PlexRequests"
  19. DAEMON_USER=root
  20. DAEMON_PATH="/usr/bin/meteor"
  21. DAEMON_OPTS=""
  22. DAEMON_PWD="/opt/plexrequests"
  23. DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
  24. DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
  25. DAEMON_NICE=0
  26. DAEMON_LOG='/var/log/plexrequests'
  27.  
  28. [ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"
  29.  
  30. do_start() {
  31. local result
  32.  
  33. pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
  34. if [ $? -eq 0 ]; then
  35. log_warning_msg "${DAEMON_NAME} is already started"
  36. result=0
  37. else
  38. log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
  39. touch "${DAEMON_LOG}"
  40. chown $DAEMON_USER "${DAEMON_LOG}"
  41. chmod u+rw "${DAEMON_LOG}"
  42. if [ -z "${DAEMON_USER}" ]; then
  43. start-stop-daemon --start --quiet --oknodo --background \
  44. --nicelevel $DAEMON_NICE \
  45. --chdir "${DAEMON_PWD}" \
  46. --pidfile "${DAEMON_PID}" --make-pidfile \
  47. --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
  48. result=$?
  49. else
  50. start-stop-daemon --start --quiet --oknodo --background \
  51. --nicelevel $DAEMON_NICE \
  52. --chdir "${DAEMON_PWD}" \
  53. --pidfile "${DAEMON_PID}" --make-pidfile \
  54. --chuid "${DAEMON_USER}" \
  55. --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
  56. result=$?
  57. fi
  58. log_end_msg $result
  59. fi
  60. return $result
  61. }
  62.  
  63. do_stop() {
  64. local result
  65.  
  66. pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
  67. if [ $? -ne 0 ]; then
  68. log_warning_msg "${DAEMON_NAME} is not started"
  69. result=0
  70. else
  71. log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
  72. killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
  73. result=$?
  74. log_end_msg $result
  75. rm "${DAEMON_PID}"
  76. fi
  77. return $result
  78. }
  79.  
  80. do_restart() {
  81. local result
  82. do_stop
  83. result=$?
  84. if [ $result = 0 ]; then
  85. do_start
  86. result=$?
  87. fi
  88. return $result
  89. }
  90.  
  91. do_status() {
  92. local result
  93. status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
  94. result=$?
  95. return $result
  96. }
  97.  
  98. do_usage() {
  99. echo $"Usage: $0 {start | stop | restart | status}"
  100. exit 1
  101. }
  102.  
  103. case "$1" in
  104. start) do_start; exit $? ;;
  105. stop) do_stop; exit $? ;;
  106. restart) do_restart; exit $? ;;
  107. status) do_status; exit $? ;;
  108. *) do_usage; exit 1 ;;
  109. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement