def restart_server(args_port): devnull = open('/dev/null', 'w') if args_port: ports = [args_port] else: ports = daemonize.get_ports_running() if not ports: logger.error('Faraday Server is not running') sys.exit(1) for port in ports: stop_server(port) params = ['/usr/bin/env', 'python2.7',\ os.path.join(server.config.FARADAY_BASE, __file__), '--no-setup', '--port', str(port)] logger.info('Restarting Faraday Server...') subprocess.Popen(params, stdout=devnull, stderr=devnull) logger.info('Faraday Server is running as a daemon in port {}'.format(port))
def main(): os.chdir(FARADAY_BASE) check_alembic_version() check_postgresql() parser = argparse.ArgumentParser() parser.add_argument('--ssl', action='store_true', help='enable HTTPS') parser.add_argument('--debug', action='store_true', help='run Faraday Server in debug mode') parser.add_argument('--start', action='store_true', help='run Faraday Server in background') parser.add_argument('--stop', action='store_true', help='stop Faraday Server') parser.add_argument('--restart', action='store_true', help='Restart Faraday Server') parser.add_argument('--nodeps', action='store_true', help='Skip dependency check') parser.add_argument('--no-setup', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--port', help='Overides server.ini port configuration') parser.add_argument('--websocket_port', help='Overides server.ini websocket port configuration') parser.add_argument('--bind_address', help='Overides server.ini bind_address configuration') f = open(server.config.VERSION_FILE) f_version = f.read().strip() parser.add_argument('-v', '--version', action='version', version='Faraday v{version}'.format(version=f_version)) args = parser.parse_args() setUpLogger(args.debug) if args.debug: server.utils.logger.set_logging_level(server.config.DEBUG) if args.restart: restart_server(args.port) sys.exit() if args.stop: if args.port: sys.exit(0 if stop_server(args.port) else 1) else: ports = daemonize.get_ports_running() if not ports: logger.info('Faraday Server is not running') exit_code = 0 for port in ports: exit_code += 0 if stop_server(port) else 1 sys.exit(exit_code) else: if not args.port: args.port = '5985' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex((args.bind_address or server.config.faraday_server.bind_address, int(args.port or server.config.faraday_server.port))) if is_server_running(args.port) and result == 0: sys.exit(1) if result == 0: logger.error("Faraday Server port in use. Check your processes and run the server again...") sys.exit(1) # Overwrites config option if SSL is set by argument if args.ssl: server.config.ssl.enabled = 'true' if not args.no_setup: setup_environment(not args.nodeps) if args.port: server.config.faraday_server.port = args.port if args.bind_address: server.config.faraday_server.bind_address = args.bind_address if args.websocket_port: server.config.faraday_server.websocket_port = args.websocket_port if args.start: # Starts a new process on background with --ignore-setup # and without --start nor --stop devnull = open('/dev/null', 'w') params = ['/usr/bin/env', 'python2.7', os.path.join(server.config.FARADAY_BASE, __file__), '--no-setup'] arg_dict = vars(args) for arg in arg_dict: if arg not in ["start", "stop"] and arg_dict[arg]: params.append('--'+arg) if arg_dict[arg] != True: params.append(arg_dict[arg]) logger.info('Faraday Server is running as a daemon') subprocess.Popen(params, stdout=devnull, stderr=devnull) elif not args.start: run_server(args)
def main(): os.chdir(FARADAY_BASE) check_alembic_version() check_postgresql() parser = argparse.ArgumentParser() parser.add_argument('--ssl', action='store_true', help='enable HTTPS') parser.add_argument('--debug', action='store_true', help='run Faraday Server in debug mode') parser.add_argument('--start', action='store_true', help='run Faraday Server in background') parser.add_argument('--stop', action='store_true', help='stop Faraday Server') parser.add_argument('--restart', action='store_true', help='Restart Faraday Server') parser.add_argument('--nodeps', action='store_true', help='Skip dependency check') parser.add_argument('--no-setup', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--port', help='Overides server.ini port configuration') parser.add_argument( '--websocket_port', help='Overides server.ini websocket port configuration') parser.add_argument('--bind_address', help='Overides server.ini bind_address configuration') f = open(server.config.VERSION_FILE) f_version = f.read().strip() parser.add_argument('-v', '--version', action='version', version='Faraday v{version}'.format(version=f_version)) args = parser.parse_args() setUpLogger(args.debug) if args.debug: server.utils.logger.set_logging_level(server.config.DEBUG) if args.restart: restart_server(args.port) sys.exit() if args.stop: if args.port: sys.exit(0 if stop_server(args.port) else 1) else: ports = daemonize.get_ports_running() if not ports: logger.info('Faraday Server is not running') exit_code = 0 for port in ports: exit_code += 0 if stop_server(port) else 1 sys.exit(exit_code) else: if not args.port: args.port = '5985' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex( (args.bind_address or server.config.faraday_server.bind_address, int(args.port or server.config.faraday_server.port))) if is_server_running(args.port) and result == 0: sys.exit(1) if result == 0: logger.error( "Faraday Server port in use. Check your processes and run the server again..." ) sys.exit(1) # Overwrites config option if SSL is set by argument if args.ssl: server.config.ssl.enabled = 'true' if not args.no_setup: setup_environment(not args.nodeps) if args.port: server.config.faraday_server.port = args.port if args.bind_address: server.config.faraday_server.bind_address = args.bind_address if args.websocket_port: server.config.faraday_server.websocket_port = args.websocket_port if args.start: # Starts a new process on background with --ignore-setup # and without --start nor --stop devnull = open('/dev/null', 'w') params = [ '/usr/bin/env', 'python2.7', os.path.join(server.config.FARADAY_BASE, __file__), '--no-setup' ] arg_dict = vars(args) for arg in arg_dict: if arg not in ["start", "stop"] and arg_dict[arg]: params.append('--' + arg) if arg_dict[arg] != True: params.append(arg_dict[arg]) logger.info('Faraday Server is running as a daemon') subprocess.Popen(params, stdout=devnull, stderr=devnull) elif not args.start: run_server(args)