diff --git a/site-modules/profile/manifests/hedgedoc.pp b/site-modules/profile/manifests/hedgedoc.pp index b34bf803..be74f216 100644 --- a/site-modules/profile/manifests/hedgedoc.pp +++ b/site-modules/profile/manifests/hedgedoc.pp @@ -1,129 +1,128 @@ # deploy a hedgedoc instance class profile::hedgedoc { include profile::hedgedoc::apt_config include profile::hedgedoc::user $user = $::profile::hedgedoc::user::user $group = $::profile::hedgedoc::user::group - # ---- configuration - $base_url = lookup('swh::deploy::hedgedoc::base_url') + # ---- install + $version = lookup('hedgedoc::release::version') + $archive_url = "https://github.com/hedgedoc/hedgedoc/releases/download/${version}/hedgedoc-${version}.tar.gz" + $archive_digest = lookup('hedgedoc::release::digest') + $archive_digest_type = lookup('hedgedoc::release::digest_type') + + $install_basepath = "/opt/hedgedoc" + $install_dir = "${install_basepath}/${version}" + $install_flag = "${install_dir}/setup_done" + + $archive_path = "${install_basepath}/${version}.tar.gz" + + $current_symlink = "${install_basepath}/current" + + $service_name = "hedgedoc" + $unit_name = "${service_name}.service" + + file { [$install_basepath, $install_dir]: + ensure => 'directory', + owner => $user, + group => $group, + mode => '0644', + } + + archive { 'hedgedoc': + path => $archive_path, + extract => true, + extract_command => 'tar xzf %s --strip-components=1 --no-same-owner --no-same-permissions', + source => $archive_url, + extract_path => $install_dir, + checksum => $archive_digest, + checksum_type => $archive_digest_type, + creates => "${install_dir}/bin/setup", + cleanup => true, + user => $user, + group => $group, + require => File[$install_dir], + notify => Exec['hedgedoc-setup'], + } + # ---- configuration $db_host = lookup('hedgedoc::db::host') $db_name = lookup('hedgedoc::db::database') $db_user = lookup('hedgedoc::db::username') $db_password = lookup('swh::deploy::hedgedoc::db::password') $db_port = lookup('swh::postgresql::port') $db_url = "postgres://${db_user}:${db_password}@${db_host}:${db_port}/${db_name}" + $sequelizerc_path = "${install_dir}/.sequelizerc" + + file {$sequelizerc_path: + ensure => present, + owner => $user, + group => $group, + mode => '0644', + content => template("profile/hedgedoc/sequelizerc.erb"), + notify => Service[$service_name], + } + + $base_url = lookup('swh::deploy::hedgedoc::base_url') + + $runtime_environment = lookup('hedgedoc::runtime_environment') + $log_level = lookup('hedgedoc::log_level') + $session_secret = lookup('hedgedoc::session_secret') $allow_anonymous = lookup('hedgedoc::allow_anonymous') $allow_anonymous_edits = lookup('hedgedoc::allow_anonymous_edits') $allow_email = lookup('hedgedoc::allow_email') $allow_email_register = lookup('hedgedoc::allow_email_register') $enable_keycloak = lookup('hedgedoc::enable_keycloak', Boolean, 'first', false) $keycloak_domain = lookup('hedgedoc::keycloak::domain') $keycloak_realm = lookup('hedgedoc::keycloak::realm') $keycloak_client_id = lookup('hedgedoc::keycloak::client::id') $keycloak_client_secret = lookup('hedgedoc::keycloak::client::secret') - $runtime_environment = lookup('hedgedoc::runtime_environment') - $log_level = lookup('hedgedoc::log_level') - - # ---- install - $version = lookup('hedgedoc::release::version') - $archive_url = "https://github.com/hedgedoc/hedgedoc/releases/download/${version}/hedgedoc-${version}.tar.gz" - $archive_digest = lookup('hedgedoc::release::digest') - $archive_digest_type = lookup('hedgedoc::release::digest_type') - $archive_path = "/tmp/hedgedoc-${version}.tar.gz" - $root_install_path = "/opt" - $install_path = "${root_install_path}/hedgedoc" - $upgrade_flag_path = "${install_path}/hedgedoc-${version}-upgrade" - - $sequelizerc_path = "${install_path}/.sequelizerc" - $config_json_path = "${install_path}/config.json" - - $service_name = "hedgedoc" - $unit_name = "${service_name}.service" - - file { $install_path: - ensure => 'directory', - owner => $user, - group => $group, - mode => '0644', - require => [User[$user], Group[$group]], - } + $config_json_path = "${install_dir}/config.json" - archive { 'hedgedoc': - path => $archive_path, - extract => true, - source => $archive_url, - extract_path => $root_install_path, - creates => $install_path, - checksum => $archive_digest, - checksum_type => $archive_digest_type, - cleanup => true, - user => 'root', - group => 'root', - notify => File[$install_path], - } ~> - exec {'active-initialize': - command => "touch ${upgrade_flag_path}", - path => '/usr/bin', - refreshonly => true, - } ~> - exec {'hedgedoc-flag-upgrade': - command => "$install_path/bin/setup", - cwd => $install_path, - require => Postgresql::Server::Db[$db_name], - refreshonly => true, - } ~> file {$config_json_path: ensure => present, owner => $user, group => $group, # Contains credentials mode => '0600', content => template("profile/hedgedoc/config.json.erb"), - } ~> - file {$sequelizerc_path: - ensure => present, - owner => $user, - group => $group, - mode => '0644', - content => template("profile/hedgedoc/sequelizerc.erb"), - } ~> - exec {'yarn-build': - command => "yarn run build", - cwd => $install_path, - path => '/usr/bin', - onlyif => "test -f ${upgrade_flag_path}", - refreshonly => true, - } ~> - exec {'hegdedoc-flag-upgrade-done': - command => "rm ${upgrade_flag_path}", - cwd => $install_path, - path => '/usr/bin', - onlyif => "test -f ${upgrade_flag_path}", - refreshonly => true, + notify => Service[$service_name], + } + + exec {'hedgedoc-setup': + command => "${install_dir}/bin/setup && touch ${install_flag}", + cwd => $install_dir, + require => [ + Postgresql::Server::Db[$db_name], + File[$config_json_path], + File[$sequelizerc_path], + ], + creates => $install_flag, + user => $user, + } + + -> file {$current_symlink: + ensure => 'link', + target => $install_dir, notify => Service[$service_name], } - systemd::unit_file {$unit_name: + -> systemd::unit_file {$unit_name: ensure => present, content => template('profile/hedgedoc/hedgedoc.service.erb'), } - service {$service_name: + -> service {$service_name: ensure => 'running', enable => true, require => [ - Systemd::Unit_file[$unit_name], Class['profile::hedgedoc::apt_config'], - Archive['hedgedoc'], ], } - } diff --git a/site-modules/profile/templates/hedgedoc/hedgedoc.service.erb b/site-modules/profile/templates/hedgedoc/hedgedoc.service.erb index 9db72b73..a9de1028 100644 --- a/site-modules/profile/templates/hedgedoc/hedgedoc.service.erb +++ b/site-modules/profile/templates/hedgedoc/hedgedoc.service.erb @@ -1,23 +1,23 @@ [Unit] Description=Hedgedoc Documentation=https://github.com/hedgedoc/hedgedoc After=network-online.target Wants=network-online.target [Service] Type=simple User=<%= @user %> Group=<%= @group %> Environment=CMD_ALLOW_ANONYMOUS=<%= @allow_anonymous %> Environment=CMD_ALLOW_ANONYMOUS_EDITS=<%= @allow_anonymous_edits %> Environment=NODE_ENV=<%= @runtime_environment %> -WorkingDirectory=<%= @install_path %> +WorkingDirectory=<%= @current_symlink %> ExecStart=/usr/bin/yarn start Restart=on-failure RestartSec=10 PrivateTmp=true [Install] WantedBy=multi-user.target