diff --git a/data/common/common.yaml b/data/common/common.yaml --- a/data/common/common.yaml +++ b/data/common/common.yaml @@ -2524,6 +2524,8 @@ - swh.loader.mercurial.tasks.LoadMercurial - swh.loader.mercurial.tasks.LoadArchiveMercurial +swh::deploy::worker::opam::root_directory: /tmp/opam/ + swh::deploy::worker::loader_opam::config_file: "%{hiera('swh::conf_directory')}/loader_opam.yml" swh::deploy::worker::loader_opam::concurrency: 1 swh::deploy::worker::loader_opam::private_tmp: true diff --git a/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp b/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp --- a/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp +++ b/site-modules/profile/manifests/swh/deploy/worker/loader_opam.pp @@ -17,4 +17,34 @@ Package[$packages], ], } + + $opam_root = lookup('swh::deploy::worker::opam::root_directory') + file {$opam_root: + ensure => 'directory', + owner => $user, + group => $group, + recurse => true, + mode => '0644', + } + + # Template uses variables + # - $user + # - $group + # - $opam_root + # - $opam_manage_shared_state + $opam_manage_shared_state = "opam-manage-shared-state" + $opam_manage_shared_state_unit_template = "profile/swh/deploy/loader_opam/${opam_manage_shared_state}.service.erb" + $opam_manage_shared_state_timer_name = "${opam_manage_shared_state}.timer" + $opam_manage_shared_state_timer_template = "profile/swh/deploy/loader_opam/${opam_manage_shared_state_timer_name}.erb" + + ::systemd::timer { $opam_manage_shared_state_timer_name: + timer_content => template($opam_manage_shared_state_timer_template), + service_content => template($opam_manage_shared_state_unit_template), + enable => true, + require => [ + Package[$packages], + File[$opam_root], + ], + } + } diff --git a/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb new file mode 100644 --- /dev/null +++ b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.service.erb @@ -0,0 +1,17 @@ +# Opam manage shared state unit file +# Managed by puppet class profile::swh::deploy::worker::loader_opam +# Changes will be overwritten + +[Unit] +Description=Software Heritage Manage OPAM shared state +Requires=network.target +After=network.target + +[Service] +User=<%= @user %> +Group=<%= @group %> +Type=simple +ExecStart=/usr/bin/opam init --reinit --bare --no-setup --root <%= @opam_root %> opam https://opam.ocaml.org + +[Install] +WantedBy=multi-user.target diff --git a/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb new file mode 100644 --- /dev/null +++ b/site-modules/profile/templates/swh/deploy/loader_opam/opam-manage-shared-state.timer.erb @@ -0,0 +1,11 @@ +[Install] +WantedBy=timers.target + +[Timer] +OnCalendar=daily +AccuracySec=4h +Persistent=true +Unit=<%= @$opam_manage_shared_state %>.service + +[Unit] +Description=Recurring webapp update savecodenow statuses