Cherry picked the stop/start files from ehds2_develop branch

This commit is contained in:
DavidCroftDKFZ 2024-07-17 09:27:32 +02:00
parent c15c3962a7
commit 353fc010cb
5 changed files with 175 additions and 0 deletions

14
ecdc.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Start ECDC Bridgehead
[Service]
Type=simple
ExecStart=/srv/docker/bridgehead/restart_service.sh
ExecStop=/srv/docker/bridgehead/shutdown_service.sh
Restart=on-failure
RestartSec=36000
KillMode=mixed
[Install]
WantedBy=multi.user.target

30
restart_service.sh Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# Start a running Bridgehead. If there is already a Bridgehead running,
# stop it first.
# This is intended to be used by systemctl.
cd /srv/docker/bridgehead
echo "git status before stop"
git status
echo "Stopping running Bridgehead, if present"
./bridgehead stop bbmri
# If "flush_blaze" is present, delete the Blaze volume before starting
# the Bridgehead again. This allows a user to upload all data, if
# requested.
if [ -f "/srv/docker/ecdc/data/flush_blaze" ]; then
docker volume rm bbmri_blaze-data
rm -f /srv/docker/ecdc/data/flush_blaze
fi
echo "git status before start"
git status | systemd-cat -p info
echo "Start the Bridgehead anew"
./bridgehead start bbmri
echo "Bridgehead has unexpectedly terminated"

79
run.sh Normal file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Start a Bridgehead from the command line. Upload data if requested.
# Behind the scenes we use systemctl to do the work.
# Function to print usage
print_usage() {
echo "Start a Bridghead, optionally upload data"
echo "Usage: $0 [--upload | --upload-all | --help | -h]"
echo "Options:"
echo " --upload Run Bridgehead and upload just the new CSV data files."
echo " --upload-all Run Bridgehead and upload all CSV data files."
echo " --help, -h Display this help message."
echo " No options Run Bridgehead only."
}
# Initialize variables
UPLOAD=false
UPLOAD_ALL=false
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--upload)
UPLOAD=true
;;
--upload-all)
UPLOAD_ALL=true
;;
--help|-h)
print_usage
exit 0
;;
*)
echo "Error: Unknown argument '$1'"
print_usage
exit 1
;;
esac
shift
done
# Check for conflicting options
if [ "$UPLOAD" = true ] && [ "$UPLOAD_ALL" = true ]; then
echo "Error: you must specify either --upload or --upload-all, specifying both is not permitted."
print_usage
exit 1
fi
# Disable/stop standard Bridgehead systemctl services, if present
sudo systemctl disable bridgehead@bbmri.service
sudo systemctl disable system-bridgehead.slice
sudo systemctl disable bridgehead-update@bbmri.timer
sudo systemctl stop bridgehead@bbmri.service
sudo systemctl stop system-bridgehead.slice
sudo systemctl stop bridgehead-update@bbmri.timer
# Set up systemctl for EHDS2/ECDC if necessary
cp /srv/docker/bridgehead/ecdc.service /etc/systemd/system
systemctl daemon-reload
systemctl enable ecdc.service
# Use systemctl to stop the Bridgehead if it is running
sudo systemctl stop ecdc.service
# Use files to tell the Bridgehead what to do with any data present
if [ "$UPLOAD" = true ] || [ "$UPLOAD_ALL" = true ]; then
if [ -f /srv/docker/ecdc/data/lock ]; then
rm /srv/docker/ecdc/data/lock
fi
fi
if [ "$UPLOAD_ALL" = true ]; then
echo "All CSV files in /srv/docker/ecdc/data will be uploaded"
touch /srv/docker/ecdc/data/flush_blaze
fi
# Start up the Bridgehead
sudo systemctl start ecdc.service

13
shutdown_service.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Shut down a running Bridgehead.
# This is intended to be used by systemctl.
cd /srv/docker/bridgehead
echo "git status before stop"
git status
echo "Stopping running Bridgehead, if present"
./bridgehead stop bbmri

39
stop.sh Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Shut down a running Bridgehead and disable auto restart.
# Behind the scenes we use systemctl to do the work.
# Function to print usage
print_usage() {
echo "Stop the running Bridgehead, disable auto-restart"
echo "Usage: $0 [--help | -h]"
echo "Options:"
echo " --help, -h Display this help message."
echo " No options Stop Bridgehead only."
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--help|-h)
print_usage
exit 0
;;
*)
echo "Error: Unknown argument '$1'"
print_usage
exit 1
;;
esac
shift
done
# Set up systemctl for EHDS2/ECDC if necessary
cp /srv/docker/bridgehead/ecdc.service /etc/systemd/system
systemctl daemon-reload
systemctl enable ecdc.service
# Use systemctl to stop the Bridgehead if it is running
sudo systemctl disable ecdc.service
sudo systemctl stop ecdc.service