1313from mineos import mc
1414
1515class cron (cherrypy .process .plugins .SimplePlugin ):
16- def __init__ (self , base_directory , commit_delay = 10 ):
16+ def __init__ (self , base_directory , commit_delay ):
1717 self .base_directory = base_directory
18- self .commit_delay = commit_delay
18+ try :
19+ self .commit_delay = int (commit_delay )
20+ except (ValueError , TypeError ):
21+ self .commit_delay = 10
1922
2023 def check_interval (self ):
2124 from procfs_reader import path_owner
2225 from time import sleep
26+ from subprocess import CalledProcessError
2327
2428 crons = []
2529
@@ -30,8 +34,10 @@ def check_interval(self):
3034 for server in set (s for a ,s in crons ):
3135 path_ = os .path .join (self .base_directory , mc .DEFAULT_PATHS ['servers' ], server )
3236 instance = mc (server , path_owner (path_ ), self .base_directory )
33-
37+
38+ cherrypy .log ('[%s] commit' % server )
3439 try :
40+ instance ._command_stuff ('save-off' )
3541 instance .commit ()
3642 except RuntimeError :
3743 pass
@@ -43,24 +49,33 @@ def check_interval(self):
4349 instance = mc (server , path_owner (path_ ), self .base_directory )
4450
4551 if action == 'restart' :
52+ cherrypy .log ('[%s] stop' % server )
4653 try :
4754 instance ._command_stuff ('stop' )
4855 except RuntimeError :
4956 pass
5057 else :
5158 sleep (self .commit_delay )
5259 elif action in ('backup' , 'archive' ):
53- getattr (instance , action )()
54- sleep (self .commit_delay )
60+ cherrypy .log ('[%s] %s' % (server , action ))
61+ try :
62+ getattr (instance , action )()
63+ except CalledProcessError as e :
64+ cherrypy .log ('[%s] %s exception: returncode %s' % (server , action , e .returncode ))
65+ cherrypy .log (e .output )
66+ else :
67+ sleep (self .commit_delay )
5568
5669 for action , server in crons :
5770 path_ = os .path .join (self .base_directory , mc .DEFAULT_PATHS ['servers' ], server )
5871 instance = mc (server , path_owner (path_ ), self .base_directory )
5972
6073 if action == 'restart' :
6174 if instance .up :
75+ cherrypy .log ('[%s] extra delay' % server )
6276 sleep (self .commit_delay )
63-
77+
78+ cherrypy .log ('[%s] start' % server )
6479 try :
6580 instance .start ()
6681 except RuntimeError :
@@ -224,15 +239,14 @@ def tally():
224239 }
225240
226241 try :
227- commit_delay = int (cherrypy .config ['server.commit_delay' ])
228- except (ValueError , KeyError ):
229- commit_delay = 10
230-
231- cron_instance = cron (base_dir , commit_delay )
232- minute_crontab = cherrypy .process .plugins .Monitor (cherrypy .engine ,
233- cron_instance .check_interval ,
234- 60 )
235- minute_crontab .subscribe ()
242+ cron_instance = cron (base_dir , cherrypy .config ['server.commit_delay' ])
243+ except KeyError :
244+ cron_instance = cron (base_dir , 10 )
245+ finally :
246+ minute_crontab = cherrypy .process .plugins .Monitor (cherrypy .engine ,
247+ cron_instance .check_interval ,
248+ 60 )
249+ minute_crontab .subscribe ()
236250
237251 import mounts , auth
238252
0 commit comments