Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

"""Reactive charm hooks.""" 

from charmhelpers.core import hookenv 

 

from charms.reactive import set_flag, when, when_not 

 

from lib_cron import CronHelper 

 

from lib_logrotate import LogrotateHelper 

 

 

hooks = hookenv.Hooks() 

logrotate = LogrotateHelper() 

cron = CronHelper() 

 

 

@when_not('logrotate.installed') 

def install_logrotate(): 

"""Install the logrotate charm.""" 

dump_config_to_disk() 

logrotate.read_config() 

cron.read_config() 

logrotate.modify_configs() 

hookenv.status_set('active', 'Unit is ready.') 

set_flag('logrotate.installed') 

cron.install_cronjob() 

 

 

@when('config.changed') 

def config_changed(): 

"""Run when configuration changes.""" 

dump_config_to_disk() 

cron.read_config() 

logrotate.read_config() 

hookenv.status_set('maintenance', 'Modifying configs.') 

logrotate.modify_configs() 

hookenv.status_set('active', 'Unit is ready.') 

cron.install_cronjob() 

 

 

def dump_config_to_disk(): 

"""Dump configurations to disk.""" 

cronjob_enabled = hookenv.config('logrotate-cronjob') 

cronjob_frequency = hookenv.config('logrotate-cronjob-frequency') 

logrotate_retention = hookenv.config('logrotate-retention') 

with open('/etc/logrotate_cronjob_config', 'w+') as cronjob_config_file: 

cronjob_config_file.write(str(cronjob_enabled) + '\n') 

cronjob_config_file.write(str(cronjob_frequency) + '\n') 

cronjob_config_file.write(str(logrotate_retention) + '\n') 

 

 

@when('stop') 

def cleanup(): 

"""Run cleanup before descutction of charm.""" 

logrotate.cleanup_custom_config() 

cron.cleanup_cronjob(-1)