wsxxz 发表于 2018-10-25 10:14:17

Mongodb简介及部署

#!/bin/sh  
#
  
# mongodb      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/local/mongodb/bin/mongod"
  
prog="mongod"
  
logfile="/var/log/mongodb/mongodb.log"
  

  
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
  
pidfile=${PIDFILE-/var/run/mongodb/mongodb.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=$?
  
                [ &quot;$RC&quot; -eq 0 ] && failure $&quot;$base shutdown&quot; || success $&quot;$base shutdown&quot;
  
                RC=$((! $RC))
  
      else
  
                failure $&quot;$base shutdown&quot;
  
                RC=0
  
      fi
  

  
      # Remove pid file if any.
  
      rm -f &quot;${pid_file:-/var/run/$base.pid}&quot;
  
      return $RC
  
}
  

  
start() {
  
    [ -x $exec ] || exit 5
  
    echo -n $&quot;Starting $prog: &quot;
  
    daemon --pidfile=${pidfile} --user mongodb &quot;$exec $options run >> $logfile 2>&1&quot;
  
    retval=$?
  
    echo
  
    [ $retval -eq 0 ] && touch $lockfile
  
    return $retval
  
}
  

  
stop() {
  
    echo -n $&quot;Stopping $prog: &quot;
  
    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 &quot;$1&quot; 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 $&quot;Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}&quot;
  
      exit 2
  
esac
  
exit $?


页: [1]
查看完整版本: Mongodb简介及部署