Skip to content
This repository

merge sbisbee's work + configurable root dirs #148

Open
wants to merge 23 commits into from

3 participants

Tim Kuijsten Robert Newson Sam Bisbee
Tim Kuijsten

use configurable root dirs, default to /usr/local

and others added some commits September 01, 2010
Sam Bisbee First pass at making the init file more system independent (still LSB). 589cb88
Sam Bisbee Rewriting the run binary to deal with its life better. c621d0e
Sam Bisbee fixing typo 5bf88e7
Sam Bisbee Fixing wrong value to pid file c307979
Sam Bisbee Prevent start if the pid file is there. 0b9cf6d
Sam Bisbee Making some LSB codes more explicit with variables a082b15
Sam Bisbee Fixing start code 4100865
Sam Bisbee Fixing var order 08c0150
Sam Bisbee Adding the usage output 97a9e85
Sam Bisbee Adding to thanks file cb00be8
Sam Bisbee Rearranging package format to match the *nix file structure. e4ae3e2
Sam Bisbee Adding the other doc files to the package. dba9760
Sam Bisbee Renaming the binary, and updating the init file accordingly a71a89e
Sam Bisbee Shouldn't overwrite PATH. c9a76e2
Sam Bisbee Fixing the assembly file from the shell script rename. 49a369d
Sam Bisbee Implementing the -p PID file arg and using in the init file. 717db0f
Sam Bisbee Forgot to tell getopts to parse the -p arg. fa35de3
Sam Bisbee Adding the main class to the jar's manifest - we can now call by jar,…
… not class.
05e02dd
Sam Bisbee Changing how we create the CLASSPATH to play friendlier with our new …
…package layout.
3eb06a5
Sam Bisbee Prevent the indexes from being written to the jar or wrapper's cwd. 87395a7
Sam Bisbee Put documentation in usr/share/doc/couchdb-lucene 0a413b9
Tim Kuijsten Merge remote branch 'sbisbee/master' into ubuntu
Conflicts:
	THANKS.md
	src/main/assembly/dist.xml
	src/main/bin/run
692ecd0
Tim Kuijsten support for configurable root directories
destRootDir
destVarDir
destVarLibDir
destEtcDir
destBinDir
destDocDir

example: mvn -DdestRootDir="" -DdestDocDir="/usr/local/share"
2988b7a
Tim Kuijsten

Succesfully built on Ubuntu Server 10.04 amd64 with: mvn -DdestRootDir="" -DdestDocDir="/usr/local/share" -DdestBinDir="/usr/local/bin"

Tim Kuijsten

but i do see some runtime errors now:
/usr/local/couchdb-lucene-0.8.0-SNAPSHOT$ ./usr/local/bin/couchdb-lucene
Exception in thread "main" java.lang.NoClassDefFoundError: com/github/rnewson/couchdb/lucene/Main
Caused by: java.lang.ClassNotFoundException: com.github.rnewson.couchdb.lucene.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.github.rnewson.couchdb.lucene.Main. Program will exit.

Have to investigate..

Robert Newson rnewson commented on the diff December 21, 2011
THANKS.md
@@ -2,3 +2,4 @@
2 2
 * Thanks to Adam Lofts for the performance boosting JSONDocumentAdapter et al.
3 3
 * Thanks to Santiago M. Mola for the termvector option.
4 4
 * Thanks to Joe Hillenbrand for adding default result limit to config.
  5
+* Thanks to Sam Bisbee.
1
Robert Newson Owner
rnewson added a note December 21, 2011

You should add yourself too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
@@ -110,6 +110,13 @@
110 110
         <tika-version>1.0</tika-version>
111 111
         <jetty-version>6.1.20</jetty-version>
112 112
         <http-version>4.0.1</http-version>
  113
+        <env>default</env>
  114
+        <destRootDir>/usr/local</destRootDir>
  115
+        <destVarDir>${destRootDir}/var</destVarDir>
  116
+        <destVarLibDir>${destVarDir}/lib</destVarLibDir>
  117
+        <destEtcDir>${destRootDir}/etc</destEtcDir>
  118
+        <destBinDir>${destRootDir}/bin</destBinDir>
  119
+        <destDocDir>${destRootDir}/share/doc</destDocDir>
1
Robert Newson Owner
rnewson added a note December 21, 2011

I'd keep destRootDir and to do the /var etc thing where it's used. The abstraction here isn't useful as these variables almost never vary. It's only the top-level that is altered and {root}/etc, {root}/bin are assumed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/assembly/dist.xml
((24 lines not shown))
20 24
       <fileMode>755</fileMode>
21  
-      <outputDirectory>/bin</outputDirectory>
  25
+      <outputDirectory>${destBinDir}</outputDirectory>
1
Robert Newson Owner
rnewson added a note December 21, 2011

i.e, ${destRootDir}/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/bin/couchdb-lucene
... ...
@@ -0,0 +1,90 @@
  1
+#!/bin/sh
  2
+
  3
+NAME="couchdb-lucene"
  4
+BACKGROUND=false        #whether to run in the background or not
  5
+STDOUT_FILE=""          #where to send background stdout to (defaults to &1)
  6
+PID_FILE=/var/run/couchdb-lucene/couchdb-lucene.pid
1
Robert Newson Owner
rnewson added a note December 21, 2011

This is absolute, but should be relative to ${destRootDir} too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/resources/couchdb-lucene.ini
... ...
@@ -1,6 +1,6 @@
1 1
 [lucene]
2 2
 # The output directory for Lucene indexes.
3  
-dir=indexes
  3
+dir=/var/lib/couchdb-lucene/indexes
1
Robert Newson Owner
rnewson added a note December 21, 2011

This is absolute, but should be relative to ${destRootDir} too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/tools/etc/init.d/couchdb-lucene
((17 lines not shown))
19 20
 NAME="couchdb-lucene"
20  
-DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
21  
-PIDFILE=/var/run/$NAME.pid
22  
-DAEMON_ARGS="$PIDFILE"
23  
-SCRIPTNAME=/etc/init.d/$NAME
  21
+PIDFILE=/var/run/$NAME/$NAME.pid
  22
+DAEMON=$NAME
  23
+DAEMON_ARGS="-o /var/log/couchdb-lucene.log -b -p $PIDFILE"
1
Robert Newson Owner
rnewson added a note December 21, 2011

This is absolute, but should be relative to ${destRootDir} too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/tools/etc/init.d/couchdb-lucene
((17 lines not shown))
19 20
 NAME="couchdb-lucene"
20  
-DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
21  
-PIDFILE=/var/run/$NAME.pid
22  
-DAEMON_ARGS="$PIDFILE"
23  
-SCRIPTNAME=/etc/init.d/$NAME
  21
+PIDFILE=/var/run/$NAME/$NAME.pid
1
Robert Newson Owner
rnewson added a note December 21, 2011

This is absolute, but should be relative to ${destRootDir} too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Newson rnewson commented on the diff December 21, 2011
src/main/tools/etc/init.d/couchdb-lucene
((17 lines not shown))
19 20
 NAME="couchdb-lucene"
20  
-DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
21  
-PIDFILE=/var/run/$NAME.pid
22  
-DAEMON_ARGS="$PIDFILE"
23  
-SCRIPTNAME=/etc/init.d/$NAME
1
Robert Newson Owner
rnewson added a note December 21, 2011

This is absolute, but should be relative to ${destRootDir} too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 23 unique commits by 2 authors.

Sep 01, 2010
Sam Bisbee First pass at making the init file more system independent (still LSB). 589cb88
Sam Bisbee Rewriting the run binary to deal with its life better. c621d0e
Sam Bisbee fixing typo 5bf88e7
Sam Bisbee Fixing wrong value to pid file c307979
Sam Bisbee Prevent start if the pid file is there. 0b9cf6d
Sam Bisbee Making some LSB codes more explicit with variables a082b15
Sam Bisbee Fixing start code 4100865
Sam Bisbee Fixing var order 08c0150
Sam Bisbee Adding the usage output 97a9e85
Sep 21, 2010
Sam Bisbee Adding to thanks file cb00be8
Sam Bisbee Rearranging package format to match the *nix file structure. e4ae3e2
Sam Bisbee Adding the other doc files to the package. dba9760
Sam Bisbee Renaming the binary, and updating the init file accordingly a71a89e
Sam Bisbee Shouldn't overwrite PATH. c9a76e2
Sam Bisbee Fixing the assembly file from the shell script rename. 49a369d
Sam Bisbee Implementing the -p PID file arg and using in the init file. 717db0f
Sep 28, 2010
Sam Bisbee Forgot to tell getopts to parse the -p arg. fa35de3
Sam Bisbee Adding the main class to the jar's manifest - we can now call by jar,…
… not class.
05e02dd
Sam Bisbee Changing how we create the CLASSPATH to play friendlier with our new …
…package layout.
3eb06a5
Sam Bisbee Prevent the indexes from being written to the jar or wrapper's cwd. 87395a7
Sam Bisbee Put documentation in usr/share/doc/couchdb-lucene 0a413b9
Dec 21, 2011
Tim Kuijsten Merge remote branch 'sbisbee/master' into ubuntu
Conflicts:
	THANKS.md
	src/main/assembly/dist.xml
	src/main/bin/run
692ecd0
Tim Kuijsten support for configurable root directories
destRootDir
destVarDir
destVarLibDir
destEtcDir
destBinDir
destDocDir

example: mvn -DdestRootDir="" -DdestDocDir="/usr/local/share"
2988b7a
This page is out of date. Refresh to see the latest.
1  THANKS.md
Source Rendered
@@ -2,3 +2,4 @@
2 2
 * Thanks to Adam Lofts for the performance boosting JSONDocumentAdapter et al.
3 3
 * Thanks to Santiago M. Mola for the termvector option.
4 4
 * Thanks to Joe Hillenbrand for adding default result limit to config.
  5
+* Thanks to Sam Bisbee.
8  pom.xml
@@ -110,6 +110,13 @@
110 110
         <tika-version>1.0</tika-version>
111 111
         <jetty-version>6.1.20</jetty-version>
112 112
         <http-version>4.0.1</http-version>
  113
+        <env>default</env>
  114
+        <destRootDir>/usr/local</destRootDir>
  115
+        <destVarDir>${destRootDir}/var</destVarDir>
  116
+        <destVarLibDir>${destVarDir}/lib</destVarLibDir>
  117
+        <destEtcDir>${destRootDir}/etc</destEtcDir>
  118
+        <destBinDir>${destRootDir}/bin</destBinDir>
  119
+        <destDocDir>${destRootDir}/share/doc</destDocDir>
113 120
     </properties>
114 121
     <issueManagement>
115 122
         <system>github</system>
@@ -179,6 +186,7 @@
179 186
                         <manifest>
180 187
                             <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
181 188
                             <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
  189
+                            <mainClass>com.github.rnewson.couchdb.lucene.Main</mainClass>
182 190
                         </manifest>
183 191
                     </archive>
184 192
                 </configuration>
30  src/main/assembly/dist.xml
@@ -6,50 +6,54 @@
6 6
   </formats>
7 7
   <fileSets>
8 8
     <fileSet>
  9
+      <directory>${project.basedir}</directory>
  10
+      <outputDirectory>${destDocDir}/couchdb-lucene</outputDirectory>
9 11
       <includes>
10  
-        <include>${project.basedir}/README*</include>
11  
-        <include>${project.basedir}/LICENSE*</include>
12  
-        <include>${project.basedir}/NOTICE*</include>
  12
