def up(message): pid = util.check_running() if pid: print 'Vainamoinen is already running with PID {0}.'.format(pid) else: print 'Starting Vainamoinen...' os.system('python main.py &') print 'Waiting for database connection...' while True: pid = util.check_running() if pid: break conn, channel = connect_service_queue() #for service in QUEUEMAP: # addService(service, pid, channel) close_connection(conn)
def down(message): pid = util.check_running() if pid: print 'Stopping Vainamoinen process with PID {0}'.format(pid) if message is None: message = 'Vainamoinen was stopped {0}'.format(datetime.datetime.now().strftime('%a %d %b %Y, %H:%M') ) else: message = '{0}. Stopped {1}'.format(message, datetime.datetime.now().strftime('%a %d %b %Y, %H:%M') ) collection = db.misc collection.update({'message': {'$exists': True}}, {'$set': {'message': message}}, ups=True) os.kill(pid, signal.SIGUSR1) else: print 'No PID in database: Vainamoinen is not currently running.'
def addService(service, masterpid=None, channel=None): conn=None if not masterpid and not util.check_running(): print 'Vainamoinen is not currently running.' return if service in QUEUEMAP: if not channel: conn, channel = connect_service_queue() print 'Adding {0} service'.format(service) send_request(channel, 'add_service****{0}'.format( QUEUEMAP[service] )) else: print 'Service not defined' if conn: close_connection(conn)