Verisons
- CentOS 6.4
- Oracle Java 1.6 JDK
- MongoDB 2.4
Prerequisites
Install
1. Download, extract tar and mv to /usr/lib
1 2 3 |
wget http://commondatastorage.googleapis.com/andreidata/mongoser.tar.gz tar xvf mongoser.tar.gz sudo mv mongoser /usr/lib |
Install as a service
1. Edit /etc/init.d/mongoser
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#!/bin/sh # # chkconfig: 2345 80 80 # # Bash script to run mongoser.sh as a service # # Note: Normal env variables are discarded by service. So must export JAVA_HOME here, see http://serverfault.com/questions/374404/service-command-and-environment-variables export JAVA_HOME=/usr/java/latest MONGOSER_HOME=/usr/lib/mongoser MONGOSER_DAEMON=bin/mongoser.sh MONGOSER_USER=root START_OPTIONS=start STOP_OPTIONS=stop start() { echo "Starting Mongoser Java REST for MongoDB..." su --preserve-environment $MONGOSER_USER -c "cd $MONGOSER_HOME && $MONGOSER_DAEMON $START_OPTIONS" return 0 } stop() { echo "Stopping Mongoser Java REST for MongoDB..." su --preserve-environment $MONGOSER_USER -c "cd $MONGOSER_HOME && $MONGOSER_DAEMON $STOP_OPTIONS" return 0 } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit $? |
Note: the script hard codes JAVA_HOME, but this could be deferred to the /etc/sysconfig/mongoser script (which you must create) if desired. Note that the normal /etc/profile.sh is *not* run for services.
2. Make it executable
1 |
sudo chmod +x /etc/init.d/mongoser |
3. Start service
1 |
sudo service mongoser start |
4. Start service on boot
1 |
sudo chkconfig mongoser on |
Test
1. Get a list of databases
1 |
curl -i "http://localhost:8081/database" |
Output:
1 2 3 4 5 6 |
HTTP/1.1 200 OK Cache-Control: no-cache,no-store,must-revalidate Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked ["local"] |