Tiny Tiny RSS for Docker
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

152 lines
3.9 KiB

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: tt-rss
  4. # Required-Start: $local_fs $remote_fs
  5. # Should-Start: mysql postgresql
  6. # Required-Stop: $local_fs $remote_fs
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Tiny Tiny RSS update daemon
  10. # Description: Update the Tiny Tiny RSS subscribed syndication feeds.
  11. ### END INIT INFO
  12. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="Tiny Tiny RSS update daemon"
  15. NAME=ttrss
  16. DISABLED=0
  17. FORKING=1
  18. PIDFILE=/var/www/lock/update_daemon.lock
  19. LOGFILE="/var/log/ttrss.log"
  20. # Read configuration variable file if it is present
  21. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  22. DAEMON="/var/www/update.php"
  23. DAEMON_ARGS="--daemon"
  24. if [ "$FORKING" != "0" ]; then
  25. DAEMON="/var/www/update_daemon2.php"
  26. DAEMON_ARGS=""
  27. fi
  28. LOADER=/usr/bin/php
  29. DAEMON_DIR="/var/www"
  30. SCRIPTNAME=/etc/init.d/ttrss
  31. # Exit if the package or loader is not installed
  32. [ -x "$LOADER" ] || exit 0
  33. [ -x "$DAEMON" ] || exit 0
  34. # Load the VERBOSE setting and other rcS variables
  35. . /lib/init/vars.sh
  36. # Define LSB log_* functions.
  37. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  38. . /lib/lsb/init-functions
  39. if [ "$DISABLED" != "0" -a "$1" != "stop" ]; then
  40. log_warning_msg "Not starting $DESC - edit /etc/default/tt-rss and change DISABLED to be 0.";
  41. exit 0;
  42. fi
  43. #
  44. # Function that starts the daemon/service
  45. #
  46. do_start()
  47. {
  48. if [ ! -f "$LOGFILE" ] ; then
  49. touch "$LOGFILE"
  50. chown www-data:www-data "$LOGFILE"
  51. fi
  52. # Return
  53. # 0 if daemon has been started
  54. # 1 if daemon was already running
  55. # 2 if daemon could not be started
  56. start-stop-daemon --start --background -c "www-data:www-data" --chdir "$DAEMON_DIR" --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null \
  57. || return 1
  58. start-stop-daemon --start --background -c "www-data:www-data" --chdir "$DAEMON_DIR" --pidfile "$PIDFILE" --exec "$DAEMON" --startas /bin/sh -- -c "$DAEMON $DAEMON_ARGS >> $LOGFILE 2>&1" \
  59. || return 2
  60. # Add code here, if necessary, that waits for the process to be ready
  61. # to handle requests from services started subsequently which depend
  62. # on this one. As a last resort, sleep for some time.
  63. }
  64. #
  65. # Function that stops the daemon/service
  66. #
  67. do_stop()
  68. {
  69. # Return
  70. # 0 if daemon has been stopped
  71. # 1 if daemon was already stopped
  72. # 2 if daemon could not be stopped
  73. # other if a failure occurred
  74. start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE
  75. RETVAL="$?"
  76. [ "$RETVAL" = 2 ] && return 2
  77. # Wait for children to finish too if this is a daemon that forks
  78. # and if the daemon is only ever run from this initscript.
  79. # If the above conditions are not satisfied then add some other code
  80. # that waits for the process to drop all resources that could be
  81. # needed by services started subsequently. A last resort is to
  82. # sleep for some time.
  83. start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
  84. [ "$?" = 2 ] && return 2
  85. # Many daemons don't delete their pidfiles when they exit.
  86. rm -f $PIDFILE
  87. return "$RETVAL"
  88. }
  89. case "$1" in
  90. start)
  91. log_daemon_msg "Starting $DESC" "$NAME"
  92. do_start
  93. case "$?" in
  94. 0|1) log_end_msg 0 ;;
  95. 2) log_end_msg 1 ;;
  96. esac
  97. ;;
  98. stop)
  99. log_daemon_msg "Stopping $DESC" "$NAME"
  100. do_stop
  101. case "$?" in
  102. 0|1) log_end_msg 0 ;;
  103. 2) log_end_msg 1 ;;
  104. esac
  105. ;;
  106. restart|force-reload)
  107. #
  108. # If the "reload" option is implemented then remove the
  109. # 'force-reload' alias
  110. #
  111. log_daemon_msg "Restarting $DESC" "$NAME"
  112. do_stop
  113. case "$?" in
  114. 0|1)
  115. do_start
  116. case "$?" in
  117. 0) log_end_msg 0 ;;
  118. 1) log_end_msg 1 ;; # Old process is still running
  119. *) log_end_msg 1 ;; # Failed to start
  120. esac
  121. ;;
  122. *)
  123. # Failed to stop
  124. log_end_msg 1
  125. ;;
  126. esac
  127. ;;
  128. status)
  129. status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
  130. ;;
  131. *)
  132. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
  133. exit 3
  134. ;;
  135. esac