Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

First pass at making the init file more system independent (still LSB).

  • Loading branch information...
commit 589cb88d57a727f6a7fa2f30328862b4e51f7966 1 parent bbaf4c8
Sam Bisbee sbisbee authored

Showing 1 changed file with 80 additions and 110 deletions. Show diff stats Hide diff stats

  1. +80 110 src/main/tools/etc/init.d/couchdb-lucene
190 src/main/tools/etc/init.d/couchdb-lucene
@@ -9,21 +9,22 @@
9 9 # Description: Initscript for CouchDB-Lucene
10 10 ### END INIT INFO
11 11
12   -# Author: Sebastian Cohnen <sebastian.cohnen@gmail.com>
13   -#
14   -
15 12 # Do NOT "set -e"
16 13
  14 +SCRIPT_OK=0
  15 +SCRIPT_ERROR=1
  16 +
17 17 PATH=/sbin:/usr/sbin:/bin:/usr/bin
18   -DESC="Description of the service"
  18 +DESC="CouchDB Lucene index"
19 19 NAME="couchdb-lucene"
20 20 DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
21   -PIDFILE=/var/run/$NAME.pid
  21 +PIDFILE=/var/run/$NAME/$NAME.pid
22 22 DAEMON_ARGS="$PIDFILE"
23   -SCRIPTNAME=/etc/init.d/$NAME
  23 +SCRIPTNAME=`basename $0`
  24 +LSB_LIBRARY=/lib/lsb/init-functions
24 25
25 26 # Exit if the package is not installed
26   -[ -x "$DAEMON" ] || exit 0
  27 +[ -x "$DAEMON" ] || exit $SCRIPT_ERROR
27 28
28 29 # Read configuration variable file if it is present
29 30 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
@@ -31,27 +32,25 @@ SCRIPTNAME=/etc/init.d/$NAME
31 32 # Load the VERBOSE setting and other rcS variables
32 33 . /lib/init/vars.sh
33 34
34   -# Define LSB log_* functions.
35   -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36   -. /lib/lsb/init-functions
  35 +# We use LSB, so require that we can find the lib.
  36 +[ ! -r $LSB_LIBRARY ] && echo "$NAME cannot find the LSB functions! Did you set LSB_LIBRARY?" && exit $SCRIPT_ERROR
  37 +
  38 +. $LSB_LIBRARY
37 39
38 40 #
39 41 # Function that starts the daemon/service
40 42 #
41 43 do_start()
42 44 {
43   - # Return
44   - # 0 if daemon has been started
45   - # 1 if daemon was already running
46   - # 2 if daemon could not be started
47   - PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
48   - || return 1
49   - PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- \
50   - $DAEMON_ARGS \
51   - || return 2
52   - # Add code here, if necessary, that waits for the process to be ready
53   - # to handle requests from services started subsequently which depend
54   - # on this one. As a last resort, sleep for some time.
  45 + # Return
  46 + # 0 if daemon has been started
  47 + # 1 if daemon was already running
  48 + # 2 if daemon could not be started
  49 + PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  50 + || return 1
  51 + PIDFILE=$PIDFILE start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- \
  52 + $DAEMON_ARGS \
  53 + || return 2
55 54 }
56 55
57 56 #
@@ -59,102 +58,73 @@ do_start()
59 58 #
60 59 do_stop()
61 60 {
62   - # Return
63   - # 0 if daemon has been stopped
64   - # 1 if daemon was already stopped
65   - # 2 if daemon could not be stopped
66   - # other if a failure occurred
67   - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
68   - RETVAL="$?"
69   - [ "$RETVAL" = 2 ] && return 2
70   - # Wait for children to finish too if this is a daemon that forks
71   - # and if the daemon is only ever run from this initscript.
72   - # If the above conditions are not satisfied then add some other code
73   - # that waits for the process to drop all resources that could be
74   - # needed by services started subsequently. A last resort is to
75   - # sleep for some time.
76   - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
77   - [ "$?" = 2 ] && return 2
78   - # Many daemons don't delete their pidfiles when they exit.
79   - rm -f $PIDFILE
80   - return "$RETVAL"
81   -}
82   -
83   -#
84   -# Function that sends a SIGHUP to the daemon/service
85   -#
86   -do_reload() {
87   - #
88   - # If the daemon can reload its configuration without
89   - # restarting (for example, when it is sent a SIGHUP),
90   - # then implement that here.
91   - #
92   - start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
93   - return 0
  61 + # Return
  62 + # 0 if daemon has been stopped
  63 + # 1 if daemon was already stopped
  64 + # 2 if daemon could not be stopped
  65 + # other if a failure occurred
  66 + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  67 + RETVAL="$?"
  68 + [ "$RETVAL" = 2 ] && return 2
  69 + # Wait for children to finish too if this is a daemon that forks
  70 + # and if the daemon is only ever run from this initscript.
  71 + # If the above conditions are not satisfied then add some other code
  72 + # that waits for the process to drop all resources that could be
  73 + # needed by services started subsequently. A last resort is to
  74 + # sleep for some time.
  75 + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  76 + [ "$?" = 2 ] && return 2
  77 + # Many daemons don't delete their pidfiles when they exit.
  78 + rm -f $PIDFILE
  79 + return "$RETVAL"
94 80 }
95 81
96 82 case "$1" in
97 83 start)
98   - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
99   - do_start
100   - case "$?" in
101   - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
102   - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
103   - esac
104   - ;;
  84 + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  85 + do_start
  86 + case "$?" in
  87 + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  88 + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  89 + esac
  90 + ;;
  91 +
