From a1ce98a14d7f2dee4898097f0efb28e62c366e10 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 14 Feb 2023 12:07:43 +0100 Subject: [PATCH] Makeswap script --- manifests/scriptreceiver.pp | 2 +- templates/scriptreceiver/makeswap.erb.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 templates/scriptreceiver/makeswap.erb.sh diff --git a/manifests/scriptreceiver.pp b/manifests/scriptreceiver.pp index d417440..a67d760 100644 --- a/manifests/scriptreceiver.pp +++ b/manifests/scriptreceiver.pp @@ -4,7 +4,7 @@ class sunetdrive::scriptreceiver() sunet::system_user {'script': username => 'script', group => 'script', managehome => true, shell => '/bin/bash' } # These tasks correspond to a ${task}.erb.sh template - $tasks = ['list_users', 'list_files_for_user', 'create_bucket', 'backup_db', 'purge_backups', 'maintenancemode', 'restart_sunet_service', 'start_sentinel', 'stop_sentinel'] + $tasks = ['list_users', 'list_files_for_user', 'create_bucket', 'backup_db', 'purge_backups', 'maintenancemode', 'restart_sunet_service', 'start_sentinel', 'stop_sentinel', 'makeswap'] $environment = sunetdrive::get_environment() $config = hiera_hash($environment) diff --git a/templates/scriptreceiver/makeswap.erb.sh b/templates/scriptreceiver/makeswap.erb.sh new file mode 100644 index 0000000..000d857 --- /dev/null +++ b/templates/scriptreceiver/makeswap.erb.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if ! [[ -f /swapfile ]]; then + gb=$(free --gibi| grep Mem: | awk '{print $2}') + fallocate -l "${gb}G" /swapfile + chmod 600 /swapfile + mkswap /swapfile + swapon /swapfile + if ! grep -E '^(#)?/swapfile' /etc/fstab; then + echo '/swapfile none swap sw 0 0' >> /etc/fstab + fi +fi