Skip to content

Instantly share code, notes, and snippets.

@georgefs
Last active December 19, 2015 17:48
Show Gist options
  • Select an option

  • Save georgefs/5993646 to your computer and use it in GitHub Desktop.

Select an option

Save georgefs/5993646 to your computer and use it in GitHub Desktop.
mongodb /etc/init.d script
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2013 george
#
# Distributed under terms of the MIT license.
__all__ = []
import os
import sys
import re
MONGO = "/opt/mongodb-linux-x86_64-2.4.5/bin/mongod"
DB_PATH = "/opt/mongodb-linux-x86_64-2.4.5/db"
LOG_PATH = "/tmp/mongodb.log"
PID_PATH = "/tmp/mongodb.pid"
def start():
cmd = "{} --dbpath {} --logpath {} --pidfilepath {} --auth --fork".format(MONGO, DB_PATH, LOG_PATH, PID_PATH)
print cmd
i,o = os.popen4(cmd)
print o.read()
def stop():
pids = open(PID_PATH).read().split('\n')
for pid in pids:
if pid:
cmd = "kill -9 {}".format(pid)
i,o = os.popen4(cmd)
print o.read()
def restart():
stop()
start()
if __name__ == '__main__':
argv = sys.argv
cmd = argv[1]
locals()[cmd]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment