Well, I have a bunch of Tiny Tiny RSS instances running on my webhost, and I wanted a init-script that starts the update-daemons for all instances.
Now, there’s already a bunch of init scripts for Debian around (1, 2) however none of them were to my liking or did what I wanted it to do. So I ended up (yeah, I know *again*) rewriting them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
#!/bin/sh ### BEGIN INIT INFO # Provides: ttrss # Required-Start: $local_fs $remote_fs networking # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Tiny Tiny RSS update daemon # Description: Update the Tiny Tiny RSS subscribed syndication feeds. ### END INIT INFO set -e PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Tiny Tiny RSS update daemon" NAME=$(command basename "${0}") DISABLED=1 FORKING=0 # Read configuration variable file if it is present [ -r "/etc/default/${NAME}" ] && . "/etc/default/${NAME}" DAEMON_SCRIPT="update.php --daemon" if [ $FORKING -ne 0 ] ; then DAEMON_SCRIPT="update_daemon2.php" fi DAEMON=/usr/bin/php # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 [ -d "${TTRSS_PATH}" ] || exit 0 # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions if [ "$DISABLED" != "0" -a "$1" != "stop" ]; then log_warning_msg "Not starting $DESC - edit /etc/default/tt-rss and change DISABLED to be 0."; exit 0; fi # Function that starts the daemon/service do_start() { for dir in ${TTRSS_PATH}/*; do INSTANCE_NAME=${dir##*/} start-stop-daemon --start --make-pidfile --background --quiet --chuid "${TTRSS_USERID}" --group "${TTRSS_GROUPID}" --chdir "${dir}" --pidfile "${TTRSS_PIDDIR}/ttrss-${INSTANCE_NAME}.pid" --exec "${DAEMON}" --test >/dev/null || return 1 start-stop-daemon --start --make-pidfile --background --quiet --chuid "${TTRSS_USERID}" --group "${TTRSS_GROUPID}" --chdir "${dir}" --pidfile "${TTRSS_PIDDIR}/ttrss-${INSTANCE_NAME}.pid" --exec "${DAEMON}" -- ${dir}/${DAEMON_SCRIPT} --log /var/log/ttrss/${INSTANCE_NAME}.log || return 2 done } # Function that stops the daemon/service do_stop() { for dir in ${TTRSS_PATH}/*; do INSTANCE_NAME=${dir##*/} start-stop-daemon --stop --make-pidfile --quiet --retry=TERM/1/KILL/5 --pidfile "${TTRSS_PIDDIR}/ttrss-${INSTANCE_NAME}.pid" RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec ${DAEMON} [ "$?" = 2 ] && return 2 rm -f "${TTRSS_PIDDIR}/ttrss-${INSTANCE_NAME}.pid" return $RETVAL done } case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; restart|force-reload) # If the "reload" option is implemented then remove the # 'force-reload' alias log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2 exit 3 ;; esac : |
1 2 3 4 5 6 7 8 9 10 11 12 |
# Set DISABLED to 1 to prevent the daemon from starting. DISABLED=0 TTRSS_USERID="www-data" TTRSS_GROUPID="www-data" TTRSS_PIDDIR="/var/run" TTRSS_PATH="/var/www/rss.heimdaheim.de/www" # Allow the update_daemon script to use a forking daemon instead of a # single-threaded instance. # This option is only available for TinyTinyRSS 1.2.20 and above. FORKING=0 |