Commit 286d8da6 authored by Nicolas Wavrant's avatar Nicolas Wavrant

slaprunner: listener added to supervisor. It writes the files used by /slapgridResult (*_info.json)

parent 1d3ee03a
......@@ -44,7 +44,7 @@ mode = 0644
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-runner.cfg
output = ${buildout:directory}/template-runner.cfg.in
md5sum = 0a74dc48fd5fae88b43be1e3ad844c9f
md5sum = d0ebedcb67681a4f192f62ea019150ea
mode = 0644
[template-runner-import-script]
......@@ -146,12 +146,21 @@ mode = 0644
[template-supervisord]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
md5sum = dbe7751c6276afd853de9239d3b509ba
md5sum = f1f08f789195dc62b66c45e130f4114d
location = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = supervisord.conf.in
download-only = true
mode = 0644
[template-listener-slapgrid]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
md5sum = d07b5a9c63dc21209692ee2966107a25
location = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = listener_slapgrid.py.in
download-only = true
mode = 0644
[eggs]
recipe = z3c.recipe.scripts
eggs =
......
......@@ -184,6 +184,8 @@ autorun = $${slap-parameter:autorun}
knowledge0_file = $${buildout:directory}/$${public:filename}
minishell_cwd_file = $${directory:etc}/.minishell-cwd
minishell_history_file = $${directory:etc}/.minishell_history
software_info_json = $${runnerdirectory:home}/software_info.json
instance_info_json = $${runnerdirectory:home}/instance_info.json
[test-runner]
<= slaprunner
......@@ -650,6 +652,17 @@ template = ${template-supervisord:location}/${template-supervisord:filename}
rendered = $${directory:etc}/supervisord.conf
context =
section supervisord supervisord
key listener_slapgrid listener-slapgrid-bin:rendered
[listener-slapgrid-bin]
recipe = slapos.recipe.template:jinja2
template = ${template-listener-slapgrid:location}/${template-listener-slapgrid:filename}
rendered = $${directory:bin}/listener_slapgrid.py
mode = 0744
context =
section supervisord supervisord
section slaprunner slaprunner
raw python_executable ${buildout:executable}
[supervisord-wrapper]
recipe = slapos.cookbook:wrapper
......
#!{{ python_executable }}
import datetime
import json
import sys
import xmlrpclib
from supervisor import childutils
def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def write_slapgrid_result():
server = xmlrpclib.Server("http://{{- supervisord['server'] -}}")
# Tuple of tuples containing 2 elements : process name and the path of its info file
watch_processes = (("slapgrid-sr", "{{- slaprunner['software_info_json'] -}}"),
("slapgrid-cp", "{{- slaprunner['instance_info_json'] -}}"))
for process, file in watch_processes:
info = server.supervisor.getProcessInfo(process)
result = dict()
result['last_build'] = datetime.datetime.fromtimestamp(info['stop']).strftime("%Y-%m-%d %H:%M:%S")
result['success'] = info['exitstatus']
open(file, 'w').write(json.dumps(result))
def main():
while 1:
headers, payload = writer.wait()
write_slapgrid_result()
writer.ok()
if __name__ == '__main__':
writer = childutils.EventListenerProtocol()
main()
......@@ -41,3 +41,7 @@ stdout_logfile = {{ supervisord['stdout_logfile'] }}
stderr_logfile = {{ supervisord['stdout_logfile'] }}
directory = {{ supervisord['directory'] }}
environment = PATH="{{- supervisord['path'] -}}"
[eventlistener:listener-slapgrid]
command = {{ listener_slapgrid }}
events = PROCESS_STATE_EXITED
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment