Skip to content

Commit

Permalink
Fix daemon problem: start now checks is_running.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss authored and wjblanke committed Jun 1, 2020
1 parent 6de2c76 commit d216249
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ async def kill_service(root_path, services, service_name, delay_before_kill=15):
return 1


def is_running(services, service_name):
process = services.get(service_name)
return process is not None and process.poll() is None


def create_server_for_daemon(root_path):
routes = web.RouteTableDef()

Expand All @@ -114,7 +119,7 @@ async def start_service(request):
r = "unknown service"
return web.Response(text=str(r))

if service_name in services:
if is_running(services, service_name):
r = "already running"
return web.Response(text=str(r))

Expand All @@ -135,10 +140,9 @@ async def stop_service(request):
return web.Response(text=str(r))

@routes.get('/daemon/service/is_running/')
async def is_running(request):
async def is_running_handler(request):
service_name = request.query.get("service")
process = services.get(service_name)
r = process is not None and process.poll() is None
r = is_running(services, service_name)
return web.Response(text=str(r))

@routes.get('/daemon/exit/')
Expand Down

0 comments on commit d216249

Please sign in to comment.