From d5f4e591f9cfedefdd4a71515b46c78e9a77e2ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 21 Apr 2018 01:09:28 +0200 Subject: [PATCH] Add redis to cryptoportfolio --- .gitmodules | 3 ++ .../files/redis/socket_shutdown_override.conf | 3 ++ modules/profile/manifests/redis.pp | 34 +++++++++++++++++++ modules/redis | 1 + modules/role/manifests/cryptoportfolio.pp | 4 +++ modules/role/manifests/cryptoportfolio/bot.pp | 31 +++++++++++++++++ .../cryptoportfolio/bot_config_hourly.ini.erb | 17 ++++++++++ 7 files changed, 93 insertions(+) create mode 100644 modules/profile/files/redis/socket_shutdown_override.conf create mode 100644 modules/profile/manifests/redis.pp create mode 160000 modules/redis create mode 100644 modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb diff --git a/.gitmodules b/.gitmodules index 6752dee..c75f803 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 index 0000000..8b73264 --- /dev/null +++ b/modules/profile/files/redis/socket_shutdown_override.conf @@ -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 index 0000000..79871b1 --- /dev/null +++ b/modules/profile/manifests/redis.pp @@ -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 index 0000000..bfcc212 --- /dev/null +++ b/modules/redis @@ -0,0 +1 @@ +Subproject commit bfcc2120f7b83342b03241d1429028a6defdd0da diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 6a659cc..53b7abd 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -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" } diff --git a/modules/role/manifests/cryptoportfolio/bot.pp b/modules/role/manifests/cryptoportfolio/bot.pp index 082e820..2f01c98 100644 --- a/modules/role/manifests/cryptoportfolio/bot.pp +++ b/modules/role/manifests/cryptoportfolio/bot.pp @@ -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 index 0000000..067f12a --- /dev/null +++ b/modules/role/templates/cryptoportfolio/bot_config_hourly.ini.erb @@ -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 -- 2.41.0