add api debug option
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
||||
__version__ = "3.0.5"
|
||||
__version__ = "3.0.6"
|
||||
|
||||
|
||||
+16
-10
@@ -102,12 +102,14 @@ def stop_api():
|
||||
# Read the process ID (pid) from the file
|
||||
try:
|
||||
with open(PID_FILE1, "r") as f:
|
||||
pid = int(f.read().strip())
|
||||
pid = int(f.readline().strip())
|
||||
port = int(f.readline().strip())
|
||||
PID_FILE=PID_FILE1
|
||||
except:
|
||||
try:
|
||||
with open(PID_FILE2, "r") as f:
|
||||
pid = int(f.read().strip())
|
||||
pid = int(f.readline().strip())
|
||||
port = int(f.readline().strip())
|
||||
PID_FILE=PID_FILE2
|
||||
except:
|
||||
print("Connpy api server is not running.")
|
||||
@@ -116,30 +118,34 @@ def stop_api():
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
# Delete the PID file
|
||||
os.remove(PID_FILE)
|
||||
|
||||
print(f"Server with process ID {pid} stopped.")
|
||||
return port
|
||||
|
||||
def start_server():
|
||||
def debug_api(port=8048):
|
||||
app.custom_config = configfile()
|
||||
serve(app, host='0.0.0.0', port=8048)
|
||||
app.run(debug=True, port=port)
|
||||
|
||||
def start_api():
|
||||
def start_server(port=8048):
|
||||
app.custom_config = configfile()
|
||||
serve(app, host='0.0.0.0', port=port)
|
||||
|
||||
def start_api(port=8048):
|
||||
if os.path.exists(PID_FILE1) or os.path.exists(PID_FILE2):
|
||||
print("Connpy server is already running.")
|
||||
return
|
||||
pid = os.fork()
|
||||
if pid == 0:
|
||||
start_server()
|
||||
start_server(port)
|
||||
else:
|
||||
try:
|
||||
with open(PID_FILE1, "w") as f:
|
||||
f.write(str(pid))
|
||||
f.write(str(pid) + "\n" + str(port))
|
||||
except:
|
||||
try:
|
||||
with open(PID_FILE2, "w") as f:
|
||||
f.write(str(pid))
|
||||
f.write(str(pid) + "\n" + str(port))
|
||||
except:
|
||||
print("Cound't create PID file")
|
||||
return
|
||||
print(f'Server is running with process ID {pid}.')
|
||||
print(f'Server is running with process ID {pid} in port {port}')
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ def main():
|
||||
if words[0] == "config":
|
||||
strings=["--allow-uppercase", "--keepalive", "--completion", "--fzf", "--configfolder", "--help"]
|
||||
if words[0] == "api":
|
||||
strings=["--start", "--stop", "--restart", "--help"]
|
||||
strings=["--start", "--stop", "--restart", "--debug", "--help"]
|
||||
if words[0] in ["--mod", "--edit", "-e", "--show", "-s", "--add", "-a", "--rm", "--del", "-r"]:
|
||||
strings=["profile"]
|
||||
if words[0] in ["list", "ls"]:
|
||||
|
||||
+14
-5
@@ -106,9 +106,10 @@ class connapp:
|
||||
#APIPARSER
|
||||
apiparser = subparsers.add_parser("api", help="Start and stop connpy api")
|
||||
apicrud = apiparser.add_mutually_exclusive_group(required=True)
|
||||
apicrud.add_argument("--start", dest="start", nargs=0, action=self._store_type, help="Start conppy api")
|
||||
apicrud.add_argument("--restart", dest="restart", nargs=0, action=self._store_type, help="Restart conppy api")
|
||||
apicrud.add_argument("--stop", dest="stop", nargs=0, action=self._store_type, help="Stop conppy api")
|
||||
apicrud.add_argument("-s","--start", dest="start", nargs="?", action=self._store_type, help="Start conppy api", type=int, default=8048, metavar="PORT")
|
||||
apicrud.add_argument("-r","--restart", dest="restart", nargs=0, action=self._store_type, help="Restart conppy api")
|
||||
apicrud.add_argument("-x","--stop", dest="stop", nargs=0, action=self._store_type, help="Stop conppy api")
|
||||
apicrud.add_argument("-d", "--debug", dest="debug", nargs="?", action=self._store_type, help="Run connpy server on debug mode", type=int, default=8048, metavar="PORT")
|
||||
apiparser.set_defaults(func=self._func_api)
|
||||
#CONFIGPARSER
|
||||
configparser = subparsers.add_parser("config", help="Manage app config")
|
||||
@@ -500,9 +501,17 @@ class connapp:
|
||||
|
||||
def _func_api(self, args):
|
||||
if args.command == "stop" or args.command == "restart":
|
||||
stop_api()
|
||||
args.data = stop_api()
|
||||
if args.command == "start" or args.command == "restart":
|
||||
start_api()
|
||||
if args.data:
|
||||
start_api(args.data)
|
||||
else:
|
||||
start_api()
|
||||
if args.command == "debug":
|
||||
if args.data:
|
||||
debug_api(args.data)
|
||||
else:
|
||||
debug_api()
|
||||
return
|
||||
|
||||
def _node_run(self, args):
|
||||
|
||||
Reference in New Issue
Block a user