]> git.pld-linux.org Git - packages/mongodb.git/blob - mongodb.init
- fix for "'swap' is not a member of 'std'" in gcc 4
[packages/mongodb.git] / mongodb.init
1 #!/bin/sh
2 #
3 # mongod                mongod
4 #
5 # chkconfig:    345 60 40
6 #
7 # description:  mongod is a NoSQL database daemon.
8 #
9 # processname:  mongod
10 # pidfile:      /var/run/mongod.pid
11 #
12 ### BEGIN INIT INFO
13 # Provides:          mongod
14 # Required-Start: $syslog $local_fs $network
15 # Required-Stop:  $syslog $local_fs $network
16 # Should-Start:   $remote_fs
17 # Should-Stop:    $remote_fs
18 # Default-Start:     3 4 5
19 # Default-Stop:      0 1 2 6
20 # Short-Description: MongoDB server
21 # Description:       Starts and stops the MongoDB daemon
22 ### END INIT INFO
23
24 # Source function library
25 . /etc/rc.d/init.d/functions
26
27 # Get network config
28 . /etc/sysconfig/network
29
30 # Check that networking is up.
31 if is_yes "${NETWORKING}"; then
32         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
33                 msg_network_down "mongod"
34                 exit 1
35         fi
36 else
37         exit 0
38 fi
39
40 MONGOD_BIN="/usr/bin/mongod"
41 MONGOD_PIDFILE="/var/run/mongod.pid"
42 MONGOD_CONFIG="/etc/sysconfig/mongod"
43
44 MONGOD_USER=mongod
45 MONGOD_GROUP=mongod
46
47 # Get service config
48 [ -f /etc/sysconfig/mongod ] && . /etc/sysconfig/mongod
49
50 start() {
51         # Check if the service is already running?
52         if [ -f /var/lock/subsys/mongod ]; then
53                 msg_already_running "mongod"
54                 return
55         fi
56
57         started=0
58         for config in /etc/mongod/*.conf ; do
59                 instance=$(basename "$config" .conf)
60                 msg_starting "mongod '$instance' instance"
61                 if [ "$instance" = "default" ] ; then
62                         pidfile="$MONGOD_PIDFILE"
63                 else
64                         pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
65                 fi
66                 daemon --pidfile "$pidfile" --user $MONGOD_USER \
67                         $MONGOD_BIN --config "$config" --fork
68                 [ $? -eq 0 ] && started=$(($started + 1))
69         done
70         # at least one started - the service is running
71         [ $started -eq 0 ] && RETVAL=1
72         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
73 }
74
75 stop() {
76         if [ ! -f /var/lock/subsys/mongod ]; then
77                 msg_not_running "mongod"
78                 return
79         fi
80
81         for config in /etc/mongod/*.conf ; do
82                 instance=$(basename "$config" .conf)
83                 msg_stopping "mongod '$instance' instance"
84                 if [ "$instance" = "default" ] ; then
85                         pidfile="$MONGOD_PIDFILE"
86                 else
87                         pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
88                 fi
89                 killproc --pidfile "$pidfile" mongod
90         done
91         rm -f /var/lock/subsys/mongod >/dev/null 2>&1
92 }
93
94 condrestart() {
95         if [ ! -f /var/lock/subsys/mongod ]; then
96                 msg_not_running "mongod"
97                 RETVAL=$1
98                 return
99         fi
100
101         stop
102         start
103 }
104
105 reload() {
106         if [ ! -f /var/lock/subsys/mongod ]; then
107                 msg_not_running "mongod"
108                 RETVAL=7
109                 return
110         fi
111
112         for config in /etc/mongod/*.conf ; do
113                 instance=$(basename "$config" .conf)
114                 msg_reloading "mongod '$instance' instance"
115                 if [ "$instance" = "default" ] ; then
116                         pidfile="$MONGOD_PIDFILE"
117                 else
118                         pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
119                 fi
120                 killproc --pidfile "$pidfile" mongod -HUP
121         done
122 }
123
124 RETVAL=0
125 # See how we were called.
126 case "$1" in
127   start)
128         start
129         ;;
130   stop)
131         stop
132         ;;
133   restart)
134         stop
135         start
136         ;;
137   try-restart)
138         condrestart 0
139         ;;
140   reload|force-reload)
141         reload
142         ;;
143   status)
144         status mongod
145         exit $?
146         ;;
147   *)
148         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
149         exit 3
150 esac
151
152 exit $RETVAL
This page took 0.086173 seconds and 3 git commands to generate.