]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Use external module for cronjobs
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 25 Mar 2018 22:41:55 +0000 (00:41 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 25 Mar 2018 23:19:39 +0000 (01:19 +0200)
.gitmodules
modules/base_installation/manifests/cleanup.pp [new file with mode: 0644]
modules/base_installation/manifests/cronie.pp
modules/base_installation/manifests/init.pp
modules/cron [new submodule]
modules/role/manifests/backup.pp
modules/role/manifests/cryptoportfolio/bot.pp

index 7a56af5bc999824581677336c71db3c6bc49fee1..6752dee196bf235b60d6051d027bc339f81b4fdd 100644 (file)
@@ -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 (file)
index 0000000..96aaa6b
--- /dev/null
@@ -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;
+  }
+}
index 2235470b6a2c93d122822b824b5f6f5e3f991e5d..3558d9f06334e51bc5f235249c284199c45e7fae 100644 (file)
@@ -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",
     }
   }
 }
index 998f8ff137015a497828de28165a93d45ba2b285..d8abcaf5ac4e06794b579c4f36361a2083001086 100644 (file)
@@ -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 (submodule)
index 0000000..d90d9be
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit d90d9be088ad5008018ada87c30ceb314a46ed77
index 7a0c2759e0728cfa254afc2ab5ce03aaebce3e35..510a8ef65fd470f5cf032c342635c5cabc9196cc 100644 (file)
@@ -41,7 +41,7 @@ class role::backup (
     mode           => "0755",
   }
 
-  cron { "backup":
+  cron::job { "backup":
     ensure  => present,
     command => $backup_script,
     user    => $user,
index d8b377f255bb0885585090b418aface92f596f42..7b62ae0120f60acb6224f6a360fc70adfc539494 100644 (file)
@@ -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",
+      }
     ],
   }