summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot2017-05-16 23:57:27 +0200
committerroot2017-05-16 23:57:27 +0200
commit118ff790598aebf3c3f11a2ed73f0c842ae83e9c (patch)
tree75b47e6d849b88b099a3b26132c6410752719022
downloadserver-utilities-118ff790598aebf3c3f11a2ed73f0c842ae83e9c.tar.gz
Add LXC containers upgrade script
-rwxr-xr-xupgrade-containers.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/upgrade-containers.sh b/upgrade-containers.sh
new file mode 100755
index 0000000..dd4bba2
--- /dev/null
+++ b/upgrade-containers.sh
@@ -0,0 +1,35 @@
1#!/bin/sh -euf
2
3usage() (
4 echo "upgrade-containers.sh"
5 echo
6 echo "Upgrade currently running LXC containers."
7 echo "Uses apt-get for Debian and apk for Alpine."
8 echo
9)
10
11upgrade_container() (
12 NAME="$1"
13
14 RELEASE_FILE="/var/lib/lxc/$NAME/rootfs/etc/os-release"
15
16 if grep -q "ID=debian" "$RELEASE_FILE"; then
17 lxc-attach -n "$NAME" -- apt-get update
18 lxc-attach -n "$NAME" -- apt-get upgrade -y
19 elif grep -q "ID=alpine" "$RELEASE_FILE"; then
20 lxc-attach -n "$NAME" -- apk update
21 lxc-attach -n "$NAME" -- apk upgrade
22 fi
23)
24
25upgrade_running_containers() (
26 for CONTAINER in $(lxc-ls --running); do
27 upgrade_container "$CONTAINER"
28 done
29)
30
31case "${1:-run}" in
32 "help") usage;;
33 "run") upgrade_running_containers;;
34esac
35