]> git.pld-linux.org Git - packages/couchdb.git/blob - couchdb.init
- remove pid on stop
[packages/couchdb.git] / couchdb.init
1 #!/bin/sh
2 #
3 # couchdb       Starts CouchDB
4 # chkconfig:    2345 84 25
5 # description:  Apache CouchDB init script
6 # pidfile:      /var/run/couchdb.pid
7 #
8 # $Id$
9
10 # Source function library
11 . /etc/rc.d/init.d/functions
12
13 # Get network config
14 . /etc/sysconfig/network
15
16 # Set defaults
17 COUCHDB="/usr/bin/couchdb"
18 COUCHDB_INI='/etc/apache-couchdb/couch.ini'
19 COUCHDB_PID='/var/run/couchdb.pid'
20 COUCHDB_USER='couchdb'
21 COUCHDB_STDOUT='/dev/null'
22 COUCHDB_STDERR='/dev/null'
23 COUCHDB_RESPAWN='5'
24
25 # Get service config - may override defaults
26 [ -f /etc/sysconfig/couchdb ] && . /etc/sysconfig/couchdb
27
28 # Check that networking is up.
29 if is_yes "${NETWORKING}"; then
30         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
31                 msg_network_down "CouchDB"
32                 exit 1
33         fi
34 else
35         exit 0
36 fi
37
38 start() {
39         # Check if the service is already running?
40         if [ -f /var/lock/subsys/couchdb ]; then
41                 msg_already_running "CouchDB"
42                 return
43         fi
44
45         msg_starting "CouchDB"
46         test -n $COUCHDB_PID \
47                 && touch $COUCHDB_PID \
48                 && chown $COUCHDB_USER $COUCHDB_PID
49         daemon --user $COUCHDB_USER $COUCHDB \
50                                 -b -c "$COUCHDB_INI" -p "$COUCHDB_PID" \
51                                 -o "$COUCHDB_STDOUT" -e "$COUCHDB_STDERR" \
52                                 -r "$COUCHDB_RESPAWN"
53         RETVAL=$?
54         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/couchdb
55 }
56
57 stop() {
58         if [ ! -f /var/lock/subsys/couchdb ]; then
59                 msg_not_running "CouchDB"
60                 return
61         fi
62
63         # Stop daemons.
64         msg_stopping "CouchDB"
65         killproc --pidfile $COUCHDB_PID couchdb -TERM
66         rm -f $COUCHDB_PID
67         rm -f /var/lock/subsys/couchdb
68 }
69
70 reload() {
71         if [ ! -f /var/lock/subsys/couchdb ]; then
72                 msg_not_running "CouchDB"
73                 RETVAL=7
74                 return
75         fi
76
77         msg_reloading "CouchDB"
78         killproc --pidfile $COUCHDB_PID couchdb -HUP
79         RETVAL=$?
80 }
81
82 condrestart() {
83         if [ ! -f /var/lock/subsys/couchdb ]; then
84                 msg_not_running "CouchDB"
85                 RETVAL=$1
86                 return
87         fi
88
89         stop
90         start
91 }
92
93 RETVAL=0
94 # See how we were called.
95 case "$1" in
96   start)
97         start
98         ;;
99   stop)
100         stop
101         ;;
102   restart)
103         stop
104         start
105         ;;
106   try-restart)
107         condrestart 0
108         ;;
109   reload|force-reload)
110         reload
111         ;;
112   status)
113         status couchdb
114         RETVAL=$?
115         ;;
116   *)
117         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
118         exit 3
119 esac
120
121 exit $RETVAL
This page took 0.03923 seconds and 3 git commands to generate.