Skip to content

Commit

Permalink
fix: SC4S failed to start, because container with same name
Browse files Browse the repository at this point in the history
Executing this ExecStartPre ensures that if the container exists is deleted. If the container doesn't exist the code || /bin/true makes the script continue.
  • Loading branch information
guillerg86 authored and ikheifets-splunk committed Jun 3, 2024
1 parent b258df7 commit 83bc799
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ansible/resources/docker_sc4s.service
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ExecStartPre=/usr/bin/docker pull $SC4S_IMAGE
# when startup fails on running bash check if the path is correct
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment SC4SHOST=$(hostname -s)"

# Note: Prevent the error "Can't create container because exists another container with SC4S name"
ExecStartPre=/usr/bin/docker rm SC4S > /dev/null 2>&1 || /usr/bin/true
ExecStart=/usr/bin/docker run \
-e "SC4S_CONTAINER_HOST=${SC4SHOST}" \
-v "$SC4S_PERSIST_MOUNT" \
Expand All @@ -41,4 +43,4 @@ ExecStart=/usr/bin/docker run \
--name SC4S \
--rm $SC4S_IMAGE

Restart=on-abnormal
Restart=always
4 changes: 3 additions & 1 deletion ansible/resources/podman_sc4s.service
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ExecStartPre=/usr/bin/podman pull $SC4S_IMAGE
# when startup fails on running bash check if the path is correct
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment SC4SHOST=$(hostname -s)"

# Note: Prevent the error "Can't create container because exists another container with SC4S name"
ExecStartPre=/usr/bin/podman rm SC4S > /dev/null 2>&1 || /usr/bin/true
ExecStart=/usr/bin/podman run \
-e "SC4S_CONTAINER_HOST=${SC4SHOST}" \
-v "$SC4S_PERSIST_MOUNT" \
Expand All @@ -42,4 +44,4 @@ ExecStart=/usr/bin/podman run \
--name SC4S \
--rm $SC4S_IMAGE

Restart=on-abnormal
Restart=always
4 changes: 3 additions & 1 deletion docs/resources/docker/sc4s.service
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ExecStartPre=/usr/bin/docker pull $SC4S_IMAGE
# when startup fails on running bash check if the path is correct
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment SC4SHOST=$(hostname -s)"

# Note: Prevent the error "Can't create container because exists another container with SC4S name"
ExecStartPre=/usr/bin/docker rm SC4S > /dev/null 2>&1 || /usr/bin/true
ExecStart=/usr/bin/docker run \
-e "SC4S_CONTAINER_HOST=${SC4SHOST}" \
-v "$SC4S_PERSIST_MOUNT" \
Expand All @@ -41,4 +43,4 @@ ExecStart=/usr/bin/docker run \
--name SC4S \
--rm $SC4S_IMAGE

Restart=on-abnormal
Restart=always
4 changes: 3 additions & 1 deletion docs/resources/podman/sc4s.service
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ExecStartPre=/usr/bin/podman pull $SC4S_IMAGE
# when startup fails on running bash check if the path is correct
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment SC4SHOST=$(hostname -s)"

# Note: Prevent the error "Can't create container because exists another container with SC4S name"
ExecStartPre=/usr/bin/podman rm SC4S > /dev/null 2>&1 || /usr/bin/true
ExecStart=/usr/bin/podman run \
-e "SC4S_CONTAINER_HOST=${SC4SHOST}" \
-v "$SC4S_PERSIST_MOUNT" \
Expand All @@ -42,4 +44,4 @@ ExecStart=/usr/bin/podman run \
--name SC4S \
--rm $SC4S_IMAGE

Restart=on-abnormal
Restart=always

0 comments on commit 83bc799

Please sign in to comment.