mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
samba-tool: Add samba-tool processes subcommand
This will allow administrators to inspect the process list in a similar way to what running on a platform with setproctitle might permit. --pid= returns the registered server names for a PID (eg kdc, cldap_server) --name= returns the pids registered with a particular name. Andrew Bartlett
This commit is contained in:
parent
a732f2a621
commit
42c379f0df
@ -38,6 +38,7 @@ from samba.netcmd.testparm import cmd_testparm
|
||||
from samba.netcmd.time import cmd_time
|
||||
from samba.netcmd.user import cmd_user
|
||||
from samba.netcmd.vampire import cmd_vampire
|
||||
from samba.netcmd.processes import cmd_processes
|
||||
|
||||
|
||||
class cmd_sambatool(SuperCommand):
|
||||
@ -66,3 +67,4 @@ class cmd_sambatool(SuperCommand):
|
||||
subcommands["time"] = cmd_time()
|
||||
subcommands["user"] = cmd_user()
|
||||
subcommands["vampire"] = cmd_vampire()
|
||||
subcommands["processes"] = cmd_processes()
|
||||
|
78
source4/scripting/python/samba/netcmd/processes.py
Normal file
78
source4/scripting/python/samba/netcmd/processes.py
Normal file
@ -0,0 +1,78 @@
|
||||
# Unix SMB/CIFS implementation.
|
||||
# List processes (to aid debugging on systems without setproctitle)
|
||||
# Copyright (C) 2010-2011 Jelmer Vernooij <jelmer@samba.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Testbed for loadparm.c/params.c
|
||||
#
|
||||
# This module simply loads a specified configuration file and
|
||||
# if successful, dumps it's contents to stdout. Note that the
|
||||
# operation is performed with DEBUGLEVEL at 3.
|
||||
#
|
||||
# Useful for a quick 'syntax check' of a configuration file.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import samba
|
||||
import samba.getopt as options
|
||||
from samba.netcmd import Command, CommandError, Option
|
||||
from samba.messaging import Messaging
|
||||
|
||||
class cmd_processes(Command):
|
||||
"""List processes (to aid debugging on systems without setproctitle)."""
|
||||
|
||||
synopsis = "%prog [options]"
|
||||
|
||||
takes_optiongroups = {
|
||||
"sambaopts": options.SambaOptions,
|
||||
"versionopts": options.VersionOptions
|
||||
}
|
||||
|
||||
takes_options = [
|
||||
Option("--name", type=str,
|
||||
help="Return only processes associated with one particular name"),
|
||||
Option("--pid", type=int,
|
||||
help="Return only names assoicated with one particular PID"),
|
||||
]
|
||||
|
||||
takes_args = []
|
||||
|
||||
def run(self, sambaopts, versionopts, section_name=None,
|
||||
name=None, pid=None):
|
||||
|
||||
lp = sambaopts.get_loadparm()
|
||||
logger = self.get_logger("processes")
|
||||
|
||||
msg_ctx = Messaging()
|
||||
|
||||
if name is not None:
|
||||
ids = msg_ctx.irpc_servers_byname(name)
|
||||
for server_id in ids:
|
||||
print "%d\n" % server_id.pid
|
||||
elif pid is not None:
|
||||
names = msg_ctx.irpc_all_servers()
|
||||
for name in names:
|
||||
for server_id in name.ids:
|
||||
if server_id.pid == int(pid):
|
||||
print "%s\n" % name.name
|
||||
else:
|
||||
names = msg_ctx.irpc_all_servers()
|
||||
for name in names:
|
||||
print "%s: " % name.name
|
||||
for server_id in name.ids:
|
||||
print "%d " % server_id.pid
|
||||
print "\n"
|
35
source4/scripting/python/samba/tests/samba_tool/processes.py
Normal file
35
source4/scripting/python/samba/tests/samba_tool/processes.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Unix SMB/CIFS implementation.
|
||||
# Copyright (C) Andrew Bartlett 2012
|
||||
#
|
||||
# based on time.py:
|
||||
# Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import os
|
||||
from samba.tests.samba_tool.base import SambaToolCmdTest
|
||||
|
||||
class ProcessCmdTestCase(SambaToolCmdTest):
|
||||
"""Tests for samba-tool process subcommands"""
|
||||
|
||||
def test_name(self):
|
||||
"""Run processes command"""
|
||||
(result, out, err) = self.runcmd("processes", "--name", "samba")
|
||||
self.assertCmdSuccess(result, "Ensuring processes ran successfully")
|
||||
|
||||
def test_all(self):
|
||||
"""Run processes command"""
|
||||
(result, out, err) = self.runcmd("processes")
|
||||
self.assertCmdSuccess(result, "Ensuring processes ran successfully")
|
@ -405,6 +405,7 @@ planpythontestsuite("dc:local", "samba.tests.dcerpc.bare")
|
||||
planpythontestsuite("dc:local", "samba.tests.dcerpc.unix")
|
||||
planpythontestsuite("dc:local", "samba.tests.dcerpc.srvsvc")
|
||||
planpythontestsuite("dc:local", "samba.tests.samba_tool.timecmd")
|
||||
planpythontestsuite("dc:local", "samba.tests.samba_tool.processes")
|
||||
planpythontestsuite("dc:local", "samba.tests.samba_tool.user")
|
||||
planpythontestsuite("dc:local", "samba.tests.samba_tool.group")
|
||||
planpythontestsuite("plugin_s4_dc:local", "samba.tests.samba_tool.ntacl")
|
||||
|
Loading…
Reference in New Issue
Block a user