Advertisement
Guest User

Untitled

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