Skip to content

Commit

Permalink
refactor nstallers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 30, 2024
1 parent 1f76925 commit acbaedb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
46 changes: 24 additions & 22 deletions orijen-udf-base-install.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#!/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
# Ensure the script is run with root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi

# Check for docker and install if it's missing
if ! command -v docker &> /dev/null; then
echo "Docker could not be found, updating repositories and installing..."
apt-get update --quiet
apt-get install --quiet --yes docker.io
fi

# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker
systemctl enable docker
systemctl start docker

# Variable Declarations
IMAGE=ghcr.io/f5devcentral/orijen-udf-service/orijen-udf-base:latest
SERVICE=orijen-udf-base.service
CONTAINER=orijen-udf-base
IMAGE="ghcr.io/f5devcentral/orijen-udf-service/orijen-udf-base:dev"
SERVICE="orijen-udf-base.service"
CONTAINER="orijen-udf-base"

# Create the systemd service file
sudo bash -c "cat > /etc/systemd/system/$SERVICE <<EOF
cat <<EOF >/etc/systemd/system/$SERVICE
[Unit]
Description=Orijen UDF Service
Requires=docker.service
Expand All @@ -29,21 +32,20 @@ After=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop $IMAGE
ExecStartPre=-/usr/bin/docker rm $IMAGE
ExecStartPre=-/usr/bin/docker stop $CONTAINER
ExecStartPre=-/usr/bin/docker rm $CONTAINER
ExecStartPre=/usr/bin/docker pull $IMAGE
ExecStart=/usr/bin/docker run --rm --name $CONTAINER $IMAGE
ExecStop=/usr/bin/docker stop $CONTAINER
[Install]
WantedBy=multi-user.target
EOF"
EOF

# Reload systemd manager configuration
sudo systemctl daemon-reload
systemctl daemon-reload

# Enable and start your app service
sudo systemctl enable $SERVICE
sudo systemctl start $SERVICE
# Enable the service
systemctl enable $SERVICE

echo "$SERVICE has been installed and started as a systemd service."
echo "$SERVICE has been installed and enabled."
56 changes: 30 additions & 26 deletions orijen-udf-site-install.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
#!/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
# Ensure the script is run with root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi

# Check for docker and install if it's missing
if ! command -v docker &> /dev/null; then
echo "Docker could not be found, updating repositories and installing..."
apt-get update --quiet
apt-get install --quiet --yes docker.io
fi

# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker
systemctl enable docker
systemctl start docker

# Variable Declarations
IMAGE=ghcr.io/f5devcentral/orijen-udf-service/orijen-udf-site:latest
SERVICE=orijen-udf-site.service
IMAGE="ghcr.io/f5devcentral/orijen-udf-service/orijen-udf-site:dev"
SERVICE="orijen-udf-site.service"
CONTAINER="orijen-udf-site"

# Create the systemd service file
sudo bash -c "cat > /etc/systemd/system/$SERVICE <<EOF
cat <<EOF >/etc/systemd/system/$SERVICE
[Unit]
Description=Orijen Site Registration Service
Description=Orijen UDF Site Service
Requires=docker.service
After=docker.service network-online.target
Wants=network-online.target
After=docker.service
[Service]
Type=oneshot
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop $CONTAINER
ExecStartPre=-/usr/bin/docker rm $CONTAINER
ExecStartPre=/usr/bin/docker pull $IMAGE
ExecStart=/usr/bin/docker run --rm $IMAGE
RemainAfterExit=no
SuccessExitStatus=0
ExecStart=/usr/bin/docker run --rm --name $CONTAINER $IMAGE
ExecStop=/usr/bin/docker stop $CONTAINER
[Install]
WantedBy=multi-user.target
EOF"
EOF

# Reload systemd manager configuration
sudo systemctl daemon-reload
systemctl daemon-reload

# Enable and start your app service
sudo systemctl enable $SERVICE
sudo systemctl start $SERVICE
# Enable the service
systemctl enable $SERVICE

echo "$SERVICE has been installed and started as a systemd service."
echo "$SERVICE has been installed and enabled."

0 comments on commit acbaedb

Please sign in to comment.