+        <include>README*</include>
  13
+        <include>LICENSE*</include>
  14
+        <include>NOTICE*</include>
  15
+        <include>BREAKING_CHANGES*</include>
  16
+        <include>TODO*</include>
  17
+        <include>THANKS*</include>
13 18
       </includes>
14  
-      <outputDirectory>/</outputDirectory>
15 19
     </fileSet>
16 20
   </fileSets>
17 21
   <files>
18 22
     <file>
19  
-      <source>${project.basedir}/src/main/bin/run</source>
  23
+      <source>${project.basedir}/src/main/bin/couchdb-lucene</source>
20 24
       <fileMode>755</fileMode>
21  
-      <outputDirectory>/bin</outputDirectory>
  25
+      <outputDirectory>${destBinDir}</outputDirectory>
22 26
     </file>
23 27
     <file>
24 28
       <source>${project.basedir}/src/main/bin/kill_ppid</source>
25 29
       <fileMode>755</fileMode>
26  
-      <outputDirectory>/bin</outputDirectory>
  30
+      <outputDirectory>${destVarLibDir}/couchdb-lucene</outputDirectory>
27 31
     </file>
28 32
     <file>
29 33
       <source>${project.basedir}/src/main/resources/couchdb-lucene.ini</source>
30 34
       <fileMode>644</fileMode>
31  
-      <outputDirectory>/conf</outputDirectory>
  35
+      <outputDirectory>${destEtcDir}/couchdb-lucene</outputDirectory>
32 36
     </file>
33 37
     <file>
34 38
       <source>${project.basedir}/src/main/resources/log4j.xml</source>
35 39
       <fileMode>644</fileMode>
36  
-      <outputDirectory>/conf</outputDirectory>
  40
+      <outputDirectory>${destEtcDir}/couchdb-lucene</outputDirectory>
37 41
     </file>
38 42
     <file>
39 43
       <source>${project.basedir}/couchdb-external-hook.py</source>
40  
-      <fileMode>777</fileMode>
41  
-      <outputDirectory>/tools</outputDirectory>
  44
+      <fileMode>755</fileMode>
  45
+      <outputDirectory>${destBinDir}</outputDirectory>
42 46
     </file>
43 47
     <file>
44 48
       <source>${project.basedir}/src/main/tools/etc/init.d/couchdb-lucene</source>
45 49
       <fileMode>755</fileMode>
46  
-      <outputDirectory>/tools/etc/init.d/couchdb-lucene</outputDirectory>
  50
+      <outputDirectory>${destEtcDir}/init.d</outputDirectory>
47 51
     </file>
48 52
   </files>
49 53
   <dependencySets>
50 54
     <dependencySet>
51 55
       <scope>runtime</scope>
52  
-      <outputDirectory>/lib</outputDirectory>
  56
+      <outputDirectory>${destVarLibDir}/couchdb-lucene</outputDirectory>
53 57
     </dependencySet>
54 58
   </dependencySets>
55 59
 </assembly>
90  src/main/bin/couchdb-lucene
... ...
@@ -0,0 +1,90 @@
  1
+#!/bin/sh
  2
+
  3
+NAME="couchdb-lucene"
  4
+BACKGROUND=false        #whether to run in the background or not
  5
+STDOUT_FILE=""          #where to send background stdout to (defaults to &1)
  6
+PID_FILE=/var/run/couchdb-lucene/couchdb-lucene.pid
  7
+
  8
+SCRIPT_OK=0
  9
+SCRIPT_ERROR=1
  10
+
  11
+printUsage()
  12
+{
  13
+  cat << EOF
  14
+Usage: `$basename $0` [OPTIONS]
  15
+
  16
+Starts the couchdb-lucene server component.
  17
+
  18
+Options:
  19
+
  20
+  -h            displays this short help message and exits
  21
+
  22
+  -b            spawn as a background process
  23
+  -o FILE       redirect background process's stdout to FILE (defaults to none)
  24
+  -p FILE       set the background process's PID FILE
  25
+EOF
  26
+}
  27
