~vila/uci-engine/rtfd

« back to all changes in this revision

Viewing changes to charms/precise/rabbitmq-worker/hooks/hooks.py

  • Committer: Ubuntu CI Bot
  • Author(s): Andy Doan
  • Date: 2014-07-16 15:08:10 UTC
  • mfrom: (674.2.2 rabbit-cron)
  • Revision ID: ubuntu_ci_bot-20140716150810-m8nzxh7zh3nliik8
[r=PS Jenkins bot, Francis Ginther] rabbit charm: add ability to support cron commands

Copying from the wsgi-app charm and including a small fix I found
with regards to buggy logic in removing an old symlink

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
        subprocess.check_call(['/sbin/start', _service_name()])
166
166
 
167
167
 
 
168
def _update_cron_config():
 
169
    periods = ('hourly', 'daily', 'weekly')
 
170
    service = charmhelpers.core.hookenv.service_name()
 
171
    config = charmhelpers.core.hookenv.config()
 
172
 
 
173
    if config['cron_period'] not in periods:
 
174
        raise ValueError('Invalid cron_peroid: %s' % config['cron_period'])
 
175
 
 
176
    for period in periods:
 
177
        p = '/etc/cron.%s/%s' % (period, service)
 
178
        if os.path.exists(p) or os.path.lexists(p):
 
179
            juju_info('removing old cron config: %s' % p)
 
180
            os.unlink(p)
 
181
 
 
182
    cmd = config['cron_cmd']
 
183
    if cmd:
 
184
        cmd = os.path.abspath(os.path.join(_code_dir(), cmd))
 
185
        juju_info('installing cron job for: %s' % cmd)
 
186
        os.symlink(cmd, '/etc/cron.%s/%s' % (config['cron_period'], service))
 
187
 
 
188
 
168
189
@hooks.hook()
169
190
def config_changed():
170
191
    charmhelpers.core.host.mkdir(_code_dir(''))
172
193
    _create_unit_config()
173
194
    _create_upstart()
174
195
    todelete = handle_code()
 
196
    _update_cron_config()
175
197
 
176
198
    _restart_upstart()
177
199