Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gabriel Monnerat
slapos.toolbox
Commits
f25f6a02
Commit
f25f6a02
authored
Nov 12, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New slapos-kill command, deprecating killpidfromfile
parent
113af892
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
2 deletions
+58
-2
setup.py
setup.py
+2
-1
slapos/systool.py
slapos/systool.py
+56
-1
No files found.
setup.py
View file @
f25f6a02
...
...
@@ -65,7 +65,7 @@ setup(name=name,
'equeue = slapos.equeue:main'
,
'htpasswd = slapos.htpasswd:main'
,
'is-local-tcp-port-opened = slapos.promise.is_local_tcp_port_opened:main'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
# BBB
'runResiliencyTest = slapos.resiliencytest:runResiliencyTest'
,
'runStandaloneResiliencyTest = slapos.resiliencytest:runStandaloneResiliencyTest'
,
'lampconfigure = slapos.lamp:run [lampconfigure]'
,
...
...
@@ -79,6 +79,7 @@ setup(name=name,
'slapcontainer = slapos.container:main'
,
'slapmonitor = slapos.monitor:run_slapmonitor'
,
'slapmonitor-xml = slapos.monitor:run_slapmonitor_xml'
,
'slapos-kill = slapos.systool:kill'
,
'slapreport = slapos.monitor:run_slapreport'
,
'slaprunner = slapos.runner:run'
,
'slaprunnertest = slapos.runner.runnertest:main'
,
...
...
slapos/systool.py
View file @
f25f6a02
import
argparse
import
sys
import
os
import
signal
def
killpidfromfile
():
"""deprecated: use below kill() instead"""
if
len
(
sys
.
argv
)
!=
3
:
raise
ValueError
(
'Invocation: %s <pidfile> <signal name>'
%
sys
.
argv
[
0
])
file
=
sys
.
argv
[
1
]
sig
=
getattr
(
signal
,
sys
.
argv
[
2
],
None
)
if
sig
is
None
:
raise
ValueError
(
'Unkn
wo
n signal name %s'
%
sys
.
argv
[
2
])
raise
ValueError
(
'Unkn
ow
n signal name %s'
%
sys
.
argv
[
2
])
pid
=
int
(
open
(
file
).
read
())
print
'Killing pid %s with signal %s'
%
(
pid
,
sys
.
argv
[
2
])
os
.
kill
(
pid
,
sig
)
def
sublist
(
a
,
b
):
try
:
i
=
a
.
index
(
b
[
0
])
except
IndexError
:
return
True
except
ValueError
:
return
False
return
a
[
i
:
i
+
len
(
b
)]
==
b
def
kill
():
parser
=
argparse
.
ArgumentParser
()
_
=
parser
.
add_argument
_
(
'--exe'
,
action
=
'append'
,
help
=
"match against executable path"
)
_
(
'-f'
,
'--full'
,
action
=
'store_true'
,
help
=
"match positional arguments against the full command line"
)
_
(
'-F'
,
'--pidfile'
,
action
=
'append'
,
help
=
"read PID's from file"
)
_
(
'-n'
,
'--name'
,
action
=
'append'
,
help
=
"match against process name"
)
_
(
'-s'
,
'--signal'
,
required
=
True
,
help
=
"signal to send to each matched process"
)
_
(
'arg'
,
nargs
=
'*'
,
help
=
"match against command line"
)
args
=
parser
.
parse_args
()
try
:
s
=
args
.
signal
.
split
(
'+'
,
1
)
s
=
getattr
(
signal
,
"SIG"
+
s
[
0
])
+
(
len
(
s
)
>
1
and
int
(
s
[
1
]))
except
(
AttributeError
,
ValueError
):
parser
.
error
(
'Unknown signal name %s'
%
args
.
signal
)
pid
=
args
.
pidfile
and
[
int
(
open
(
p
).
read
())
for
p
in
args
.
pidfile
]
exe
=
args
.
exe
and
map
(
os
.
path
.
realpath
,
args
.
exe
)
import
psutil
r
=
1
for
p
in
psutil
.
process_iter
():
try
:
if
(
pid
and
p
.
pid
not
in
pid
or
args
.
name
and
p
.
name
()
not
in
args
.
name
or
exe
and
p
.
exe
()
not
in
exe
):
continue
cmdline
=
p
.
cmdline
()
if
cmdline
==
args
.
arg
if
args
.
full
else
sublist
(
cmdline
,
args
.
arg
):
p
.
send_signal
(
s
)
print
'killed pid %s with signal %s'
%
(
p
.
pid
,
args
.
signal
)
r
=
0
except
psutil
.
Error
:
pass
return
r
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment