]>
Commit | Line | Data |
---|---|---|
69fbae1d | 1 | #!/bin/sh |
2 | # | |
3 | # /etc/init.d/mongod | |
4 | # | |
5 | ### BEGIN INIT INFO | |
6 | # Provides: mongod | |
7 | # Required-Start: $syslog $local_fs $network | |
8 | # Required-Stop: $syslog $local_fs $network | |
9 | # Should-Start: $remote_fs | |
10 | # Should-Stop: $remote_fs | |
11 | # Default-Start: 3 4 5 | |
12 | # Default-Stop: 0 1 2 6 | |
13 | # Short-Description: MongoDB server | |
14 | # Description: Starts and stops the MongoDB daemon | |
15 | ### END INIT INFO | |
16 | ||
17 | ||
18 | # Check for missing binaries (stale symlinks should not happen) | |
19 | # Note: Special treatment of stop for LSB conformance | |
20 | ||
21 | MONGOD_BIN="/usr/bin/mongod" | |
22 | MONGOD_LOGFILE="/var/log/mongo/mongod.log" | |
23 | MONGOD_PIDFILE="/var/run/mongod.pid" | |
24 | MONGOD_CONFIG="/etc/sysconfig/mongod" | |
25 | ||
26 | MONGOD_USER=mongod | |
27 | MONGOD_GROUP=mongod | |
28 | ||
29 | test -x $MONGOD_BIN || { echo "$MONGOD_BIN not installed"; | |
30 | if [ "$1" = "stop" ]; then exit 0; | |
31 | else exit 5; fi; } | |
32 | ||
33 | # Check for existence of needed config file and read it | |
34 | # test -r $MONGOD_CONFIG || { echo "$MONGOD_CONFIG not existing"; | |
35 | # if [ "$1" = "stop" ]; then exit 0; | |
36 | # else exit 6; fi; } | |
37 | # Read config | |
38 | # . $MONGOD_CONFIG | |
39 | ||
40 | # Read config | |
41 | [ -e $MONGOD_CONFIG ] && . $MONGOD_CONFIG | |
42 | ||
43 | ||
44 | # Source LSB init functions | |
45 | # providing start_daemon, killproc, pidofproc, | |
46 | # log_success_msg, log_failure_msg and log_warning_msg. | |
47 | # This is currently not used by UnitedLinux based distributions and | |
48 | # not needed for init scripts for UnitedLinux only. If it is used, | |
49 | # the functions from rc.status should not be sourced or used. | |
50 | #. /lib/lsb/init-functions | |
51 | ||
52 | # Shell functions sourced from /etc/rc.status: | |
53 | # rc_check check and set local and overall rc status | |
54 | # rc_status check and set local and overall rc status | |
55 | # rc_status -v be verbose in local rc status and clear it afterwards | |
56 | # rc_status -v -r ditto and clear both the local and overall rc status | |
57 | # rc_status -s display "skipped" and exit with status 3 | |
58 | # rc_status -u display "unused" and exit with status 3 | |
59 | # rc_failed set local and overall rc status to failed | |
60 | # rc_failed <num> set local and overall rc status to <num> | |
61 | # rc_reset clear both the local and overall rc status | |
62 | # rc_exit exit appropriate to overall rc status | |
63 | # rc_active checks whether a service is activated by symlinks | |
64 | . /etc/rc.status | |
65 | ||
66 | # Reset status of this service | |
67 | rc_reset | |
68 | ||
69 | # Return values acc. to LSB for all commands but status: | |
70 | # 0 - success | |
71 | # 1 - generic or unspecified error | |
72 | # 2 - invalid or excess argument(s) | |
73 | # 3 - unimplemented feature (e.g. "reload") | |
74 | # 4 - user had insufficient privileges | |
75 | # 5 - program is not installed | |
76 | # 6 - program is not configured | |
77 | # 7 - program is not running | |
78 | # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) | |
79 | # | |
80 | # Note that starting an already running service, stopping | |
81 | # or restarting a not-running service as well as the restart | |
82 | # with force-reload (in case signaling is not supported) are | |
83 | # considered a success. | |
84 | ||
85 | # Set ulimit setting | |
86 | # ulimit -n 10240 | |
87 | ulimit -n 12000 | |
88 | ||
89 | case "$1" in | |
90 | start) | |
91 | echo -n "Starting service MongoDB " | |
92 | ## Start daemon with startproc(8). If this fails | |
93 | ## the return value is set appropriately by startproc. | |
94 | /sbin/startproc -u $MONGOD_USER -g $MONGOD_GROUP -s -e $MONGOD_BIN --config /etc/mongod.conf run | |
95 | # Remember status and be verbose | |
96 | rc_status -v | |
97 | ;; | |
98 | stop) | |
99 | echo -n "Stopping service MongoDB " | |
100 | # killproc -p /var/lib/mongo/mongod.lock -t30 -TERM /usr/bin/mongod | |
101 | /sbin/killproc -TERM $MONGOD_BIN | |
102 | rc_status -v | |
103 | ;; | |
104 | try-restart|condrestart) | |
105 | ## Do a restart only if the service was active before. | |
106 | ## Note: try-restart is now part of LSB (as of 1.9). | |
107 | ## RH has a similar command named condrestart. | |
108 | if test "$1" = "condrestart"; then | |
109 | echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" | |
110 | fi | |
111 | $0 status | |
112 | if test $? = 0; then | |
113 | $0 restart | |
114 | else | |
115 | rc_reset # Not running is not a failure. | |
116 | fi | |
117 | # Remember status and be quiet | |
118 | rc_status | |
119 | ;; | |
120 | restart) | |
121 | ## Stop the service and regardless of whether it was | |
122 | ## running or not, start it again. | |
123 | $0 stop | |
124 | $0 start | |
125 | ||
126 | # Remember status and be quiet | |
127 | rc_status | |
128 | ;; | |
129 | reload) | |
130 | $0 restart | |
131 | ;; | |
132 | status) | |
133 | echo -n "Checking for service MongoDB: " | |
134 | /sbin/checkproc -p $MONGOD_PIDFILE $MONGOD_BIN | |
135 | rc_status -v | |
136 | ;; | |
137 | *) | |
138 | echo "Usage: $0 {start|stop|status|try-restart|restart|reload}" | |
139 | exit 1 | |
140 | ;; | |
141 | esac | |
142 | rc_exit |