Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Jürges
occron
Commits
dd2b8835
Commit
dd2b8835
authored
Oct 29, 2015
by
Christian Juerges
Browse files
first commit
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
dd2b8835
.idea
__pycache__
*.pyc
/*.egg-info
*.log
*.conf
*.list
occron.conf.example
0 → 100644
View file @
dd2b8835
[occron]
basedir=/home/chris/
php=/usr/bin/php
cron.php=cron.php
[redis]
server=192.168.166.41
port=6379
db=0
occron.list.example
0 → 100644
View file @
dd2b8835
my
carpathia
eqipe
\ No newline at end of file
occron.py
0 → 100644
View file @
dd2b8835
#!/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
())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment