Skip to content

Instantly share code, notes, and snippets.

@jaffarc
Created August 26, 2020 17:57
Show Gist options
  • Save jaffarc/42ea9f3811557b816db76459920a87d8 to your computer and use it in GitHub Desktop.
Save jaffarc/42ea9f3811557b816db76459920a87d8 to your computer and use it in GitHub Desktop.

Revisions

  1. vanilladesk revised this gist Sep 10, 2010. 1 changed file with 78 additions and 38 deletions.
    116 changes: 78 additions & 38 deletions mongodb_initd.sh
    Original file line number Diff line number Diff line change
    @@ -1,55 +1,95 @@
    #! /bin/sh
    #!/bin/sh

    ### BEGIN INIT INFO
    # Provides: mongodb
    # Required-Start: $all
    # Required-Stop: $all
    # Provides: mongod
    # Required-Start: $local_fs $remote_fs $network $syslog
    # Required-Stop: $local_fs $remote_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: starts the mongodb data-store
    # Description: starts mongodb using start-stop-daemon
    # Short-Description: Starts the MongoDB database server
    # Description: Starts the MongoDB database server
    ### END INIT INFO

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/local/sbin/mongod
    PIDFILE=/var/run/mongodb.pid
    LOGFILE=/var/log/mongod.log
    DATAFLD=/data/db
    NAME=mongodb
    DESC=mongodb

    test -x $DAEMON || exit 0
    # Full name of daemon
    DAEMON=/usr/local/bin/mongod

    #set -e
    # Daemon command line options
    DAEMON_OPTS="-f /etc/mongodb/mongod.conf"

    # Daemon name. Used also for pid file creation.
    NAME="mongod"

    # Daemon description
    DESC="MongoDB database server"

    # User account used to run mongod daemon
    USER="mongodb"

    # Replica set name (modify in case you would like to run mongod
    # configured as replica set node - see http://www.mongodb.org/display/DOCS/Replica+Sets)
    RS_NAME=""

    # In case mongod is configured as replica-set node, then RS_SEED
    # can contain comma separated seed nodes or e.g. command to get
    # the list of seed nodes, e.g. RS_SEED="host1:port1,host2:port2,host3"
    # or something like RS_SEED="`get_seed_nodes`" (see Reg2Rep project
    # at http://github.com/vanilladesk/reg2rep for example of using
    # remote registry for keeping list of seed nodes in a dynamic environment)
    RS_SEED=""

    #------------------------------------------------

    # if RS_SEED is defined and RS_NAME too, then append RS_SEED to RS_NAME
    [ "$RS_SEED" ] && [ "$RS_NAME" ] && RS_NAME="$RS_NAME/$RS_SEED"

    # if RS_NAME is defined, then include it in daemon command line options
    [ "$RS_NAME" ] && DAEMON_OPTS="--replSet $RS_NAME $DAEMON_OPTS"

    [ -e $DAEMON ] || exit 0

    set -e

    . /lib/lsb/init-functions

    function d_start {
    echo -n "Starting $DESC: "
    start-stop-daemon --start --background --quiet \
    --make-pidfile --pidfile /var/run/$NAME.pid \
    --chuid $USER \
    --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME $DAEMON_OPTS"

    }

    function d_stop {
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
    --exec $DAEMON || true
    echo "$NAME."

    }

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    start-stop-daemon --pidfile $PIDFILE --exec $DAEMON --start -- run >> $LOGFILE&
    echo "$NAME."
    ;;
    d_start
    ;;
    stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --quiet --pidfile $PIFDILE --exec $DAEMON --stop
    echo "$NAME."
    ;;
    d_stop
    ;;
    restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --quiet --pidfile $PIDFILE --exec $DAEMON --stop
    sleep 1
    start-stop-daemon --quiet --pidfile $PIDFILE --exec $DAEMON --start -- run >> $LOGFILE&
    echo "$NAME."
    ;;
    reload)
    echo -n "Reloading $DESC configuration: "
    start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE --exec $DAEMON
    echo "$NAME."
    ;;
    d_stop
    sleep 1
    d_start
    ;;
    status)
    status_of_proc -p /var/run/$NAME.pid "$DAEMON" mongod && exit 0 || exit $?
    ;;
    *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
    echo "Usage: $NAME {start|stop|restart|force-reload|status}" >&2
    exit 1
    ;;
    esac

    exit 0
    exit 0
  2. vanilladesk renamed this gist Jul 12, 2010. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.sh → mongodb_initd.sh
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,9 @@

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/local/sbin/mongod
    PIDFILE=/usr/local/mongodb/logs/mongodb.pid
    LOGFILE=/usr/local/mongodb/logs/mongod.log
    PIDFILE=/var/run/mongodb.pid
    LOGFILE=/var/log/mongod.log
    DATAFLD=/data/db
    NAME=mongodb
    DESC=mongodb

  3. @tpitale tpitale created this gist Aug 5, 2009.
    54 changes: 54 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #! /bin/sh

    ### BEGIN INIT INFO
    # Provides: mongodb
    # Required-Start: $all
    # Required-Stop: $all
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: starts the mongodb data-store
    # Description: starts mongodb using start-stop-daemon
    ### END INIT INFO

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/local/sbin/mongod
    PIDFILE=/usr/local/mongodb/logs/mongodb.pid
    LOGFILE=/usr/local/mongodb/logs/mongod.log
    NAME=mongodb
    DESC=mongodb

    test -x $DAEMON || exit 0

    #set -e

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    start-stop-daemon --pidfile $PIDFILE --exec $DAEMON --start -- run >> $LOGFILE&
    echo "$NAME."
    ;;
    stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --quiet --pidfile $PIFDILE --exec $DAEMON --stop
    echo "$NAME."
    ;;
    restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --quiet --pidfile $PIDFILE --exec $DAEMON --stop
    sleep 1
    start-stop-daemon --quiet --pidfile $PIDFILE --exec $DAEMON --start -- run >> $LOGFILE&
    echo "$NAME."
    ;;
    reload)
    echo -n "Reloading $DESC configuration: "
    start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE --exec $DAEMON
    echo "$NAME."
    ;;
    *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
    esac

    exit 0