Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Patch for Harbor 2.8.2's install script to support systemd
diff -uNr harbor.orig/ harbor/
--- harbor.orig/ 2023-06-02 11:46:12.000000000 +0000
+++ harbor/ 2023-07-26 18:04:48.666624099 +0000
@@ -19,6 +19,8 @@
# trivy is not enabled by default
+# assume no systemd for now
# flag to using docker compose v1 or v2, default would using v1 docker-compose
@@ -90,7 +92,38 @@
echo ""
-h2 "[Step $item]: starting Harbor ..."
+if [ -d /etc/systemd ]
+ have_systemd=true
+ h2 "[Step $item]: installing Harbor systemd service ..."; let item+=1
+ cat >/etc/systemd/system/harbor.service <<EOF
+Description=Harbor Cloud Native Registry
+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
+ note "Reloading systemd unit files ..."
+ systemctl daemon-reload
+ note "Setting Harbor to start on boot ..."
+ systemctl enable harbor
+h2 "[Step $item]: starting Harbor ..."; let item+=1
if [ $with_notary ]
warn "
@@ -99,6 +132,11 @@
Please see discussion here for more details."
+if [ $have_systemd ]
+ systemctl start harbor
success $"----Harbor has been installed and started successfully.----"
Copy link

dleske commented Jul 27, 2023

To use, copy to harbor.patch (or whatever, but that's the filename I'm using in the example), then:

# unpack harbor 2.8.2
tar xfz harbor-online-installer-v2.8.2.tgz

# patch it
patch -p0 < harbor.patch

# run as you normally would (don't forget to create harbor.yml first)
cd harbor
sudo ./ <options>

Might work on earlier versions, will not work on later versions as there are changes to the install script that cause the patch to fail. I've submitted a PR to add this to the install script moving forward, but if that's not accepted, the changes shown here should still work, you'll just have to patch the file manually.

Copy link

ffppmm commented Jul 27, 2023

nice work. Maybe you shoud use the existing systemd Unit file:

With relative path, something like that,
regards Philipp

Copy link

dleske commented Jul 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment