-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongod.init
168 lines (147 loc) · 3.2 KB
/
mongod.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh
#
# mongod init file for starting up the MongoDB server
#
# chkconfig: - 90 10
# description: Starts and stops the MongDB daemon that handles all \
# database requests.
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/bin/mongod"
prog="mongod"
logfile="/var/log/mongodb/mongodb.log"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
pidfile=${PIDFILE-/var/run/mongodb/mongod.pid}
options="$MONGODB_OPTIONS $OPTIONS"
lockfile="/var/lock/subsys/mongod"
# Nicer version of killproc that does not kill mongodb when it takes
# a long time to shut down and does not hang for a long time when mongo
# shuts down quickly
killproc_nice() {
local RC base pid pid_file= delay i
RC=0; delay=3
# Test syntax.
if [ "$#" -eq 0 ]; then
echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
return 1
fi
if [ "$1" = "-p" ]; then
pid_file=$2
shift 2
fi
if [ "$1" = "-d" ]; then
delay=$2
shift 2
fi
# Save basename.
base=${1##*/}
# Find pid.
__pids_var_run "$1" "$pid_file"
RC=$?
if [ -z "$pid" ]; then
if [ -z "$pid_file" ]; then
pid="$(__pids_pidof "$1")"
else
[ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
fi
fi
# Kill it.
if [ -n "$pid" ] ; then
[ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
if checkpid $pid 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $pid >/dev/null 2>&1
usleep 100000
# Check every one second if the program is stopped.
# Do so for a maximum of $delay seconds
for ((i = 0 ; i < $delay; i++))
do
if checkpid $pid; then
sleep 1
else
break
fi
done
# If the program is not stopped, kill it
if checkpid $pid ; then
kill -KILL $pid >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $pid
RC=$?
[ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
RC=$((! $RC))
else
failure $"$base shutdown"
RC=0
fi
# Remove pid file if any.
rm -f "${pid_file:-/var/run/$base.pid}"
return $RC
}
start() {
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} --user mongodb "$exec $options run >> $logfile 2>&1 &"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc_nice -p ${pidfile} -d 300 $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status -p ${pidfile} $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?