From 2859008efe8f0a75344c7ba1c9c6e4d589f92da3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 26 Mar 2018 00:41:55 +0200 Subject: [PATCH] Use external module for cronjobs --- .gitmodules | 3 ++ .../base_installation/manifests/cleanup.pp | 20 +++++++ modules/base_installation/manifests/cronie.pp | 54 +++++++++++-------- modules/base_installation/manifests/init.pp | 1 + modules/cron | 1 + modules/role/manifests/backup.pp | 2 +- modules/role/manifests/cryptoportfolio/bot.pp | 40 +++++++------- 7 files changed, 76 insertions(+), 45 deletions(-) create mode 100644 modules/base_installation/manifests/cleanup.pp create mode 160000 modules/cron diff --git a/.gitmodules b/.gitmodules index 7a56af5..6752dee 100644 --- a/.gitmodules +++ b/.gitmodules @@ -55,3 +55,6 @@ [submodule "modules/ssl"] path = modules/ssl url = git://git.immae.eu/github/fnerdwq/puppet-ssl +[submodule "modules/cron"] + path = modules/cron + url = git://git.immae.eu/github/voxpupuli/puppet-cron diff --git a/modules/base_installation/manifests/cleanup.pp b/modules/base_installation/manifests/cleanup.pp new file mode 100644 index 0000000..96aaa6b --- /dev/null +++ b/modules/base_installation/manifests/cleanup.pp @@ -0,0 +1,20 @@ +class base_installation::cleanup inherits base_installation { + # This class contains temporary classes used to cleanup old stuff + # after refactoring + + cron { "puppet-pull-apply": + ensure => absent; + "puppet-apply": + ensure => absent; + "puppet-apply-reboot": + ensure => absent; + "pacman_keys": + ensure => absent; + "backup": + ensure => absent; + "py-cryptoportfolio-before": + ensure => absent; + "py-cryptoportfolio-after": + ensure => absent; + } +} diff --git a/modules/base_installation/manifests/cronie.pp b/modules/base_installation/manifests/cronie.pp index 2235470..3558d9f 100644 --- a/modules/base_installation/manifests/cronie.pp +++ b/modules/base_installation/manifests/cronie.pp @@ -10,31 +10,39 @@ class base_installation::cronie inherits base_installation { owner => root, group => root, } - cron { 'puppet-pull-apply': - ensure => present, - command => "cd $base_installation::puppet_code_path ; /usr/bin/git pull", - user => root, - minute => '*/30', - require => File['post-hook'], + cron::job { 'puppet-pull-apply': + ensure => present, + command => "cd $base_installation::puppet_code_path ; /usr/bin/git pull", + user => root, + minute => '15,45', + require => File['post-hook'], + description => "Pull git and apply puppet changes", } - cron { 'puppet-apply': - ensure => present, - command => "cd $base_installation::puppet_code_path ; /usr/local/sbin/puppet_apply $base_installation::puppet_code_path/manifests/site.pp", - user => root, - minute => '*/20' + cron::job::multiple { 'puppet-apply': + ensure => present, + jobs => [ + { + command => "cd $base_installation::puppet_code_path ; /usr/local/sbin/puppet_apply $base_installation::puppet_code_path/manifests/site.pp", + user => root, + minute => '*/20', + description => "Re-apply puppet changes regularly", + }, + { + command => "cd $base_installation::puppet_code_path ; /usr/local/sbin/puppet_apply $base_installation::puppet_code_path/manifests/site.pp", + user => root, + special => "reboot", + description => "Re-apply puppet changes at reboot", + } + ] } - cron { 'puppet-apply-reboot': - ensure => present, - command => "cd $base_installation::puppet_code_path ; /usr/local/sbin/puppet_apply $base_installation::puppet_code_path/manifests/site.pp", - user => root, - special => "reboot" - } - cron { 'pacman_keys': - ensure => present, - command => "pacman-key --populate archlinux", - user => root, - minute => "0", - hour => "1", + + cron::daily { 'pacman_keys': + ensure => present, + command => "pacman-key --populate archlinux", + user => root, + minute => "0", + hour => "1", + description => "Populate pacman keys", } } } diff --git a/modules/base_installation/manifests/init.pp b/modules/base_installation/manifests/init.pp index 998f8ff..d8abcaf 100644 --- a/modules/base_installation/manifests/init.pp +++ b/modules/base_installation/manifests/init.pp @@ -30,4 +30,5 @@ class base_installation ( contain ::base_installation::users contain ::base_installation::package_managers contain ::base_installation::puppet + contain ::base_installation::cleanup } diff --git a/modules/cron b/modules/cron new file mode 160000 index 0000000..d90d9be --- /dev/null +++ b/modules/cron @@ -0,0 +1 @@ +Subproject commit d90d9be088ad5008018ada87c30ceb314a46ed77 diff --git a/modules/role/manifests/backup.pp b/modules/role/manifests/backup.pp index 7a0c275..510a8ef 100644 --- a/modules/role/manifests/backup.pp +++ b/modules/role/manifests/backup.pp @@ -41,7 +41,7 @@ class role::backup ( mode => "0755", } - cron { "backup": + cron::job { "backup": ensure => present, command => $backup_script, user => $user, diff --git a/modules/role/manifests/cryptoportfolio/bot.pp b/modules/role/manifests/cryptoportfolio/bot.pp index d8b377f..7b62ae0 100644 --- a/modules/role/manifests/cryptoportfolio/bot.pp +++ b/modules/role/manifests/cryptoportfolio/bot.pp @@ -37,8 +37,7 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio { refreshonly => true, before => [ File[$cf_bot_app_conf], - Cron["py-cryptoportfolio-before"], - Cron["py-cryptoportfolio-after"], + Cron::Job::Multiple["py-cryptoportfolio"], ] } @@ -54,31 +53,30 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio { ], } - cron { "py-cryptoportfolio-before": + cron::job::multiple { "py-cryptoportfolio": ensure => present, - command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --before", - user => $user, - weekday => 7, # Sunday - hour => 22, - minute => 30, environment => ["HOME=${home}","PATH=/usr/bin/","CRON_TZ=UTC"], require => [ File[$cf_bot_app_conf], Archive["${home}/trader_${bot_version}.tar.gz"] ], - } - - cron { "py-cryptoportfolio-after": - ensure => present, - command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --after", - user => $user, - weekday => 1, # Monday - hour => 0, - minute => 0, - environment => ["HOME=${home}","PATH=/usr/bin/","CRON_TZ=UTC"], - require => [ - File[$cf_bot_app_conf], - Archive["${home}/trader_${bot_version}.tar.gz"] + jobs => [ + { + command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --before", + user => $user, + weekday => 7, # Sunday + hour => 22, + minute => 30, + description => "Run before the cryptoportfolio update", + }, + { + command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --after", + user => $user, + weekday => 1, # Monday + hour => 0, + minute => 0, + description => "Run after the cryptoportfolio update", + } ], } -- 2.41.0