Less dangerous pruning script
This commit is contained in:
parent
f2f919a59c
commit
165415b725
|
@ -53,11 +53,22 @@ class sunetdrive::multinode (
|
||||||
group => 'root',
|
group => 'root',
|
||||||
}
|
}
|
||||||
file { '/usr/local/bin/upgrade23-25.sh':
|
file { '/usr/local/bin/upgrade23-25.sh':
|
||||||
|
ensure => absent,
|
||||||
|
}
|
||||||
|
file { '/usr/local/bin/get_paying_customers':
|
||||||
ensure => present,
|
ensure => present,
|
||||||
force => true,
|
force => true,
|
||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
content => template('sunetdrive/multinode/upgrade23-25.erb.sh'),
|
content => template('sunetdrive/multinode/get_paying_customers.erb.sh'),
|
||||||
|
mode => '0744',
|
||||||
|
}
|
||||||
|
file { '/usr/local/bin/get_non_paying_customers':
|
||||||
|
ensure => present,
|
||||||
|
force => true,
|
||||||
|
owner => 'root',
|
||||||
|
group => 'root',
|
||||||
|
content => template('sunetdrive/multinode/get_non_paying_customers.erb.sh'),
|
||||||
mode => '0744',
|
mode => '0744',
|
||||||
}
|
}
|
||||||
file { '/usr/local/bin/get_containers':
|
file { '/usr/local/bin/get_containers':
|
||||||
|
@ -68,6 +79,14 @@ class sunetdrive::multinode (
|
||||||
content => template('sunetdrive/multinode/get_containers'),
|
content => template('sunetdrive/multinode/get_containers'),
|
||||||
mode => '0744',
|
mode => '0744',
|
||||||
}
|
}
|
||||||
|
file { '/usr/local/bin/restart_and_prune':
|
||||||
|
ensure => present,
|
||||||
|
force => true,
|
||||||
|
owner => 'root',
|
||||||
|
group => 'root',
|
||||||
|
content => template('sunetdrive/multinode/restart_and_prune.erb.sh'),
|
||||||
|
mode => '0744',
|
||||||
|
}
|
||||||
file { '/usr/local/bin/add_admin_user':
|
file { '/usr/local/bin/add_admin_user':
|
||||||
ensure => present,
|
ensure => present,
|
||||||
force => true,
|
force => true,
|
||||||
|
@ -92,14 +111,21 @@ class sunetdrive::multinode (
|
||||||
content => template('sunetdrive/multinode/proxysql.cnf.erb'),
|
content => template('sunetdrive/multinode/proxysql.cnf.erb'),
|
||||||
mode => '0644',
|
mode => '0644',
|
||||||
}
|
}
|
||||||
if $environment == 'test' {
|
sunet::scriptherder::cronjob { 'prune_non_paying':
|
||||||
cron { 'multinode_prune':
|
cmd => '/usr/local/bin/restart_and_prune',
|
||||||
command => '/opt/nextcloud/prune.sh',
|
day => '1-6'
|
||||||
require => File['/opt/nextcloud/prune.sh'],
|
hour => '2',
|
||||||
user => 'root',
|
minute => '45',
|
||||||
minute => '25',
|
ok_criteria => ['exit_status=0','max_age=3d'],
|
||||||
hour => '4',
|
warn_criteria => ['exit_status=1','max_age=5d'],
|
||||||
}
|
}
|
||||||
|
sunet::scriptherder::cronjob { 'prune_all_paying':
|
||||||
|
cmd => '/usr/local/bin/restart_and_prune include_paying',
|
||||||
|
day => '0'
|
||||||
|
hour => '2',
|
||||||
|
minute => '45',
|
||||||
|
ok_criteria => ['exit_status=0','max_age=7d'],
|
||||||
|
warn_criteria => ['exit_status=1','max_age=9d'],
|
||||||
}
|
}
|
||||||
file { '/opt/nextcloud/apache.php.ini':
|
file { '/opt/nextcloud/apache.php.ini':
|
||||||
ensure => file,
|
ensure => file,
|
||||||
|
|
4
templates/multinode/get_non_paying_customers.erb.sh
Normal file
4
templates/multinode/get_non_paying_customers.erb.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
me=$(hostname -s)
|
||||||
|
cat /etc/hiera/data/common.yaml | yq -r '.multinode_mapping| to_entries |map({name: .key} + .value)| map(select(.server == "'"${me}"'")) |.[] |.name' | \
|
||||||
|
grep -Ev "$(cat /etc/hiera/data/common.yaml | yq -r '.singlenodes[]' | sed -e 's/^- //' -e 's/$/|/' | tr -d '\n' | sed 's/|$//')"
|
4
templates/multinode/get_paying_customers.erb.sh
Normal file
4
templates/multinode/get_paying_customers.erb.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cat /etc/hiera/data/common.yaml | yq -r '.multinode_mapping| to_entries |map({name: .key} + .value)| map(select(.server == "'"${me}"'")) |.[] |.name' |
|
||||||
|
grep -E "$(cat /etc/hiera/data/common.yaml | yq -r '.singlenodes[]' | sed -e 's/^- //' -e 's/$/|/' | tr -d '\n' | sed 's/|$//')"
|
21
templates/multinode/restart_and_prune.erb.sh
Normal file
21
templates/multinode/restart_and_prune.erb.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
include_paying="${1}"
|
||||||
|
customers="$(/usr/local/bin/get_non_paying_customers)"
|
||||||
|
echo "Starting cleanup: $(date)"
|
||||||
|
if [[ -n ${include_paying} ]]; then
|
||||||
|
echo "Including paying customers: $(date)"
|
||||||
|
customers="${customers}
|
||||||
|
$(/usr/local/bin/get_paying_customers)"
|
||||||
|
fi
|
||||||
|
touch /etc/no-automatic-cosmos
|
||||||
|
for customer in ${customers}; do
|
||||||
|
echo "Stopping ${customer}: $(date)"
|
||||||
|
systemctl stop sunet-{redis,nextcloud}-"${customer}"
|
||||||
|
echo "Pruning docker: $(date)"
|
||||||
|
docker system prune -af --volumes
|
||||||
|
echo "Starting ${customer}: $(date)"
|
||||||
|
systemctl start sunet-{redis,nextcloud}-"${customer}"
|
||||||
|
done
|
||||||
|
rm /etc/no-automatic-cosmos
|
||||||
|
echo "Cleanup done: $(date)"
|
Loading…
Reference in a new issue