2013-01-15 23:43:32 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
|
|
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
# obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2013-02-01 01:32:00 +04:00
|
|
|
import os
|
2013-01-16 00:33:02 +04:00
|
|
|
import sys
|
2013-01-15 23:43:32 +04:00
|
|
|
import time
|
|
|
|
|
|
|
|
import stoneridge
|
|
|
|
|
|
|
|
|
|
|
|
class StoneRidgeDeferrer(object):
|
2013-01-17 00:40:58 +04:00
|
|
|
def __init__(self, srid, nightly, ldap, sha, netconfigs, operating_systems,
|
2013-02-20 04:22:00 +04:00
|
|
|
attempt):
|
2013-01-17 00:40:58 +04:00
|
|
|
self.srid = srid
|
2013-01-15 23:43:32 +04:00
|
|
|
self.nightly = nightly
|
|
|
|
self.ldap = ldap
|
|
|
|
self.sha = sha
|
|
|
|
self.netconfigs = netconfigs
|
|
|
|
self.operating_systems = operating_systems
|
|
|
|
self.attempt = attempt
|
2013-01-16 00:33:02 +04:00
|
|
|
self.interval = stoneridge.get_config_int('cloner', 'interval')
|
2013-01-15 23:43:32 +04:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
start = int(time.time())
|
|
|
|
end = start + self.interval
|
|
|
|
now = start
|
|
|
|
|
|
|
|
while now < end:
|
|
|
|
# Sleep for short periods in an attempt to not get too skewed
|
|
|
|
time.sleep(30)
|
|
|
|
now = int(time.time())
|
|
|
|
|
2013-02-21 08:20:22 +04:00
|
|
|
stoneridge.enqueue(srid=self.srid, nightly=self.nightly,
|
|
|
|
ldap=self.ldap, sha=self.sha,
|
|
|
|
netconfigs=self.netconfigs,
|
2013-02-20 04:22:00 +04:00
|
|
|
operating_systems=self.operating_systems,
|
|
|
|
attempt=self.attempt)
|
2013-01-15 23:43:32 +04:00
|
|
|
|
|
|
|
|
2013-01-16 00:33:02 +04:00
|
|
|
def daemon(deferrer, args):
|
|
|
|
deferrer.run()
|
|
|
|
os.unlink(args.pidfile)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
2013-01-15 23:43:32 +04:00
|
|
|
@stoneridge.main
|
|
|
|
def main():
|
2013-01-16 00:33:02 +04:00
|
|
|
parser = stoneridge.DaemonArgumentParser()
|
2013-01-15 23:43:32 +04:00
|
|
|
|
2013-01-17 00:40:58 +04:00
|
|
|
parser.add_argument('--srid', dest='srid', required=True)
|
|
|
|
parser.add_argument('--attempt', dest='attempt', type=int, required=True)
|
2013-01-15 23:43:32 +04:00
|
|
|
parser.add_argument('--nightly', dest='nightly', action='store_true',
|
2013-02-20 04:22:00 +04:00
|
|
|
default=False)
|
2013-01-15 23:43:32 +04:00
|
|
|
parser.add_argument('--ldap', dest='ldap', default='')
|
|
|
|
parser.add_argument('--sha', dest='sha', default='')
|
|
|
|
for nc in stoneridge.NETCONFIGS:
|
|
|
|
parser.add_argument('--%s' % (nc,), dest='netconfigs',
|
2013-02-20 04:22:00 +04:00
|
|
|
action='append_const', const=nc, default=[])
|
2013-01-15 23:43:32 +04:00
|
|
|
for ops in stoneridge.OPERATING_SYSTEMS:
|
2013-02-01 01:13:54 +04:00
|
|
|
parser.add_argument('--%s' % (ops,), dest='operating_systems',
|
2013-02-20 04:22:00 +04:00
|
|
|
action='append_const', const=ops, default=[])
|
2013-01-15 23:43:32 +04:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2013-01-17 00:40:58 +04:00
|
|
|
deferrer = StoneRidgeDeferrer(args.srid, args.nightly, args.ldap, args.sha,
|
2013-02-20 04:22:00 +04:00
|
|
|
args.netconfigs, args.operating_systems,
|
|
|
|
args.attempt)
|
2013-01-16 00:33:02 +04:00
|
|
|
|
|
|
|
parser.start_daemon(daemon, deferrer=deferrer, args=args)
|