Commit dd2b8835 authored by Christian Juerges's avatar Christian Juerges
Browse files

first commit

parents
.idea
__pycache__
*.pyc
/*.egg-info
*.log
*.conf
*.list
[occron]
basedir=/home/chris/
php=/usr/bin/php
cron.php=cron.php
[redis]
server=192.168.166.41
port=6379
db=0
my
carpathia
eqipe
\ No newline at end of file
#!/usr/bin/python
__author__ = 'chris'
import sys, redis, redis_lock, ConfigParser, subprocess, os, time
import logging
mypath = os.path.dirname(sys.argv[0])
def main():
config = ConfigParser.SafeConfigParser(
{'port': '6379',
'db': 1})
config.read(mypath + '/occron.conf')
php = config.get('occron', 'php')
basepath = config.get('occron', 'basedir')
cron_php = config.get('occron', 'cron.php')
redis_db = int(config.get('redis', 'db'))
redis_port = int(config.get('redis', 'port'))
redis_server = config.get('redis', 'server')
if not redis_server:
print 'missing redis server ip address or fqdn!'
exit(-1)
r = redis.StrictRedis(host=redis_server, port=redis_port, db=redis_db, socket_timeout=15)
not_connected = True
while not_connected:
try:
response = r.client_list()
if response:
not_connected = False
except redis.ConnectionError:
continue
print('Error connecting to redis server! Trying to connect in 30 seconds...')
time.sleep(30)
except redis.RedisError:
print "Redis Error!"
print "Goodbye."
exit(-1)
# try to acquire lock to redis
# redislock = r.lock('occron.lock',120, auto_renewal=True)
redislock = redis_lock.Lock(r, mypath + '/occron.lock', expire=10, auto_renewal=True)
if redislock.acquire(blocking=False):
# read list of oc instances...
try:
with open(mypath + '/occron.list', 'r') as f:
for line in f:
# time.sleep(10)
line = line.strip()
# print(line)
occ_path = os.path.dirname(basepath) + '/' + line + '/' + cron_php
if os.path.exists(occ_path):
cmd = [php, occ_path]
return_code = subprocess.call(cmd)
logging.info('occ cron call [%s %s] returned %d' % (php, occ_path, return_code))
# logging.info('occ cron call [%s] returned %d' %(cmd, return_code))
else:
logging.info('OC Instance occ cli %s doest not exist!' % (occ_path))
except IOError as e:
print("Missing occron.list")
redislock.release()
else:
logging.info('occron is locked from another instance. Doing nothing.')
logging.info('Done')
if __name__ == '__main__':
logging.basicConfig(filename=mypath + '/occron.log', level=logging.INFO, format='%(asctime)s %(message)s')
logging.info('Start')
sys.exit(main())
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