import requests
# Own modules
+from fb_tools.handler.lock import LockHandler
+
from . import __version__
from .base_app import BaseHookApp
self.r10k_bin = None
self.puppet_bin = None
+ self.locker = None
description = _("Receives push events as JSON-Data and deploys it with r10k.")
self.locale = 'de_DE.utf8'
self.search_r10k_bin()
self.check_cert_files()
+ self.locker = LockHandler(
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
+ simulate=self.simulate, sudo=False, quiet=self.quiet,
+ lockretry_delay_start=1, lockretry_delay_increase=1,
+ lockretry_max_delay=120, max_lockfile_age=1800, locking_use_pid=True,
+ lockdir='/tmp')
+ self.locker.initialized = True
+
self.initialized = True
# -------------------------------------------------------------------------
def run_hook(self):
"""Main routine."""
- if not self.exec_r10k():
- LOG.warn(_("Executing {!r} was not successful.").format(str(self.r10k_bin)))
- return
+ lockfile = 'r10k.' + self.ref + '.lock'
+ LOG.info(_("Trying to create lockfile {fn!r} in directory {d!r} ...").format(
+ fn=lockfile, d=str(self.locker.lockdir)))
- if not self.generate_puppet_types():
- what = '{c} generate types --environment {e}'.format(c=self.puppet_bin, e=self.ref)
- LOG.warn(_("{!r} was not successful.").format(what))
- return
+ lock = self.locker.create_lockfile(lockfile)
+
+ try:
+ lock.autoremove = True
+
+ if not self.exec_r10k():
+ LOG.warn(_("Executing {!r} was not successful.").format(str(self.r10k_bin)))
+ return
+
+ if not self.generate_puppet_types():
+ what = '{c} generate types --environment {e}'.format(c=self.puppet_bin, e=self.ref)
+ LOG.warn(_("{!r} was not successful.").format(what))
+ return
+
+ return self.del_env_cache()
- return self.del_env_cache()
+ finally:
+ lock = None
# -------------------------------------------------------------------------
def del_env_cache(self):