Commit 13d31a4b authored by Łukasz Nowak's avatar Łukasz Nowak

Provide wrapper for daemons.

As zabbix agentd cannot run in foreground mode wrap it in simple foreground
application which sends singals whenever it is requested to be killed.
parent a857877c
...@@ -87,5 +87,25 @@ class Recipe(BaseSlapRecipe): ...@@ -87,5 +87,25 @@ class Recipe(BaseSlapRecipe):
self.logrotate_d, self.logrotate_backup = self.installLogrotate() self.logrotate_d, self.logrotate_backup = self.installLogrotate()
zabbix_log_file = os.path.join(self.log_directory, 'zabbix_agentd.log') zabbix_log_file = os.path.join(self.log_directory, 'zabbix_agentd.log')
self.registerLogRotation('zabbix_agentd', [zabbix_log_file]) self.registerLogRotation('zabbix_agentd', [zabbix_log_file])
raise NotImplementedError zabbix_agentd = dict(
pid_file=os.path.join(self.run_directory, "zabbix_agentd.pid"),
log_file=zabbix_log_file,
ip=self.getGlobalIPv6Address(),
server=self.parameter_dict['server'],
hostname=self.parameter_dict['hostname'],
port='4567'
)
zabbix_agentd_conf = self.createConfigurationFile("zabbix_agentd.conf",
pkg_resources.resource_string(__name__,
'template/zabbix_agentd.conf.in') % zabbix_agentd)
self.path_list.append(zabbix_agentd_conf)
wrapper = zc.buildout.easy_install.scripts([('zabbixagentd',
'slapos.recipe.librecipe.execute', 'execute')], self.ws, sys.executable,
self.bin_directory, arguments=[
self.options['zabbix_agentd_binary'].strip(), '-c',
zabbix_agentd_conf])[0]
self.path_list.extend(zc.buildout.easy_install.scripts([
('zabbixagentd', __name__ + '.svcdaemon', 'svcdaemon')],
self.ws, sys.executable, self.wrapper_directory, arguments=[dict(
real_binary=wrapper, pid_file=zabbix_agentd['pid_file'])]))
return self.path_list return self.path_list
import os
import subprocess
import time
import signal
import sys
pid_file = None
def sig_handler(s, frame):
print "Killing on signal %s:" % s,
global pid_file
if pid_file is not None:
if os.path.exists(pid_file):
pid = int(open(pid_file).read())
print 'pid %s with SIGTERM...' % pid,
os.kill(pid, signal.SIGTERM)
if os.kill(pid, 0):
time.sleep(5)
if os.kill(pid, 0):
print 'with SIGKILL...',
os.kill(pid, signal.SIGKILL)
else:
print 'no pid file %r, nothing to do...' % pid_file,
print 'done.'
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
def svcdaemon(args):
"""Utility script to run daemons in supervisord"""
real_binary = args[0]['real_binary']
global pid_file
pid_file = args[0]['pid_file']
subprocess.check_call(real_binary)
print 'Started %r' % real_binary
while True:
time.sleep(2)
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