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
841517de
Commit
841517de
authored
Oct 21, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: allow to specify a second promise folder
parent
03dff33c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
slapos/monitor/monitor.py
slapos/monitor/monitor.py
+3
-0
slapos/monitor/runpromise.py
slapos/monitor/runpromise.py
+18
-7
No files found.
slapos/monitor/monitor.py
View file @
841517de
...
...
@@ -92,6 +92,8 @@ class Monitoring(object):
# Use this file to write knowledge0_cfg required by webrunner
self
.
parameter_cfg_file
=
config
.
get
(
"monitor"
,
"parameter-file-path"
).
strip
()
self
.
pid_file
=
config
.
get
(
"monitor"
,
"pid-file"
)
self
.
monitor_promise_folder
=
softConfigGet
(
config
,
"monitor"
,
"monitor-promise-folder"
)
self
.
config_folder
=
os
.
path
.
join
(
self
.
private_folder
,
'config'
)
self
.
report_folder
=
self
.
private_folder
...
...
@@ -409,6 +411,7 @@ class Monitoring(object):
"monitor-promises.pid"
),
'--output "%s"'
%
self
.
public_folder
,
'--promise_folder "%s"'
%
self
.
promise_folder
,
'--monitor_promise_folder "%s"'
%
self
.
monitor_promise_folder
,
'--monitor_url "%s/jio_private/"'
%
self
.
webdav_url
,
# XXX hardcoded,
'--history_folder "%s"'
%
self
.
public_folder
,
'--instance_name "%s"'
%
self
.
title
,
...
...
slapos/monitor/runpromise.py
View file @
841517de
...
...
@@ -28,6 +28,8 @@ def parseArguments():
help
=
'Promise script to execute.'
)
parser
.
add_argument
(
'--promise_folder'
,
help
=
'Folder where to find promises to execute. Hide --promise_script and --promise_name'
)
parser
.
add_argument
(
'--monitor_promise_folder'
,
help
=
'Folder where to find Custom monitor promises to execute.'
)
parser
.
add_argument
(
'--promise_name'
,
help
=
'Title to give to this promise.'
)
parser
.
add_argument
(
'--promise_type'
,
...
...
@@ -118,7 +120,10 @@ class RunPromise(object):
with
open
(
self
.
config
.
pid_path
,
'w'
)
as
fpid
:
fpid
.
write
(
str
(
os
.
getpid
()))
status_list
=
self
.
checkPromises
(
self
.
config
.
promise_folder
)
promise_folder_list
=
[
self
.
config
.
promise_folder
]
if
self
.
config
.
monitor_promise_folder
:
promise_folder_list
.
append
(
self
.
config
.
monitor_promise_folder
)
status_list
=
self
.
checkPromises
(
promise_folder_list
)
promises_status_file
=
os
.
path
.
join
(
self
.
config
.
output
,
'_promise_status'
)
previous_state_dict
=
{}
new_state_dict
=
{}
...
...
@@ -254,19 +259,22 @@ class RunPromise(object):
stderr
=
subprocess
.
PIPE
)
def
checkPromises
(
self
,
promise_dir
):
def
checkPromises
(
self
,
promise_dir
_list
):
"""
Run all promises found into specified folder
"""
if
not
os
.
path
.
exists
(
promise_dir
)
or
not
os
.
path
.
isdir
(
promise_dir
):
return
[]
promise_list
=
[]
for
promise_dir
in
promise_dir_list
:
if
not
os
.
path
.
exists
(
promise_dir
)
or
not
os
.
path
.
isdir
(
promise_dir
):
continue
promise_list
.
extend
([
os
.
path
.
join
(
promise_dir
,
promise
)
for
promise
in
os
.
listdir
(
promise_dir
)])
promise_result_list
=
[]
# Check whether every promise is kept
for
promise
in
os
.
listdir
(
promise_dir
)
:
for
promise
_script
in
promise_list
:
promise_script
=
os
.
path
.
join
(
promise_dir
,
promise
)
if
not
os
.
path
.
isfile
(
promise_script
)
or
not
os
.
access
(
promise_script
,
os
.
X_OK
):
# Not executable file
continue
...
...
@@ -300,7 +308,10 @@ class RunPromise(object):
result_dict
[
"message"
]
=
process_handler
.
communicate
()[
0
]
result_dict
[
"status"
]
=
"OK"
else
:
result_dict
[
"message"
]
=
process_handler
.
communicate
()[
1
]
stdout
,
stderr
=
process_handler
.
communicate
()
result_dict
[
"message"
]
=
stderr
if
not
stderr
:
result_dict
[
"message"
]
=
stdout
break
else
:
process_handler
.
terminate
()
...
...
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