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
331216b6
Commit
331216b6
authored
Oct 09, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introducing a general killer removing pidfiles after killing everychild.
Slapgrid now use standard pidfile. StopProxy Kill it.
parent
c26eb8c3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
36 deletions
+42
-36
slapos/runner/utils.py
slapos/runner/utils.py
+42
-36
No files found.
slapos/runner/utils.py
View file @
331216b6
...
...
@@ -187,6 +187,39 @@ def writePid(file, pid):
"""Save process pid into a file `file`"""
open
(
file
,
'w'
).
write
(
str
(
pid
))
def
killRunningProcess
(
config
,
ptype
):
"""Kill process and all running children process and remove pidfile"""
process_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
ptype
)
pid
=
readPid
(
process_pid
)
if
pid
:
recursifKill
([
pid
])
os
.
remove
(
process_pid
)
else
:
return
False
def
recursifKill
(
pids
):
"""Try to kill a list of proccess by the given pid list"""
if
pids
==
[]:
return
else
:
for
pid
in
pids
:
ppids
=
pidppid
(
pid
)
try
:
os
.
kill
(
pid
,
signal
.
SIGKILL
)
#kill current process
except
Exception
:
pass
recursifKill
(
ppids
)
#kill all children of this process
def
pidppid
(
pid
):
"""get the list of the children pids of a process `pid`"""
proc
=
Popen
(
'ps -o pid,ppid ax | grep "%d"'
%
pid
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
ppid
=
[
x
.
split
()
for
x
in
proc
.
communicate
()[
0
].
split
(
"
\
n
"
)
if
x
]
return
list
(
int
(
p
)
for
p
,
pp
in
ppid
if
int
(
pp
)
==
pid
)
def
updateInstanceParameter
(
config
,
software_type
=
None
):
"""
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
...
...
@@ -220,6 +253,7 @@ def startProxy(config):
def
stopProxy
(
config
):
"""Stop Slapproxy server"""
killRunningProcess
(
config
,
'proxy.pid'
)
pass
...
...
@@ -266,9 +300,9 @@ def runSoftwareWithLock(config):
environment
=
os
.
environ
.
copy
()
environment
[
'MAKEFLAGS'
]
=
'-j%r'
%
multiprocessing
.
cpu_count
()
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
,
'--develop'
],
stdout
=
logfile
,
env
=
environment
)
writePid
(
slapgrid_pid
,
slapgrid
.
pid
)
slapgrid
.
wait
()
#Saves the current compile software for re-use
config_SR_folder
(
config
)
...
...
@@ -341,34 +375,6 @@ def isInstanceRunning(config):
running
=
False
return
running
def
killRunningSlapgrid
(
config
,
ptype
):
"""Kill slapgrid process and all running children process"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
ptype
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
recursifKill
([
pid
])
else
:
return
False
def
recursifKill
(
pids
):
"""Try to kill a list of proccess by the given pid list"""
if
pids
==
[]:
return
else
:
for
pid
in
pids
:
ppids
=
pidppid
(
pid
)
try
:
os
.
kill
(
pid
,
signal
.
SIGKILL
)
#kill current process
except
Exception
:
pass
recursifKill
(
ppids
)
#kill all children of this process
def
pidppid
(
pid
):
"""get the list of the children pids of a process `pid`"""
proc
=
Popen
(
'ps -o pid,ppid ax | grep "%d"'
%
pid
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
ppid
=
[
x
.
split
()
for
x
in
proc
.
communicate
()[
0
].
split
(
"
\
n
"
)
if
x
]
return
list
(
int
(
p
)
for
p
,
pp
in
ppid
if
int
(
pp
)
==
pid
)
def
runInstanceWithLock
(
config
):
"""
...
...
@@ -383,9 +389,9 @@ def runInstanceWithLock(config):
return
False
svcStopAll
(
config
)
#prevent lost control of process
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
],
stdout
=
logfile
)
writePid
(
slapgrid_pid
,
slapgrid
.
pid
)
slapgrid
.
wait
()
return
True
return
False
...
...
@@ -578,9 +584,9 @@ def configNewSR(config, projectpath):
folder = realpath(config, projectpath)
if folder:
if isInstanceRunning(config):
killRunning
Slapgrid
(config, "slapgrid-cp.pid")
killRunning
Process
(config, "slapgrid-cp.pid")
if isSoftwareRunning(config):
killRunning
Slapgrid
(config, "slapgrid-sr.pid")
killRunning
Process
(config, "slapgrid-sr.pid")
stopProxy(config)
removeProxyDb(config)
startProxy(config)
...
...
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