Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / landscape / manager / | server ip : 104.21.89.46 your ip : 172.69.130.117 H O M E |
Filename | /usr/lib/python2.7/dist-packages/landscape/manager/processkiller.py |
Size | 2.8 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 20-Feb-2014 23:01 |
Last accessed | 06-Jul-2025 20:00 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
import os
import signal
import logging
from datetime import datetime
from landscape.lib.process import ProcessInformation
from landscape.manager.plugin import ManagerPlugin
class ProcessNotFoundError(Exception):
pass
class ProcessMismatchError(Exception):
pass
class SignalProcessError(Exception):
pass
class ProcessKiller(ManagerPlugin):
"""
A management plugin that signals processes upon receiving a message from
the server.
"""
def __init__(self, process_info=None):
if process_info is None:
process_info = ProcessInformation()
self.process_info = process_info
def register(self, registry):
super(ProcessKiller, self).register(registry)
registry.register_message("signal-process",
self._handle_signal_process)
def _handle_signal_process(self, message):
self.call_with_operation_result(message, self.signal_process,
message["pid"], message["name"],
message["start-time"],
message["signal"])
def signal_process(self, pid, name, start_time, signame):
logging.info("Sending %s signal to the process with PID %d.",
signame, pid)
process_info = self.process_info.get_process_info(pid)
if not process_info:
start_time = datetime.utcfromtimestamp(start_time)
message = ("The process %s with PID %d that started at %s UTC was "
"not found") % (name, pid, start_time)
raise ProcessNotFoundError(message)
elif abs(process_info["start-time"] - start_time) > 2:
# We don't check that the start time matches precisely because
# the way we obtain boot times isn't very precise, and this may
# cascade into having imprecise process start times.
expected_time = datetime.utcfromtimestamp(start_time)
actual_time = datetime.utcfromtimestamp(process_info["start-time"])
message = ("The process %s with PID %d that started at "
"%s UTC was not found. A process with the same "
"PID that started at %s UTC was found and not "
"sent the %s signal") % (name, pid, expected_time,
actual_time, signame)
raise ProcessMismatchError(message)
signum = getattr(signal, "SIG%s" % (signame,))
try:
os.kill(pid, signum)
except:
# XXX Nothing is indicating what the problem was.
message = ("Attempting to send the %s signal to the process "
"%s with PID %d failed") % (signame, name, pid)
raise SignalProcessError(message)
import signal
import logging
from datetime import datetime
from landscape.lib.process import ProcessInformation
from landscape.manager.plugin import ManagerPlugin
class ProcessNotFoundError(Exception):
pass
class ProcessMismatchError(Exception):
pass
class SignalProcessError(Exception):
pass
class ProcessKiller(ManagerPlugin):
"""
A management plugin that signals processes upon receiving a message from
the server.
"""
def __init__(self, process_info=None):
if process_info is None:
process_info = ProcessInformation()
self.process_info = process_info
def register(self, registry):
super(ProcessKiller, self).register(registry)
registry.register_message("signal-process",
self._handle_signal_process)
def _handle_signal_process(self, message):
self.call_with_operation_result(message, self.signal_process,
message["pid"], message["name"],
message["start-time"],
message["signal"])
def signal_process(self, pid, name, start_time, signame):
logging.info("Sending %s signal to the process with PID %d.",
signame, pid)
process_info = self.process_info.get_process_info(pid)
if not process_info:
start_time = datetime.utcfromtimestamp(start_time)
message = ("The process %s with PID %d that started at %s UTC was "
"not found") % (name, pid, start_time)
raise ProcessNotFoundError(message)
elif abs(process_info["start-time"] - start_time) > 2:
# We don't check that the start time matches precisely because
# the way we obtain boot times isn't very precise, and this may
# cascade into having imprecise process start times.
expected_time = datetime.utcfromtimestamp(start_time)
actual_time = datetime.utcfromtimestamp(process_info["start-time"])
message = ("The process %s with PID %d that started at "
"%s UTC was not found. A process with the same "
"PID that started at %s UTC was found and not "
"sent the %s signal") % (name, pid, expected_time,
actual_time, signame)
raise ProcessMismatchError(message)
signum = getattr(signal, "SIG%s" % (signame,))
try:
os.kill(pid, signum)
except:
# XXX Nothing is indicating what the problem was.
message = ("Attempting to send the %s signal to the process "
"%s with PID %d failed") % (signame, name, pid)
raise SignalProcessError(message)