Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a "om <path> pg pids" action
To display the pids in the object pg, which are the pids that
would be killed by "om <path> pg kill".
  • Loading branch information
cvaroqui committed Oct 29, 2019
1 parent a6a74ee commit 5c28d19
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/node.py
Expand Up @@ -2428,6 +2428,8 @@ def action_need_aggregate(action, options):
Returns True if the action returns data from multiple sources (nodes
or services) to arrange for display.
"""
if action in ("pg_pids"):
return True
if action.startswith("print_") and options.format in ("json", "flat_json"):
return True
if action.startswith("json_"):
Expand Down
20 changes: 11 additions & 9 deletions lib/rcPgLinux.py
Expand Up @@ -347,24 +347,26 @@ def freeze(o):
def thaw(o):
return freezer(o, "THAWED")

def kill(o):
cgp = get_cgroup_path(o, "freezer")
pids = set()
for p in glob.glob(cgp+"/tasks") + glob.glob(cgp+"/*/tasks") + glob.glob(cgp+"/*/*/tasks") + glob.glob(cgp+"/cgroup.procs") + glob.glob(cgp+"/*/cgroup.procs") + glob.glob(cgp+"/*/*/cgroup.procs"):
def pids(o, controller="memory"):
cgp = get_cgroup_path(o, controller)
_pids = set()
for p in glob.glob(cgp+"/cgroup.procs") + glob.glob(cgp+"/*/cgroup.procs") + glob.glob(cgp+"/*/*/cgroup.procs") + glob.glob(cgp+"/*/*/*/cgroup.procs"):
with open(p, "r") as f:
buff = f.read()
pids |= set(buff.split("\n"))
pids.remove("")
for pid in f.readlines():
_pids.add(pid.strip())
return list(_pids)

def kill(o):
_pids = pids(o, controller="freezer")
if hasattr(o, "log"):
_o = o
else:
_o = o.svc

if len(pids) == 0:
if len(_pids) == 0:
_o.log.info("no task to kill")
return
cmd = ["kill"] + list(pids)
cmd = ["kill"] + list(_pids)
_o.vcall(cmd)

if hasattr(o, "path"):
Expand Down
6 changes: 5 additions & 1 deletion lib/svc.py
Expand Up @@ -188,6 +188,7 @@ def signal_handler(*args):
"json_base_devs",
"logs",
"podman",
"pg_pids",
"print_config",
"print_devs",
"print_exposed_devs",
Expand Down Expand Up @@ -905,7 +906,7 @@ def _action(self, action, options=None):

self.setup_signal_handlers()
self.set_skip_resources(keeprid=self.action_rid, xtags=options.xtags)
if action in ("status", "decode") or \
if action in ("status", "decode", "pg_pids") or \
action.startswith("print_") or \
action.startswith("collector") or \
action.startswith("json_"):
Expand Down Expand Up @@ -3697,6 +3698,9 @@ def pg_remove(self):
return
self.pg.remove_pg(self)

def pg_pids(self):
return sorted(self.pg.pids(self))

@lazy
def pg(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions lib/svcmgr_parser.py
Expand Up @@ -544,6 +544,13 @@
OPT.verbose,
],
},
"pg_pids": {
"msg": "Display the tasks of the service process groups or selected resources process groups.",
"options": [
OPT.filter,
OPT.format,
],
},
"pg_freeze": {
"msg": "Freeze the tasks of a process group.",
"options": mp.ACTION_OPTS,
Expand Down

0 comments on commit 5c28d19

Please sign in to comment.