Less dangerous pruning script
This commit is contained in:
parent
f2f919a59c
commit
165415b725
|
@ -53,11 +53,22 @@ class sunetdrive::multinode (
|
|||
group => 'root',
|
||||
}
|
||||
file { '/usr/local/bin/upgrade23-25.sh':
|
||||
ensure => absent,
|
||||
}
|
||||
file { '/usr/local/bin/get_paying_customers':
|
||||
ensure => present,
|
||||
force => true,
|
||||
owner => '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',
|
||||
}
|
||||
file { '/usr/local/bin/get_containers':
|
||||
|
@ -68,6 +79,14 @@ class sunetdrive::multinode (
|
|||
content => template('sunetdrive/multinode/get_containers'),
|
||||
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':
|
||||
ensure => present,
|
||||
force => true,
|
||||
|
@ -92,14 +111,21 @@ class sunetdrive::multinode (
|
|||
content => template('sunetdrive/multinode/proxysql.cnf.erb'),
|
||||
mode => '0644',
|
||||
}
|
||||
if $environment == 'test' {
|
||||
cron { 'multinode_prune':
|
||||
command => '/opt/nextcloud/prune.sh',
|
||||
require => File['/opt/nextcloud/prune.sh'],
|
||||
user => 'root',
|
||||
minute => '25',
|
||||
hour => '4',
|
||||
}
|
||||
sunet::scriptherder::cronjob { 'prune_non_paying':
|
||||
cmd => '/usr/local/bin/restart_and_prune',
|
||||
day => '1-6'
|
||||
hour => '2',
|
||||
minute => '45',
|
||||
ok_criteria => ['exit_status=0','max_age=3d'],
|
||||
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':
|
||||
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