Commit 3706f75b by John Jarvis

flock in repos-from-orgs to prevent multiple instances from running

parent 2336b8cf
......@@ -13,6 +13,16 @@ import logging
from os.path import dirname, abspath, join
from argparse import ArgumentParser
def check_running(run_type=''):
pid_file = '{}-{}.pid'.format(
os.path.basename(__file__),run_type)
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
# another instance is running
sys.exit(0)
def run_cmd(cmd):
logging.debug('running: {}\n'.format(cmd))
......@@ -74,15 +84,13 @@ def update_repos():
run_cmd('cd {} && git update-server-info'.format(repo_path))
if __name__ == '__main__':
logging.basicConfig(filename='/var/log/repos-from-orgs.log',
level=logging.DEBUG)
args = parse_args()
if args.refresh:
check_running('refresh')
refresh_cache()
else:
check_running()
if not args.datadir:
print "Please specificy a repository directory"
sys.exit(1)
if not os.path.exists('/var/tmp/repos.json'):
refresh_cache()
update_repos()
......@@ -30,11 +30,11 @@
- name: creating cron job to update repos
cron:
name: "update repos from github"
job: "/usr/bin/flock -n /tmp/update-repo.lock -c '/usr/bin/python {{ gh_mirror_app_dir }}/repos_from_orgs.py -d {{ gh_mirror_data_dir }}'"
job: "/usr/bin/python {{ gh_mirror_app_dir }}/repos_from_orgs.py -d {{ gh_mirror_data_dir }}"
- name: creating cron to update github repo list
cron:
name: "refresh repo list from github"
job: "/usr/bin/flock -n /tmp/update-github-repo.lock -c '/usr/bin/python {{ gh_mirror_app_dir}}/repos_from_orgs.py -r'"
job: "/usr/bin/python {{ gh_mirror_app_dir}}/repos_from_orgs.py -r"
minute: 0
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