Skip to content

Instantly share code, notes, and snippets.

@marugoshi
Created May 8, 2010 06:19
Show Gist options
  • Save marugoshi/394400 to your computer and use it in GitHub Desktop.
Save marugoshi/394400 to your computer and use it in GitHub Desktop.
Create MongoDB Launch Item (for blog)
#!/bin/sh
#
# MongoDB OSX Launch Item
#
# usage: sudo ./install.sh
#
# initialize
DAEMON_PATH=`which mongod`
DATA_DIR="/opt/local/var/db/mongodb"
LOG_DIR="/opt/local/var/log/mongodb"
LOG_FILE="$LOG_DIR/mongodb.log"
ITEM_FILE="/Library/LaunchDaemons/org.mongo.mongod.plist"
# be should run as root
USER_ID=`id -u`
if [ $USER_ID -ne 0 ] ; then
echo "Current user is not root."
echo "usage: sudo ./install.rb"
exit 1
fi
# start
echo "Installing MongoDB Launchctl Item..."
echo "Before run this script, you should install mongodb via Macports."
# create data directory
echo "Input mongodb data directory: [$DATA_DIR]"
read data_dir
if [ "$data_dir" = "" ] ; then
data_dir=$DATA_DIR
fi
mkdir -p $data_dir
chown root:admin $data_dir
# create log directory
echo "Input log directory: [$LOG_DIR]"
read log_dir
if [ "$log_dir" = "" ] ; then
log_dir=$LOG_DIR
fi
mkdir -p $log_dir
chown root:admin $log_dir
touch $LOG_FILE
chown root:admin $LOG_FILE
# write launchctl item
cat << EOF > $ITEM_FILE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongo.mongod</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>$DAEMON_PATH</string>
<string>--dbpath</string>
<string>$DATA_DIR</string>
<string>--logpath</string>
<string>$LOG_FILE</string>
</array>
</dict>
</plist>
EOF
# finish
echo "Done."
@marugoshi
Copy link
Author

tedted on osx 10.5.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment