MongoDB Install

by plumata
2 deployments · 1 still active · last rev. 6 years ago

Installs MongoDB on Debian platforms. Tested on Ubuntu 9.10 x86_64. I basically copy and pasted everything from this page: http://library.linode.com/databases/mongodb/

Report any errors/bugs to Charles Hooper <chooper@plumata.com>

Compatible with: No distros currently supported
						#!/bin/sh
#
# install_mongo.sh
#
# Summary: Installs MongoDB on Debian platforms. Tested on Ubuntu 9.10 x86_64.
#
# I basically copied and pasted everything from this page:
# http://library.linode.com/databases/mongodb/
#
# Copyright (c) 2010, Charles Hooper <chooper@plumata.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, 
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# * Neither the name of Plumata LLC nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.


BASEURL="http://downloads.mongodb.org/linux/"
FILENAME="mongodb-linux-`uname -m`-1.2.2.tgz"
DIRNAME=`echo "${FILENAME}" | sed -e 's/.tgz//'`

cd /tmp

# Make all needed directories and create files
mkdir -p /opt/bin /opt/config /srv/db/mongodb
touch /srv/db/mongodb.log

# Download and extract MongoDB
wget "${BASEURL}${FILENAME}" && tar xzvf "${FILENAME}"
mv "${DIRNAME}" /opt/
ln -s /opt/${DIRNAME} /opt/mongodb

# Install various scripts and config files
cat > /opt/bin/mongodb-stop << EOF
#!/bin/bash

pid=\`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print \$1}'\`;
if [ "\${pid}" != "" ]; then
    kill -2 \${pid};
fi
EOF

cat > /opt/bin/mongodb-start << EOF
#!/bin/sh

/opt/mongodb/bin/mongod --config /opt/config/mongodb \
## --upgrade \ ##runs a database upgrade option if needed
EOF

cat > /opt/config/mongodb << EOF
# Configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration

dbpath = /srv/db/mongodb
logpath = /srv/db/mongodb.log
logappend = true

bind_ip = 127.0.0.1
port = 27017
fork = true

auth = true
# noauth = true
EOF

cat > /etc/init.d/mongodb << EOF
#! /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 mongodb database system
# Description:       starts mongodb using basic start scripts
### END INIT INFO

PATH=/opt/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=mongodb

test -x \$DAEMON || exit 0

set -e

case "\$1" in
  start)
        echo -n "Starting \$DESC: "

        start-stop-daemon --start --user mongodb -c mongodb:mongodb \
            --startas /opt/bin/mongodb-start

        echo "\$NAME."
        ;;
  stop)
        echo -n "Stopping \$DESC: "

        start-stop-daemon --stop --exec /opt/mongodb/bin/mongod -c mongodb:mongodb \
            /opt/bin/mongodb-stop

        echo "\$NAME."
        ;;
      *)
            N=/etc/init.d/\$NAME
            echo "Usage: \$N {start|stop}" >&2
            exit 1
            ;;
    esac

    exit 0
EOF

# Set perms on scripts
chmod +x /opt/bin/mongodb-start
chmod +x /opt/bin/mongodb-stop
chmod +x /etc/init.d/mongodb

# Start MongoDB at boot
/usr/sbin/update-rc.d -f mongodb defaults

# Create MongoDB user and finish setting perms
adduser --system --no-create-home --disabled-login --disabled-password --group mongodb || true
chown mongodb:mongodb -R /srv/db/

# Start MongoDB
/etc/init.d/mongodb start ; sleep 1 ; tail /srv/db/mongodb.log