105 92 stop)
106   - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
107   - do_stop
108   - case "$?" in
109   - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
110   - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
111   - esac
112   - ;;
  93 + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  94 + do_stop
  95 + case "$?" in
  96 + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  97 + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  98 + esac
  99 + ;;
  100 +
113 101 status)
114   - #status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
115   - if [ ! -f $PIDFILE -o ! -d /proc/`cat $PIDFILE` ]
116   - then
117   - log_failure_msg "$NAME is not running"
118   - else
119   - log_success_msg "$NAME is running"
120   - fi
121   - ;;
122   - #reload|force-reload)
123   - #
124   - # If do_reload() is not implemented then leave this commented out
125   - # and leave 'force-reload' as an alias for 'restart'.
126   - #
127   - #log_daemon_msg "Reloading $DESC" "$NAME"
128   - #do_reload
129   - #log_end_msg $?
130   - #;;
  102 + status_of_proc "$DAEMON" "$NAME" && exit $SCRIPT_OK || exit $?
  103 + ;;
  104 +
131 105 restart|force-reload)
132   - #
133   - # If the "reload" option is implemented then remove the
134   - # 'force-reload' alias
135   - #
136   - log_daemon_msg "Restarting $DESC" "$NAME"
137   - do_stop
138   - case "$?" in
139   - 0|1)
140   - do_start
141   - case "$?" in
142   - 0) log_end_msg 0 ;;
143   - 1) log_end_msg 1 ;; # Old process is still running
144   - *) log_end_msg 1 ;; # Failed to start
145   - esac
146   - ;;
147   - *)
148   - # Failed to stop
149   - log_end_msg 1
150   - ;;
151   - esac
152   - ;;
  106 + log_daemon_msg "Restarting $DESC" "$NAME"
  107 + do_stop
  108 + case "$?" in
  109 + 0|1)
  110 + do_start
  111 + case "$?" in
  112 + 0) log_end_msg $SCRIPT_OK ;;
  113 + 1) log_end_msg $SCRIPT_ERROR ;; # Old process is still running
  114 + *) log_end_msg $SCRIPT_ERROR ;; # Failed to start
  115 + esac
  116 + ;;
  117 + *)
  118 + # Failed to stop
  119 + log_end_msg $SCRIPT_ERROR
  120 + ;;
  121 + esac
  122 + ;;
  123 +
153 124 *)
154   - #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
155   - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
156   - exit 3
157   - ;;
  125 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  126 + exit 3
  127 + ;;
158 128 esac
159 129
160 130 :

0 comments on commit 589cb88

Please sign in to comment.
Something went wrong with that request. Please try again.