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
Tristan Cavelier
slapos.toolbox
Commits
f239576c
Commit
f239576c
authored
Feb 23, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add is-process-older-than-dependency-set script
parent
46edd99b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
CHANGES.txt
CHANGES.txt
+7
-0
setup.py
setup.py
+1
-0
slapos/promise/is_process_older_than_dependency_set/__init__.py
.../promise/is_process_older_than_dependency_set/__init__.py
+51
-0
No files found.
CHANGES.txt
View file @
f239576c
0.54.dev0 (2016-02-23)
======================
* The egg provides `is-process-older-than-dependency-set` script to check if
process needs to be restarted because is runnnig on an old version of its
loaded module.
0.50 (2015-07-20)
0.50 (2015-07-20)
=================
=================
...
...
setup.py
View file @
f239576c
...
@@ -69,6 +69,7 @@ setup(name=name,
...
@@ -69,6 +69,7 @@ setup(name=name,
'equeue = slapos.equeue:main'
,
'equeue = slapos.equeue:main'
,
'htpasswd = slapos.htpasswd:main'
,
'htpasswd = slapos.htpasswd:main'
,
'is-local-tcp-port-opened = slapos.promise.is_local_tcp_port_opened:main'
,
'is-local-tcp-port-opened = slapos.promise.is_local_tcp_port_opened:main'
,
'is-process-older-than-dependency-set = slapos.promise.is_process_older_than_dependency_set:main'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
# BBB
'killpidfromfile = slapos.systool:killpidfromfile'
,
# BBB
'runResiliencyUnitTestTestNode = slapos.resiliencytest:runUnitTest'
,
'runResiliencyUnitTestTestNode = slapos.resiliencytest:runUnitTest'
,
'runResiliencyScalabilityTestNode = slapos.resiliencytest:runResiliencyTest'
,
'runResiliencyScalabilityTestNode = slapos.resiliencytest:runResiliencyTest'
,
...
...
slapos/promise/is_process_older_than_dependency_set/__init__.py
0 → 100755
View file @
f239576c
#!/usr/bin/env python
"""
Check if a process is running with an old version of the modules
found in the defined python paths.
It parses all folders containing an `__init__.py` file and checks if
a file modification date is greater than the start date of the
process.
"""
import
sys
import
os
import
errno
import
psutil
def
moduleIsModifiedSince
(
top
,
last_modified
,
followlinks
=
False
):
for
root
,
dir_list
,
file_list
in
os
.
walk
(
top
,
followlinks
=
followlinks
):
if
"__init__.py"
not
in
file_list
:
del
dir_list
[:]
continue
for
name
in
file_list
:
path
=
os
.
path
.
join
(
root
,
name
)
if
last_modified
>
os
.
stat
(
path
).
st_mtime
:
return
True
return
False
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
):
start_time
=
psutil
.
Process
(
pid
).
create_time
()
return
any
(
moduleIsModifiedSince
(
product_path
,
start_time
)
for
product_path
in
python_path_list
)
def
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
python_path_list
):
with
open
(
pid_file_path
,
"r"
)
as
f
:
pid
=
int
(
f
.
readline
())
return
isProcessOlderThanDependencySet
(
pid
,
python_path_list
)
def
main
():
pid_file_path
,
python_path_list
=
sys
.
argv
[
1
],
sys
.
argv
[
2
:]
try
:
if
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
python_path_list
):
return
1
return
0
except
(
OSError
,
IOError
)
as
err
:
if
err
.
errno
==
errno
.
ENOENT
:
return
0
raise
except
psutil
.
NoSuchProcess
:
return
0
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
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