def command_start(): if not os.path.isdir(DEFAULT_DIR): os.makedirs(DEFAULT_DIR) if os.path.exists(get_pid_file()): raise OSError("Already running") if args.type == 'oc': print("Using Openshift handler") handler = OpenshiftHandler(ns=args.namespace, mgr='fiomgr') else: print("'{}' handler has not been implemented yet".format(args.type)) sys.exit(1) print("Checking port 8080 is free") if port_in_use(8080): print("-> port in use") sys.exit(1) server = FIOWebService(handler=handler) print("Checking connection to {}".format(handler._target)) if server.ready or args.debug_only: print("Starting the engine") # Call the run handler to start the web service server.run() else: print("Unable to connect to {}. Are you logged in?".format( handler._target))
def command_restart(): pidfile = get_pid_file() if pid_exists(pidfile): command_stop() command_start() else: print("service not running")
def command_status(): pidfile = get_pid_file() if os.path.exists(pidfile): print("PID file : {}".format(pidfile)) pid = rfile(pidfile) print("PID : {}".format(pid)) if os.path.exists('/proc/{}'.format(pid)): state = "running" else: state = "not running" print("State : {}".format(state)) else: print("Not running") return
def command_stop(): pidfile = get_pid_file() if not os.path.exists(pidfile): print("nothing to do") return with open(pidfile) as p: pid = p.read().strip() try: os.kill(int(pid), signal.SIGTERM) except Exception: print("kill for {} caused an exception") raise else: print("engine stopped")