-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Reynolds
committed
Apr 28, 2024
1 parent
3075eb0
commit a3a92ce
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# Update apt | ||
sudo DEBIAN_FRONTEND=noninteractive apt-get update --yes | ||
|
||
# Check if Docker is installed, install it if it's not | ||
if ! command -v docker &> /dev/null | ||
then | ||
echo "Docker could not be found, installing..." | ||
sudo apt-get install -y docker.io | ||
fi | ||
|
||
# Enable and start Docker | ||
sudo systemctl enable docker | ||
sudo systemctl start docker | ||
|
||
# Variable Declarations | ||
IMAGE=ghcr.io/f5devcentral/f5xc-lab-mcn-practical/labapp:latest | ||
SERVICE=mcn-practical-labapp.service | ||
CONTAINER=mcn-practical-labapp | ||
|
||
# Create the systemd service file | ||
sudo bash -c "cat > /etc/systemd/system/$SERVICE <<EOF | ||
[Unit] | ||
Description=Orijen UDF Service | ||
Requires=docker.service | ||
After=docker.service | ||
[Service] | ||
TimeoutStartSec=0 | ||
Restart=always | ||
ExecStartPre=-/usr/bin/docker stop $IMAGE | ||
ExecStartPre=-/usr/bin/docker rm $IMAGE | ||
ExecStartPre=/usr/bin/docker pull $IMAGE | ||
ExecStart=/usr/bin/docker run -p 1337:5000 --rm --name $CONTAINER $IMAGE | ||
ExecStop=/usr/bin/docker stop $CONTAINER | ||
[Install] | ||
WantedBy=multi-user.target | ||
EOF" | ||
|
||
# Reload systemd manager configuration | ||
sudo systemctl daemon-reload | ||
|
||
# Enable and start your app service | ||
sudo systemctl enable $SERVICE | ||
sudo systemctl start $SERVICE | ||
|
||
echo "$SERVICE has been installed and started as a systemd service." |