Advertisement
Guest User

mongod-init-7254

a guest
Feb 4th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.25 KB | None | 0 0
  1. #!/bin/sh
  2. # init.d script with LSB support.
  3. #
  4. # Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
  5. #
  6. # This is free software; you may redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2,
  9. # or (at your option) any later version.
  10. #
  11. # This is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License with
  17. # the Debian operating system, in /usr/share/common-licenses/GPL; if
  18. # not, write to the Free Software Foundation, Inc., 59 Temple Place,
  19. # Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. ### BEGIN INIT INFO
  22. # Provides: mongod_data_d
  23. # Required-Start: $network $local_fs $remote_fs
  24. # Required-Stop: $network $local_fs $remote_fs
  25. # Should-Start: $named
  26. # Should-Stop:
  27. # Default-Start: 2 3 4 5
  28. # Default-Stop: 0 1 6
  29. # Short-Description: An object/document-oriented database
  30. # Description: MongoDB is a high-performance, open source, schema-free
  31. # document-oriented data store that's easy to deploy, manage
  32. # and use. It's network accessible, written in C++ and offers
  33. # the following features:
  34. #
  35. # * Collection oriented storage - easy storage of object-
  36. # style data
  37. # * Full index support, including on inner objects
  38. # * Query profiling
  39. # * Replication and fail-over support
  40. # * Efficient storage of binary data including large
  41. # objects (e.g. videos)
  42. # * Auto-sharding for cloud-level scalability (Q209)
  43. #
  44. # High performance, scalability, and reasonable depth of
  45. # functionality are the goals for the project.
  46. ### END INIT INFO
  47.  
  48. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  49. DAEMON=/usr/bin/mongod
  50. DESC=database
  51.  
  52. NAME=mongod_data_d
  53. # Defaults. Can be overridden by the /etc/default/$NAME
  54. # Other configuration options are located in $CONF file. See here for more:
  55. # http://docs.mongodb.org/manual/reference/configuration-options/
  56. CONF="/etc/mongod_data_d.conf"
  57. DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONF"`
  58. PIDFILE=`awk -F= '/^pidfilepath=/{print $2}' "$CONF"`
  59. ENABLE_MONGODB=yes
  60.  
  61. # Handle NUMA access to CPUs (SERVER-3574)
  62. # This verifies the existence of numactl as well as testing that the command works
  63. NUMACTL_ARGS="--interleave=all"
  64. if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
  65. then
  66. NUMACTL="numactl $NUMACTL_ARGS"
  67. else
  68. NUMACTL=""
  69. fi
  70.  
  71. if test ! -x $DAEMON; then
  72. echo "Could not find $DAEMON"
  73. exit 0
  74. fi
  75.  
  76. if test "x$ENABLE_MONGODB" != "xyes"; then
  77. exit 0
  78. fi
  79.  
  80. . /lib/lsb/init-functions
  81.  
  82. STARTTIME=1
  83. DIETIME=10 # Time to wait for the server to die, in seconds
  84. # If this value is set too low you might not
  85. # let some servers to die gracefully and
  86. # 'restart' will not work
  87.  
  88. DAEMONUSER=mongodb
  89. DAEMONGROUP=mongodb
  90. DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"}
  91.  
  92. set -e
  93.  
  94. running_pid() {
  95. # Check if a given process pid's cmdline matches a given name
  96. pid=$1
  97. name=$2
  98. [ -z "$pid" ] && return 1
  99. [ ! -d /proc/$pid ] && return 1
  100. cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
  101. # Is this the expected server
  102. [ "$cmd" != "$name" ] && return 1
  103. return 0
  104. }
  105.  
  106. running() {
  107. # Check if the process is running looking at /proc
  108. # (works for all users)
  109.  
  110. # No pidfile, probably no daemon present
  111. [ ! -f "$PIDFILE" ] && return 1
  112. pid=`cat $PIDFILE`
  113. running_pid $pid $DAEMON || return 1
  114. return 0
  115. }
  116.  
  117. start_server() {
  118. mkdir -p $DBPATH || exit 5
  119. chown -R ${DAEMONUSER}:${DAEMONGROUP} $DBPATH
  120. # Start the process using the wrapper
  121. # start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
  122. # --make-pidfile --chuid $DAEMONUSER \
  123. # --exec $NUMACTL $DAEMON -- $DAEMON_OPTS
  124. ### bchecketts change here, remove the --make-pidfile option
  125. start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
  126. --chuid $DAEMONUSER \
  127. --exec $NUMACTL $DAEMON -- $DAEMON_OPTS
  128. errcode=$?
  129. return $errcode
  130. }
  131.  
  132. stop_server() {
  133. # Stop the process using the wrapper
  134. start-stop-daemon --stop --quiet --pidfile $PIDFILE \
  135. --retry 300 \
  136. --user $DAEMONUSER \
  137. --exec $DAEMON
  138. errcode=$?
  139. return $errcode
  140. }
  141.  
  142. force_stop() {
  143. # Force the process to die killing it manually
  144. [ ! -e "$PIDFILE" ] && return
  145. if running ; then
  146. kill -15 $pid
  147. # Is it really dead?
  148. sleep "$DIETIME"s
  149. if running ; then
  150. kill -9 $pid
  151. sleep "$DIETIME"s
  152. if running ; then
  153. echo "Cannot kill $NAME (pid=$pid)!"
  154. exit 1
  155. fi
  156. fi
  157. fi
  158. rm -f $PIDFILE
  159. }
  160.  
  161.  
  162. case "$1" in
  163. start)
  164. log_daemon_msg "Starting $DESC" "$NAME"
  165. # Check if it's running first
  166. if running ; then
  167. log_progress_msg "apparently already running"
  168. log_end_msg 0
  169. exit 0
  170. fi
  171. if start_server ; then
  172. # NOTE: Some servers might die some time after they start,
  173. # this code will detect this issue if STARTTIME is set
  174. # to a reasonable value
  175. [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
  176. if running ; then
  177. # It's ok, the server started and is running
  178. log_end_msg 0
  179. else
  180. # It is not running after we did start
  181. log_end_msg 1
  182. fi
  183. else
  184. # Either we could not start it
  185. log_end_msg 1
  186. fi
  187. ;;
  188. stop)
  189. log_daemon_msg "Stopping $DESC" "$NAME"
  190. if running ; then
  191. # Only stop the server if we see it running
  192. errcode=0
  193. stop_server || errcode=$?
  194. log_end_msg $errcode
  195. else
  196. # If it's not running don't do anything
  197. log_progress_msg "apparently not running"
  198. log_end_msg 0
  199. exit 0
  200. fi
  201. ;;
  202. force-stop)
  203. # First try to stop gracefully the program
  204. $0 stop
  205. if running; then
  206. # If it's still running try to kill it more forcefully
  207. log_daemon_msg "Stopping (force) $DESC" "$NAME"
  208. errcode=0
  209. force_stop || errcode=$?
  210. log_end_msg $errcode
  211. fi
  212. ;;
  213. restart|force-reload)
  214. log_daemon_msg "Restarting $DESC" "$NAME"
  215. errcode=0
  216. stop_server || errcode=$?
  217. # Wait some sensible amount, some server need this
  218. [ -n "$DIETIME" ] && sleep $DIETIME
  219. start_server || errcode=$?
  220. [ -n "$STARTTIME" ] && sleep $STARTTIME
  221. running || errcode=$?
  222. log_end_msg $errcode
  223. ;;
  224. status)
  225.  
  226. log_daemon_msg "Checking status of $DESC" "$NAME"
  227. if running ; then
  228. log_progress_msg "running"
  229. log_end_msg 0
  230. else
  231. log_progress_msg "apparently not running"
  232. log_end_msg 1
  233. exit 1
  234. fi
  235. ;;
  236. # MongoDB can't reload its configuration.
  237. reload)
  238. log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
  239. log_warning_msg "cannot re-read the config file (use restart)."
  240. ;;
  241.  
  242. *)
  243. N=/etc/init.d/$NAME
  244. echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
  245. exit 1
  246. ;;
  247. esac
  248.  
  249. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement