← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:add_rabbitmq_cleanup_to_rabbitmq_unit into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:add_rabbitmq_cleanup_to_rabbitmq_unit into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/458627
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:add_rabbitmq_cleanup_to_rabbitmq_unit into autopkgtest-cloud:master.
diff --git a/mojo/manifest b/mojo/manifest
index c60df1b..b5be817 100644
--- a/mojo/manifest
+++ b/mojo/manifest
@@ -2,3 +2,8 @@ collect
 secrets
 bundle config=service-bundle wait=True max-wait=1200
 script config=make-lxd-secgroup
+<<<<<<< mojo/manifest
+=======
+script config=postdeploy
+script config=rabbitmq-cleanup-setup
+>>>>>>> mojo/manifest
diff --git a/mojo/rabbitmq-cleanup-setup b/mojo/rabbitmq-cleanup-setup
new file mode 100644
index 0000000..8fb4ea9
--- /dev/null
+++ b/mojo/rabbitmq-cleanup-setup
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+##################################################################
+# Get machine number for rabbitmq-server application
+machine=$(juju status --format=json rabbitmq-server | jq --monochrome-output --raw-output '.applications["rabbitmq-server"].units | map(.["machine"])[]')
+
+##################################################################
+# set file names
+service_name="maybe-restart-rabbitmq"
+rabbitmq_mdir="/home/ubuntu/${service_name}"
+
+##################################################################
+# Create script
+cat > /tmp/"${service_name}" << EOM
+#!/bin/sh
+
+set -e
+
+# Set a limit 2 GiB
+LIMIT=$((2 * 1024 * 1024 * 1024))
+
+if [ $(cat /sys/fs/cgroup/memory/system.slice/rabbitmq-server.service/memory.usage_in_bytes 2>/dev/null || echo 0) -ge $LIMIT ]; then
+	echo "RabbitMQ uses too much memory, restarting"
+	timeout 30 rabbitmq-diagnostics memory_breakdown || true
+	systemctl restart rabbitmq-server.service
+fi
+
+EOM
+
+chmod +x /tmp/"${service_name}"
+
+# Create service file
+cat > /tmp/"${service_name}".service << EOM
+[Unit]
+Description=Check rabbitmq memory use and restart if needed
+
+[Service]
+Type=oneshot
+ExecStart=/usr/local/sbin/maybe-restart-rabbitmq
+EOM
+
+# Create timer file
+cat > /tmp/"${service_name}".timer << EOM
+[Unit]
+Description=Check rabbitmq every 15 mins
+
+[Timer]
+OnBootSec=15min
+OnUnitInactiveSec=15min
+
+[Install]
+WantedBy=multi-user.target
+EOM
+
+##################################################################
+# Create directory for files
+juju exec --machine "${machine}" "mkdir -p ${rabbitmq_mdir}"
+
+
+##################################################################
+# Copy script to machine
+juju scp /tmp/"${service_name}" "${machine}":"${rabbitmq_mdir}/"
+
+# Copy service to machine
+juju scp /tmp/"${service_name}".service "${machine}":"${rabbitmq_mdir}/"
+
+# Copy timer to machine
+juju scp /tmp/"${service_name}".timer "${machine}":"${rabbitmq_mdir}/"
+
+##################################################################
+# Set necessary symbolic links
+
+# Set link for script
+juju exec --machine "${machine}" "sudo ln -sf ${rabbitmq_mdir}/${service_name} /usr/local/sbin/"
+
+# Set link for service
+juju exec --machine "${machine}" "sudo ln -sf ${rabbitmq_mdir}/${service_name}.service /etc/systemd/system/"
+
+# Set link for timer
+juju exec --machine "${machine}" "sudo ln -sf ${rabbitmq_mdir}/${service_name}.timer /etc/systemd/system/"
+
+##################################################################
+# Enable systemd unit
+juju exec --machine "${machine}" "sudo systemctl daemon-reload"
+
+juju exec --machine "${machine}" "sudo systemctl restart ${service_name}.service"

Follow ups