]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add redis to cryptoportfolio
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 20 Apr 2018 23:09:28 +0000 (01:09 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 21 Apr 2018 08:21:23 +0000 (10:21 +0200)
.gitmodules
modules/profile/files/redis/socket_shutdown_override.conf [new file with mode: 0644]
modules/profile/manifests/redis.pp [new file with mode: 0644]
modules/redis [new submodule]
modules/role/manifests/cryptoportfolio.pp
modules/role/manifests/cryptoportfolio/bot.pp
modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb [new file with mode: 0644]

index 6752dee196bf235b60d6051d027bc339f81b4fdd..c75f8038fa9525a599ed5abc182b373d47e7c7ab 100644 (file)
@@ -58,3 +58,6 @@
 [submodule "modules/cron"]
        path = modules/cron
        url = git://git.immae.eu/github/voxpupuli/puppet-cron
+[submodule "modules/redis"]
+       path = modules/redis
+       url = git://git.immae.eu/github/arioch/puppet-redis
diff --git a/modules/profile/files/redis/socket_shutdown_override.conf b/modules/profile/files/redis/socket_shutdown_override.conf
new file mode 100644 (file)
index 0000000..8b73264
--- /dev/null
@@ -0,0 +1,3 @@
+[Service]
+ExecStop=
+ExecStop=/usr/bin/redis-cli -s /run/redis/redis.sock shutdown
diff --git a/modules/profile/manifests/redis.pp b/modules/profile/manifests/redis.pp
new file mode 100644 (file)
index 0000000..79871b1
--- /dev/null
@@ -0,0 +1,34 @@
+class profile::redis {
+  file { '/etc/systemd/system/redis.service.d/':
+    ensure => "directory",
+    path   => "/etc/systemd/system/redis.service.d/",
+    mode   => "0755",
+    owner  => "root",
+    group  => "root"
+  } ->
+  file { '/etc/systemd/system/redis.service.d/socket_shutdown.conf':
+    ensure  => "present",
+    path    => "/etc/systemd/system/redis.service.d/noclear.conf",
+    source  => 'puppet:///modules/profile/redis/socket_shutdown_override.conf',
+    recurse => true,
+    mode    => "0644",
+    owner   => "root",
+    group   => "root",
+    notify  => Service["redis"],
+  }
+
+  package { "ruby-augeas":
+    ensure => installed,
+  } ->
+  class { '::redis':
+    unixsocket       => "/run/redis/redis.sock",
+    unixsocketperm   => "777",
+    ulimit           => false,
+    daemonize        => false,
+    config_file      => "/etc/redis.conf",
+    config_file_orig => "/etc/redis.conf.puppet",
+    port             => 0,
+    require          => File["/etc/systemd/system/redis.service.d/socket_shutdown.conf"],
+  }
+
+}
diff --git a/modules/redis b/modules/redis
new file mode 160000 (submodule)
index 0000000..bfcc212
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit bfcc2120f7b83342b03241d1429028a6defdd0da
index 6a659cc8b30e53ff8b30fd6578c309fdf1194499..53b7abd6fdd7fffe37f20a9299887f70a915ffe5 100644 (file)
@@ -9,6 +9,7 @@ class role::cryptoportfolio (
   String            $pg_db,
   Optional[String]  $pg_hostname          = "localhost",
   Optional[String]  $pg_port              = "5432",
+  Optional[String]  $redis_host           = "/run/redis/redis.sock",
   Optional[String]  $web_host             = undef,
   Optional[String]  $web_port             = "",
   Optional[Boolean] $web_ssl              = true,
@@ -30,6 +31,9 @@ class role::cryptoportfolio (
   contain "role::cryptoportfolio::notify"
 
   unless empty($trader_version) {
+    if versioncmp($trader_version, "v1.3") >= 0 {
+      include "profile::redis"
+    }
     contain "role::cryptoportfolio::bot"
   }
 
index 082e82059ae43b9222759bce9a0d4c6bd9e209f0..2f01c98ab6735b59bdaa0267cadf6781c017b747 100644 (file)
@@ -3,6 +3,7 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
 
   $cf_bot_app = "${home}/bot"
   $cf_bot_app_conf = "${home}/bot_config.ini"
+  $cf_bot_app_conf_hourly = "${home}/bot_config_hourly.ini"
   $cf_bot_app_reports = "${home}/bot_reports"
 
   ensure_packages(["python", "python-pip"])
@@ -80,6 +81,36 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
     ],
   }
 
+  if versioncmp($trader_version, "v1.3") >= 0 {
+    file { $cf_bot_app_conf_hourly:
+      owner   => $user,
+      group   => $group,
+      mode    => "0600",
+      content => template("role/cryptoportfolio/bot_config_hourly.ini.erb"),
+      require => [
+        User["$user:"],
+        Archive["${home}/trader_${trader_version}.tar.gz"],
+      ],
+    }
+
+    cron::job::multiple { "py-cryptoportfolio-hourly":
+      ensure      => present,
+      environment => ["HOME=${home}","PATH=/usr/bin/"],
+      require     => [
+        File[$cf_bot_app_conf_hourly],
+        Archive["${home}/trader_${trader_version}.tar.gz"]
+      ],
+      jobs        => [
+        {
+          command     => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf_hourly",
+          user        => $user,
+          minute      => 30,
+          description => "Print the current state to redis",
+        },
+      ],
+    }
+  }
+
   unless empty($webhook_url) {
     exec { "bot-slack-notify":
       refreshonly => true,
diff --git a/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb b/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb
new file mode 100644 (file)
index 0000000..067f12a
--- /dev/null
@@ -0,0 +1,17 @@
+[postgresql]
+db-host = <%= @pg_hostname %>
+db-port = <%= @pg_port %>
+db-user = <%= @pg_user %>
+db-password = <%= @pg_password %>
+db-database = <%= @pg_db %>
+
+[redis]
+redis-host = <%= @redis_host %>
+
+[app]
+action = print_balances
+report-redis
+no-report-path
+no-report-db
+quiet
+debug