Skip to content

Commit

Permalink
Use terminate_or_kill to stop daemon process
Browse files Browse the repository at this point in the history
We previously manually sent signals to the daemon process, but failed to
properly await for it to finish, and to send a more drastic KILL signal.
Now that we have our new ExistingProcess class we simply wrap the daemon
process into one of these and reuse our terminate_or_kill method, which
does all the proper checks and cleanups for us.

An effect of reusing terminate_or_kill is that we will use loggers, but
without having configured the codebase to use the instrumented DlgLogger
class. Thus we need to ensure that our logging configuration does *not*
include the extra record attributes included by DlgLogger.

This addresses LIU-51.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Oct 30, 2020
1 parent 79a4d25 commit db479d7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions daliuge-runtime/dlg/manager/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
like DMs and DIMs.
"""

import errno
import logging
import os
import signal
Expand Down Expand Up @@ -153,14 +152,10 @@ def start(options, parser):
if pid is None:
sys.stderr.write('Cannot read PID file, is there an instance running?\n')
else:
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
# Process is gone and file was left dangling,
# let's clean it up ourselves
if e.errno == errno.ESRCH:
sys.stderr.write('Process %d does not exist, removing PID file')
os.unlink(pidfile)
utils.terminate_or_kill(utils.ExistingProcess(pid), 5)
if os.path.exists(pidfile):
sys.stderr.write('Process %d does not exist, removing PID file\n' % (pid,))
os.unlink(pidfile)

# Check status
elif options.status:
Expand Down Expand Up @@ -202,8 +197,13 @@ def setupLogging(opts):
# optionally a session_id and drop_uid to indicate what is currently being
# executed. This only applies to the NodeManager logs though, for which a
# 'no_log_ids' option exists (but can be set to True).
# We also skip logging IDs when stopping a daemon, as the infrastructure
# won't have been set
log_ids = (opts.dmType == NodeManager and
not opts.no_log_ids and
not opts.stop)
fmt = '%(asctime)-15s [%(levelname)5.5s] [%(threadName)15.15s] '
if opts.dmType == NodeManager and not opts.no_log_ids:
if log_ids:
fmt += '[%(session_id)10.10s] [%(drop_uid)10.10s] '
fmt += '%(name)s#%(funcName)s:%(lineno)s %(message)s'
fmt = logging.Formatter(fmt)
Expand Down

0 comments on commit db479d7

Please sign in to comment.