+
  28
+getPid()
  29
+{
  30
+  [ -f $PID_FILE ] && PID=`cat $PID_FILE`
  31
+  echo $PID
  32
+}
  33
+
  34
+start()
  35
+{
  36
+  CLASSPATH="$CL_BASEDIR/etc/couchdb-lucene:$CL_BASEDIR/lib/couchdb-lucene/*"
  37
+  JAVA_OPTS="-server -Xmx1g -cp $CLASSPATH"
  38
+
  39
+  command="java $JAVA_OPTS $JAR com.github.rnewson.couchdb.lucene.Main"
  40
+
  41
+  if [ "$BACKGROUND" != "true" ]
  42
+  then
  43
+    eval $command
  44
+  else
  45
+    PID=`getPid`
  46
+
  47
+    if [ -z "$PID" ]
  48
+    then
  49
+      [ -n $STDOUT_FILE ] && command="$command >> $STDOUT_FILE"
  50
+
  51
+      eval "$command &"
  52
+      echo $! > $PID_FILE
  53
+    else
  54
+      echo "$NAME is already running ($PID_FILE)."
  55
+    fi
  56
+  fi
  57
+}
  58
+
  59
+checkEnvironment()
  60
+{
  61
+  prepend="couchdb-lucene needs write access to"
  62
+  [ ! -w $STDOUT_FILE ] && echo "$prepend output file $STDOUT_FILE" && exit $SCRIPT_ERROR 
  63
+  unset prepend
  64
+}
  65
+
  66
+parseOptions()
  67
+{
  68
+  opts=`getopt o:hbp: $@`
  69
+  set -- $opts
  70
+  while [ $# -gt 0 ]
  71
+  do
  72
+    case "$1" in
  73
+      -h) shift; printUsage; exit $SCRIPT_OK;;
  74
+      -o) shift; STDOUT_FILE="$1"; shift;;
  75
+      -b) shift; BACKGROUND=true;;
  76
+      -p) shift; PID_FILE="$1"; shift;;
  77
+      --) shift; break;; 
  78
+      *) echo "Unknown option: $1" >&2; exit $SCRIPT_ERROR;;
  79
+    esac
  80
+  done
  81
+}
  82
+
  83
+parseOptions $@
  84
+checkEnvironment
  85
+
  86
+[ -z $CL_BASEDIR ] && CL_BASEDIR=`dirname "$0"`"/.."
  87
+cd $CL_BASEDIR
  88
+
  89
+start
  90
+
2  src/main/resources/couchdb-lucene.ini
... ...
@@ -1,6 +1,6 @@
1 1
 [lucene]
2 2
 # The output directory for Lucene indexes.
3  
-dir=indexes
  3
+dir=/var/lib/couchdb-lucene/indexes
4 4
 
5 5
 # The local host name that couchdb-lucene binds to
6 6
 host=localhost
194  src/main/tools/etc/init.d/couchdb-lucene
@@ -9,21 +9,23 @@
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
 
17  
-PATH=/sbin:/usr/sbin:/bin:/usr/bin
18  
-DESC="Description of the service"
  14
+SCRIPT_OK=0
  15
+SCRIPT_ERROR=1
  16
+SCRIPT_ERROR_NOT_IMPLEMENTED=3
  17
+SCRIPT_ERROR_NOT_INSTALLED=5
  18
+
  19
+DESC="CouchDB Lucene index"
19 20
 NAME="couchdb-lucene"
20  
-DAEMON=/usr/local/couchdb-lucene-0.5.5/bin/run
21  
-PIDFILE=/var/run/$NAME.pid
22  
-DAEMON_ARGS="$PIDFILE"
23  
-SCRIPTNAME=/etc/init.d/$NAME
  21
+PIDFILE=/var/run/$NAME/$NAME.pid
  22
+DAEMON=$NAME
  23
+DAEMON_ARGS="-o /var/log/couchdb-lucene.log -b -p $PIDFILE"
  24
+SCRIPTNAME=`basename $0`
  25
+LSB_LIBRARY=/lib/lsb/init-functions
24 26
 
25 27
 # Exit if the package is not installed
26  
-[ -x "$DAEMON" ] || exit 0
  28
+[ -x "$DAEMON" ] || exit $SCRIPT_ERROR_NOT_INSTALLED
27 29
 
28 30
 # Read configuration variable file if it is present
29 31
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
@@ -31,27 +33,22 @@ SCRIPTNAME=/etc/init.d/$NAME
31 33
 # Load the VERBOSE setting and other rcS variables
32 34
 . /lib/init/vars.sh
33 35
 
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
  36
+# We use LSB, so require that we can find the lib.
  37
+[ ! -r $LSB_LIBRARY ] && echo "$NAME cannot find the LSB functions! Did you set LSB_LIBRARY?" && exit $SCRIPT_ERROR 
  38
+
  39
+. $LSB_LIBRARY 
37 40
 
38 41
 #
39 42
 # Function that starts the daemon/service
40 43
 #
41 44
 do_start()
42 45
 {
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.
  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
+  start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test || return 1
  51
+  start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2
55 52
 }
56 53
 
57 54
 #
@@ -59,102 +56,73 @@ do_start()
59 56
 #
60 57
 do_stop()
61 58
 {
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
  59
+  # Return
  60
+  #   0 if daemon has been stopped
  61
+  #   1 if daemon was already stopped
  62
+  #   2 if daemon could not be stopped
  63
+  #   other if a failure occurred
  64
+  start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  65
+  RETVAL="$?"
  66
+  [ "$RETVAL" = 2 ] && return 2
  67
+  # Wait for children to finish too if this is a daemon that forks
  68
+  # and if the daemon is only ever run from this initscript.
  69
+  # If the above conditions are not satisfied then add some other code
  70
+  # that waits for the process to drop all resources that could be
  71
+  # needed by services started subsequently.  A last resort is to
  72
+  # sleep for some time.
  73
+  start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  74
+  [ "$?" = 2 ] && return 2
  75
+  # Many daemons don't delete their pidfiles when they exit.
  76
+  rm -f $PIDFILE
  77
+  return "$RETVAL"
94 78
 }
95 79
 
96 80
 case "$1" in
97 81
   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  
-	;;
  82
+    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  83
+    do_start
  84
+    case "$?" in
  85
+      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  86
+      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  87
+    esac
  88
+    ;;
  89
+
105 90
   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  
-	;;
  91
+    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  92
+    do_stop
  93
+    case "$?" in
  94
+      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  95
+      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  96
+    esac
  97
+    ;;
  98
+
113 99
   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  
-	#;;
  100
+    status_of_proc "$DAEMON" "$NAME" && exit $SCRIPT_OK || exit $?
  101
+    ;;
  102
+
131 103
   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  
-	;;
  104
+    log_daemon_msg "Restarting $DESC" "$NAME"
  105
+    do_stop
  106
+    case "$?" in
  107
+      0|1)
  108
+        do_start
  109
+        case "$?" in
  110
+          0) log_end_msg $SCRIPT_OK ;;
  111
+          1) log_end_msg $SCRIPT_ERROR ;; # Old process is still running
  112
+          *) log_end_msg $SCRIPT_ERROR ;; # Failed to start
  113
+        esac
  114
+        ;;
  115
+      *)
  116
+        # Failed to stop
  117
+        log_end_msg $SCRIPT_ERROR
  118
+        ;;
  119
+    esac
  120
+    ;;
  121
+
153 122
   *)
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  
-	;;
  123
+    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  124
+    exit $SCRIPT_ERROR_NOT_IMPLEMENTED
  125
+    ;;
158 126
 esac
159 127
 
160 128
 :
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.