Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

185 rindas
4.3 KiB

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: matrix-synapse
  4. # Required-Start: $local_fs $network $remote_fs $syslog
  5. # Required-Stop: $local_fs $network $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: <Enter a short description of the software>
  9. # Description: <Enter a long description of the software>
  10. # <...>
  11. # <...>
  12. ### END INIT INFO
  13. # Author: Paul "LeoNerd" Evans <paul@matrix.org>
  14. # Do NOT "set -e"
  15. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  16. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  17. DESC="matrix-synapse"
  18. NAME=matrix-synapse
  19. SCRIPTNAME=/etc/init.d/$NAME
  20. PYTHON="/usr/bin/python"
  21. CONFIGS="--config-path /etc/matrix-synapse/homeserver.yaml --config-path /etc/matrix-synapse/conf.d/"
  22. USER="matrix-synapse"
  23. SHAREDIR=/var/lib/$NAME
  24. # Exit if the package is not installed
  25. [ -f "/etc/matrix-synapse/homeserver.yaml" ] || exit 0
  26. # Read configuration variable file if it is present
  27. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  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.2-14) to ensure that this file is present
  32. # and status_of_proc is working.
  33. . /lib/lsb/init-functions
  34. get_config_key()
  35. {
  36. python -m synapse.config read "$1" $CONFIGS || return 2
  37. }
  38. #
  39. # Function that starts the daemon/service
  40. #
  41. do_start()
  42. {
  43. # Running --generate-config to create keys if any are absent.
  44. # Doesn't matter if not
  45. $PYTHON -m "synapse.app.homeserver" $CONFIGS --generate-keys || return 2
  46. # Return
  47. # 0 if daemon has been started
  48. # 1 if daemon was already running
  49. # 2 if daemon could not be started
  50. PIDFILE=`get_config_key "pid_file"`
  51. RETVAL=$?
  52. if [ "$RETVAL" != 0 ]; then
  53. return $RETVAL
  54. fi
  55. if [ -r "$PIDFILE" ]; then
  56. kill -0 `cat $PIDFILE` && return 1
  57. fi
  58. export PYTHONPATH
  59. # Create the PID file so that synapse can write to it as nonroot
  60. touch $PIDFILE
  61. chown $USER:nogroup $PIDFILE
  62. chown $USER:nogroup $SHAREDIR/media/
  63. chown $USER:nogroup $SHAREDIR/uploads/
  64. start-stop-daemon --start --pidfile $PIDFILE --chuid $USER \
  65. --exec $PYTHON -- -m "synapse.app.homeserver" $CONFIGS --daemonize || return 2
  66. return 0
  67. }
  68. #
  69. # Function that stops the daemon/service
  70. #
  71. do_stop()
  72. {
  73. # Return
  74. # 0 if daemon has been stopped
  75. # 1 if daemon was already stopped
  76. # 2 if daemon could not be stopped
  77. # other if a failure occurred
  78. PIDFILE=`get_config_key "pid_file"`
  79. RETVAL=$?
  80. if [ "$RETVAL" != 0 ]; then
  81. return $RETVAL
  82. fi
  83. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --user $USER --exec $PYTHON
  84. RETVAL="$?"
  85. [ "$RETVAL" = 2 ] && return 2
  86. # Many daemons don't delete their pidfiles when they exit.
  87. rm -f $PIDFILE
  88. return "$RETVAL"
  89. }
  90. #
  91. # Function that sends a SIGHUP to the daemon/service
  92. #
  93. do_reload() {
  94. #
  95. # If the daemon can reload its configuration without
  96. # restarting (for example, when it is sent a SIGHUP),
  97. # then implement that here.
  98. #
  99. return 1
  100. }
  101. case "$1" in
  102. start)
  103. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  104. do_start
  105. case "$?" in
  106. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  107. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  108. esac
  109. ;;
  110. stop)
  111. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  112. do_stop
  113. case "$?" in
  114. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  115. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  116. esac
  117. ;;
  118. status)
  119. PIDFILE=`get_config_key "pid_file"`
  120. RETVAL=$?
  121. if [ "$RETVAL" != 0 ]; then
  122. return $RETVAL
  123. fi
  124. status_of_proc -p "$PIDFILE" "$PYTHON" "$NAME" && exit 0 || exit $?
  125. ;;
  126. #reload|force-reload)
  127. #
  128. # If do_reload() is not implemented then leave this commented out
  129. # and leave 'force-reload' as an alias for 'restart'.
  130. #
  131. #log_daemon_msg "Reloading $DESC" "$NAME"
  132. #do_reload
  133. #log_end_msg $?
  134. #;;
  135. restart|force-reload)
  136. #
  137. # If the "reload" option is implemented then remove the
  138. # 'force-reload' alias
  139. #
  140. log_daemon_msg "Restarting $DESC" "$NAME"
  141. do_stop
  142. case "$?" in
  143. 0|1)
  144. do_start
  145. case "$?" in
  146. 0) log_end_msg 0 ;;
  147. 1) log_end_msg 1 ;; # Old process is still running
  148. *) log_end_msg 1 ;; # Failed to start
  149. esac
  150. ;;
  151. *)
  152. # Failed to stop
  153. log_end_msg 1
  154. ;;
  155. esac
  156. ;;
  157. *)
  158. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  159. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  160. exit 3
  161. ;;
  162. esac
  163. :