Skip to content

Commit

Permalink
-P 0, -P 1 to check_port
Browse files Browse the repository at this point in the history
  • Loading branch information
ali96343 committed Dec 27, 2023
1 parent 43b66f2 commit e9bed4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ def run(**kwargs):
'You have not set a dashboard password. Run "%s set_password" to do so.'
% PY4WEB_CMD
)
elif "_dashboard" in Reloader.ROUTES and (not kwargs['host'].startswith('unix:')) :
elif "_dashboard" in Reloader.ROUTES and (not kwargs['host'].startswith('unix:/')) :
click.echo(
f"Dashboard is at: http{'s' if kwargs.get('ssl_cert', None) else ''}://{kwargs['host']}:{kwargs['port']}/_dashboard"
)
Expand Down
17 changes: 12 additions & 5 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,25 @@ def os_cmd (run_cmd ):
if host.startswith('unix:/'):
socket_path = host[5:]
if os.path.exists(socket_path):
os_cmd ("ps -ef | head -1; ps -ef | grep py4web | grep -v grep")
os_cmd (f"ls -alFi {socket_path}")
print (f"reopen {socket_path}")
print (f'=== gunicorn listening at: {host} ===')
if port == 0:
os_cmd (f"ls -alFi {socket_path}")
sys.exit(f"can't run gunicorn: {socket_path} exists")
elif port == 1:
os_cmd ("ps -ef | head -1; ps -ef | grep py4web | grep -v grep")
os_cmd (f"ls -alFi {socket_path}")
os_cmd (f"lsof -w {socket_path}")
elif port == 8000:
pass
print (f'gunicorn listening at: {host}')
return

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((host, int(port) ))
except socket.error as e:
if e.errno == errno.EADDRINUSE:
os_cmd( f"command -v lsof >/dev/null 2>&1 && ps aux | grep py4web && lsof -nPi:{port}" )
os_cmd( f"command -v lsof >/dev/null 2>&1 && ps -ef | head -1; ps -ef |"
f" grep py4web | grep -v grep && lsof -nPi:{port}" )
sys.exit(f"{host}:{port} is already in use")
else:
sys.exit(f"{e}\n{host}:{port} cannot be acessed")
Expand Down

0 comments on commit e9bed4f

Please sign in to comment.