daily pastebin goal
84%
SHARE
TWEET

Untitled

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