1212#
1313
1414PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
15- DAEMON=/usr/sbin/geocoderd
15+ DAEMON=/usr/bin/thin
16+ DAEMON_OPTS=" -C /etc/geocoder/thin.yml -R /etc/geocoder/geocoder.ru"
1617NAME=geocoder
1718DESC=" geocoder server"
1819
1920test -x $DAEMON || exit 0
2021
21- LOGDIR=/var/log/geocoder
22- PIDFILE=/var/run/$NAME .pid
22+ PIDFILE=/var/run/$NAME /$NAME .pid
2323DODTIME=3 # Time to wait for the server to die, in seconds
2424 # If this value is set too low you might not
2525 # let some servers to die gracefully and
@@ -29,6 +29,14 @@ DODTIME=3 # Time to wait for the server to die, in seconds
2929if [ -f /etc/default/geocoder-us ] ; then
3030 . /etc/default/geocoder-us
3131fi
32+ # $DATABASE should be set to the location of the database in /etc/default/gecoder-us
33+ [ -z " $DATABASE " ] && exit 0
34+ if [ ! -r " $DATABASE " ] ; then
35+ echo " $DATABASE not found; not running command."
36+ exit 0
37+ fi
38+ # set the environment variable so that the daemon can find the database
39+ export GEOCODER_DB=" $DATABASE "
3240
3341set -e
3442
@@ -39,7 +47,7 @@ running_pid()
3947 name=$2
4048 [ -z " $pid " ] && return 1
4149 [ ! -d /proc/$pid ] && return 1
42- cmd=` cat /proc/$pid /cmdline | tr " \000" " \n" | head -n 1 | cut -d : -f 1`
50+ cmd=` cat /proc/$pid /cmdline | tr " \000" " \n" | head -n 1 | cut -d" " -f 1`
4351 # Is this the expected child?
4452 [ " $cmd " != " $name " ] && return 1
4553 return 0
@@ -54,7 +62,7 @@ running()
5462 [ ! -f " $PIDFILE " ] && return 1
5563 # Obtain the pid and check it against the binary name
5664 pid=` cat $PIDFILE `
57- running_pid $pid $DAEMON || return 1
65+ running_pid $pid ` basename $DAEMON ` || return 1
5866 return 0
5967}
6068
@@ -80,22 +88,24 @@ force_stop() {
8088
8189case " $1 " in
8290 start)
91+ running && exit 0
8392 echo -n " Starting $DESC : "
84- start-stop-daemon --start --quiet --pidfile $PIDFILE \
85- --exec $DAEMON -- $DAEMON_OPTS
93+ $DAEMON $DAEMON_OPTS $1
94+ sleep 1
8695 if running ; then
8796 echo " $NAME ."
8897 else
8998 echo " ERROR."
9099 fi
91100 ;;
92101 stop)
102+ running || exit 0
93103 echo -n " Stopping $DESC : "
94- start-stop-daemon --stop --quiet --pidfile $PIDFILE \
95- --exec $DAEMON
104+ $DAEMON $DAEMON_OPTS $1
96105 echo " $NAME ."
97106 ;;
98107 force-stop)
108+ running || exit 0
99109 echo -n " Forcefully stopping $DESC : "
100110 force_stop
101111 if ! running ; then
@@ -123,18 +133,13 @@ case "$1" in
123133 # just the same as "restart" except that it does nothing if the
124134 # daemon isn't already running.
125135 # check wether $DAEMON is running. If so, restart
126- start-stop-daemon --stop --test --quiet --pidfile \
127- /var/run/$NAME .pid --exec $DAEMON \
128- && $0 restart \
129- || exit 0
136+ running || exit 0
137+ $DAEMON $DAEMON_OPTS stop && $DAEMON $DAEMON_OPTS start
130138 ;;
131139 restart)
132- echo -n " Restarting $DESC : "
133- start-stop-daemon --stop --quiet --pidfile \
134- /var/run/$NAME .pid --exec $DAEMON
135- [ -n " $DODTIME " ] && sleep $DODTIME
136- start-stop-daemon --start --quiet --pidfile \
137- /var/run/$NAME .pid --exec $DAEMON -- $DAEMON_OPTS
140+ running || exit 0
141+ echo -n " Restarting $DESC : "
142+ $DAEMON $DAEMON_OPTS restart
138143 echo " $NAME ."
139144 ;;
140145 status)
0 commit comments