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
Xiaowu Zhang
slapos.toolbox
Commits
bc882801
Commit
bc882801
authored
May 29, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apache-mpm_watchdog: Initial commit
parent
d1ed4bf0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
slapos/promise/apache_mpm_watchdog/__init__.py
slapos/promise/apache_mpm_watchdog/__init__.py
+43
-0
No files found.
slapos/promise/apache_mpm_watchdog/__init__.py
0 → 100644
View file @
bc882801
import
requests
import
re
import
signal
import
os
import
psutil
import
json
import
time
search_pid_regex
=
r"</td><td.*?>(.+?)</td><td>yes \
(old ge
n\
)</
td>"
def
main
(
url
,
user
,
password
,
db_path
,
timeout
=
600
):
if
os
.
path
.
exists
(
db_path
):
with
open
(
db_path
)
as
json_file
:
try
:
pid_dict
=
json
.
load
(
json_file
)
except
ValueError
:
pid_dict
=
{}
else
:
pid_dict
=
{}
r
=
requests
.
get
(
url
,
auth
=
(
user
,
password
))
for
i
in
re
.
findall
(
search_pid_regex
,
r
.
text
):
try
:
process
=
psutil
.
Process
(
int
(
i
))
except
psutil
.
NoSuchProcess
:
continue
# Ensure the process is actually an apache
if
process
.
cmdline
()[
0
].
endswith
(
"/httpd"
):
pid_dict
.
setdefault
(
i
,
time
.
time
()
+
timeout
)
if
pid_dict
[
i
]
<
time
.
time
():
print
"Sending signal -%s to %s"
%
(
signal
.
SIGKILL
,
i
)
os
.
kill
(
int
(
i
),
signal
.
SIGKILL
)
for
i
in
pid_dict
.
copy
():
try
:
process
=
psutil
.
Process
(
int
(
i
))
except
psutil
.
NoSuchProcess
:
del
pid_dict
[
i
]
with
open
(
db_path
,
"w"
)
as
f
:
f
.
write
(
json
.
dumps
(
pid_dict
))
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