Skip to content

Commit 4b3c9fa

Browse files
committed
Install rackup and thin configurations in /etc/geocoder; modify default, init, postinst scripts to bring the REST server up on boot, assuming that a database is correctly set in /etc/default/geocoder-us.
1 parent b200eaf commit 4b3c9fa

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Homepage: http://github.com/simplegeo/geocoder/
88

99
Package: geocoder-us
1010
Architecture: any
11-
Depends: libsqlite3-0, libsqlite3-ruby (>= 1.3.0), libsinatra-ruby, libjson-ruby
11+
Depends: libsqlite3-0, libsqlite3-ruby (>= 1.3.0), libsinatra-ruby, libjson-ruby, thin
1212
Description: A US address geocoder.
1313
A US address geocoder. Requires a suitable database.

debian/geocoder-us.default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DAEMON_OPTS=/var/lib/geocoder/geocoder-us.db
1+
GEOCODER_US=/var/lib/geocoder/geocoder-us.db

debian/init.d renamed to debian/geocoder-us.init

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#
1313

1414
PATH=/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"
1617
NAME=geocoder
1718
DESC="geocoder server"
1819

1920
test -x $DAEMON || exit 0
2021

21-
LOGDIR=/var/log/geocoder
22-
PIDFILE=/var/run/$NAME.pid
22+
PIDFILE=/var/run/$NAME/$NAME.pid
2323
DODTIME=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
2929
if [ -f /etc/default/geocoder-us ] ; then
3030
. /etc/default/geocoder-us
3131
fi
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

3341
set -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

8189
case "$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)

debian/postinst renamed to debian/geocoder-us.postinst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ set -e
2020

2121
case "$1" in
2222
configure)
23-
mkdir -p /var/lib/geocoder
23+
# just make sure that /usr/bin/thin can write its PID file here
24+
chown www-data /var/run/geocoder
2425
;;
2526

2627
abort-upgrade|abort-remove|abort-deconfigure)

debian/rules

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ SHELL = /bin/bash
33

44
tmp = debian/tmp
55
sbindir = /usr/sbin
6+
vardir = /var
7+
etcdir = /etc
68
libdir18 = $(shell ruby1.8 -r rbconfig -e 'print Config::CONFIG["rubylibdir"]')
79
archdir18 = $(shell ruby1.8 -r rbconfig -e 'print Config::CONFIG["archdir"]')
810
libdir19 = $(shell ruby1.9.1 -r rbconfig -e 'print Config::CONFIG["rubylibdir"]')
@@ -23,6 +25,7 @@ build-ruby1.8-stamp:
2325

2426
# configure
2527
ruby1.8 setup.rb config \
28+
--sysconfdir=$(shell pwd)/$(tmp)$(etcdir) \
2629
--bin-dir=$(shell pwd)/$(tmp)$(sbindir) \
2730
--rb-dir=$(shell pwd)/$(tmp)$(libdir18) \
2831
--so-dir=$(shell pwd)/$(tmp)$(archdir18)
@@ -43,6 +46,7 @@ build-ruby1.9.1-stamp: $(QUILT_STAMPFN)
4346

4447
# configure
4548
ruby1.9.1 setup.rb config \
49+
--sysconfdir=$(shell pwd)/$(tmp)$(etcdir) \
4650
--bin-dir=$(shell pwd)/$(tmp)$(sbindir) \
4751
--rb-dir=$(shell pwd)/$(tmp)$(libdir19) \
4852
--so-dir=$(shell pwd)/$(tmp)$(archdir19)
@@ -61,9 +65,13 @@ install: build
6165

6266
echo $(tmp)$(libdir18) >debian/geocoder-us.install
6367
echo $(tmp)$(sbindir) >>debian/geocoder-us.install
68+
echo $(tmp)$(vardir) >>debian/geocoder-us.install
69+
echo $(tmp)$(etcdir) >>debian/geocoder-us.install
70+
71+
mkdir -p $(tmp)$(vardir)/lib/geocoder
72+
mkdir -p $(tmp)$(vardir)/run/geocoder
6473

6574
#echo $(tmp)$(libdir19) >debian/libsqlite3-ruby1.9.1.install
66-
#echo $(tmp)$(archdir19) >>debian/libsqlite3-ruby1.9.1.install
6775

6876
dh_install
6977

@@ -88,6 +96,9 @@ binary-arch: install
8896
dh_testdir -a
8997
dh_testroot -a
9098

99+
# install init script and default
100+
dh_installinit
101+
91102
# dh_installchangelogs -a CHANGELOG.rdoc
92103
dh_installdocs -a -A README.rdoc
93104
dh_link -a

0 commit comments

Comments
 (0)