Created
July 27, 2023 00:05
-
-
Save dleske/7a42485d582149480b8fd46fe833848e to your computer and use it in GitHub Desktop.
Patch for Harbor 2.8.2's install script to support systemd
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
diff -uNr harbor.orig/install.sh harbor/install.sh | |
--- harbor.orig/install.sh 2023-06-02 11:46:12.000000000 +0000 | |
+++ harbor/install.sh 2023-07-26 18:04:48.666624099 +0000 | |
@@ -19,6 +19,8 @@ | |
with_clair=$false | |
# trivy is not enabled by default | |
with_trivy=$false | |
+# assume no systemd for now | |
+have_systemd=$false | |
# flag to using docker compose v1 or v2, default would using v1 docker-compose | |
DOCKER_COMPOSE=docker-compose | |
@@ -90,7 +92,38 @@ | |
fi | |
echo "" | |
-h2 "[Step $item]: starting Harbor ..." | |
+if [ -d /etc/systemd ] | |
+then | |
+ have_systemd=true | |
+ h2 "[Step $item]: installing Harbor systemd service ..."; let item+=1 | |
+ | |
+ cat >/etc/systemd/system/harbor.service <<EOF | |
+[Unit] | |
+Description=Harbor Cloud Native Registry | |
+Documentation=https://goharbor.io | |
+After=docker.service | |
+Requires=docker.service | |
+ | |
+[Service] | |
+Type=simple | |
+Restart=on-failure | |
+RestartSec=5 | |
+ExecStart=${DOCKER_COMPOSE} -f ${workdir}/docker-compose.yml up | |
+ExecStop=${DOCKER_COMPOSE} -f ${workdir}/docker-compose.yml down -v | |
+ExecStopPost=${DOCKER_COMPOSE} -f ${workdir}/docker-compose.yml rm -f | |
+ | |
+[Install] | |
+WantedBy=multi-user.target | |
+EOF | |
+ | |
+ note "Reloading systemd unit files ..." | |
+ systemctl daemon-reload | |
+ | |
+ note "Setting Harbor to start on boot ..." | |
+ systemctl enable harbor | |
+fi | |
+ | |
+h2 "[Step $item]: starting Harbor ..."; let item+=1 | |
if [ $with_notary ] | |
then | |
warn " | |
@@ -99,6 +132,11 @@ | |
Please see discussion here for more details. https://github.com/goharbor/harbor/discussions/16612" | |
fi | |
-$DOCKER_COMPOSE up -d | |
+if [ $have_systemd ] | |
+then | |
+ systemctl start harbor | |
+else | |
+ $DOCKER_COMPOSE up -d | |
+fi | |
success $"----Harbor has been installed and started successfully.----" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @ffppmm, it is indeed based on that but fixes the broken
docker compose
call, replacing it with the variable set earlier in the script, and uses the path in place for the installation. So for me I unpack Harbor in/opt/harbor-<version>
, symlink from/opt/harbor
, and run the install script from/opt/harbor
so that's the working directory and it'll be a tad smoother to upgrade as I won't then have to update the unit file.