- A+
- #!/bin/bash
- #
- # chkconfig: 2345 70 71
- # description: mongodb
- # config: /usr/local/mongodb/conf/mongodb.conf
- [ -f /etc/init.d/functions ] && source /etc/init.d/functions
- [ -f /etc/profile ] && source /etc/profile
- start() {
- /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf
- }
- stop(){
- /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf --shutdown
- }
- is_ok() {
- Port=`netstat -lntup|grep 37017|wc -l`
- if [ $Port -eq 1 ];then
- action "mongodb start..." /bin/true
- else
- action "mongodb start..." /bin/false
- fi
- }
- is_false() {
- Port=`netstat -lntup|grep 37017|wc -l`
- if [ $Port -ne 1 ];then
- action "mongodb stop..." /bin/true
- else
- action "mongodb stop..." /bin/false
- fi
- }
- case "$1" in
- start)
- start
- is_ok
- ;;
- stop)
- stop
- is_false
- ;;
- restart)
- stop
- is_false
- sleep 1
- start
- is_ok
- ;;
- *)
- echo "Usage: $0 {start|stop|restart}"
- exit 1
- esac