Several fixes to shell scripts

This commit is contained in:
Martin Lablans 2022-01-10 16:31:48 +01:00
parent 0ecf38cabb
commit 0d7769fa7f
5 changed files with 28 additions and 39 deletions

View File

@ -11,38 +11,27 @@ if ! ./lib/prerequisites.sh; then
fi
source site.conf
echo "Installing bridgehead"
_systemd_path=/etc/systemd/system/
echo "Installing systemd units ..."
echo -e "\nInstalling systemd units ..."
cp -v \
convenience/bridgehead\@.service \
convenience/bridgehead-update\@.service \
convenience/bridgehead-update\@.timer \
$_systemd_path
echo "Loading the bridgehead definitions in systemd"
systemctl daemon-reload
echo
echo "Starting Project ${project} "
if [ ! -f "/etc/systemd/system/bridgehead@${project}.service.d/bridgehead.conf" ]; then
echo "Can't find local configuration file for bridgehead@${project} service. Please ensure that the file /etc/systemd/system/bridgehead@${project}.service.d/bridgehead.conf exists"
exit
fi
systemctl is-active --quiet bridgehead@"${project}"
if [ ! $? -eq 0 ]; then
echo "Starting bridgehead@${project} service ..."
systemctl start bridgehead@"${project}"
if ! systemctl is-active --quiet bridgehead@"${project}"; then
echo "Enabling autostart of bridgehead@${project}.service"
systemctl enable bridgehead@"${project}"
echo "Enabling nightly updates for bridgehead@${project}.service ..."
systemctl enable --now bridgehead-update@"${project}".timer
fi
# Switch back to execution directory;
cd -
echo -e "\nDone - now start your bridgehead by running\n\tsystemctl start bridgehead@${project}.service\nor by rebooting your machine."
# TODO: Configuration of the different modules

View File

@ -1,13 +1,15 @@
#!/bin/bash
### Note: Currently not complete, needs some features before useable for production
source lib/functions.sh
if ! ./prerequisites.sh; then
echo "Prerequisites failed, exiting"
log "Prerequisites failed, exiting"
exit
fi
source site.conf
echo "Starting bridgehead"
log "Starting bridgehead"
cd ${project}
@ -15,4 +17,4 @@ docker-compose --env-file ../site-config/${project}.env up -d
cd ..
echo "The bridgehead should be in online in a few seconds"
log "The bridgehead should be in online in a few seconds"

View File

@ -1,7 +1,10 @@
echo "Stoping bridgehead"
#!/bin/bash -e
source lib/functions.sh
source site.conf
log "Stopping bridgehead"
cd ${project}
docker-compose --env-file ../site-config/${project}.env down

View File

@ -1,14 +1,11 @@
echo "Stoping systemd services and removing bridgehead"
#!/bin/bash -e
source site.conf
source lib/functions.sh
systemctl stop bridgehead@"${project}".service
systemctl stop bridgehead-update@"${project}".timer
systemctl stop bridgehead-update@"${project}".service
echo "Stopping systemd services and removing bridgehead ..."
cd /etc/systemd/system/
rm bridgehead\@.service
rm bridgehead-update\@.timer
rm bridgehead-update\@.service
cd -
for i in bridgehead\@.service bridgehead-update\@.timer bridgehead-update\@.service; do
systemctl disable $i --now
rm -v /etc/systemd/system/$i
done

View File

@ -1,9 +1,7 @@
#!/bin/bash
service="bridgehead"
# Creates logs
log() {
echo "$(date +'%Y-%m-%d %T')" "$1:" "$2"
}
source lib/functions.sh
log "INFO" "Checking for updates of $service"
# check prerequisites