10343: Update postinst script to run on Red Hat systems, and accommodate Python33...
authorTom Clegg <tom@curoverse.com>
Fri, 28 Oct 2016 22:22:24 +0000 (18:22 -0400)
committerTom Clegg <tom@curoverse.com>
Fri, 28 Oct 2016 22:22:24 +0000 (18:22 -0400)
build/go-python-package-scripts/postinst
build/go-python-package-scripts/prerm
doc/_includes/_install_docker_cleaner.liquid
services/dockercleaner/arvados-docker-cleaner.service

index 051c8bd98bd379cf29752f08ea1d88284706d60e..729855a8806faa938bda6e9d3a95a3159eca08b5 100755 (executable)
@@ -2,39 +2,61 @@
 
 set -e
 
-# NOTE: This package name detection will only work on Debian.
-# If this postinst script ever starts doing work on Red Hat,
-# we'll need to adapt this code accordingly.
-script="$(basename "${0}")"
-pkg="${script%.postinst}"
-systemd_unit="${pkg}.service"
+if [ "%{name}" != "%\{name\}" ]; then
+    # Red Hat ("%{...}" is interpolated at package build time)
+    pkg="%{name}"
+    pkgtype=rpm
+    prefix="${RPM_INSTALL_PREFIX}"
+else
+    # Debian
+    script="$(basename "${0}")"
+    pkg="${script%.postinst}"
+    pkgtype=deb
+    prefix=/usr
+fi
 
-case "${1}" in
-    configure)
-        if [ -d /lib/systemd/system ]
-        then
-            # Python packages put all data files in /usr, so we copy
-            # them to /lib at install time.
-            py_unit="/usr/share/doc/${pkg}/${pkg}.service"
-            if [ -e "${py_unit}" ]
-            then
-                cp "${py_unit}" /lib/systemd/system/
+case "${pkgtype}-${1}" in
+    deb-configure | rpm-1)
+        dest_dir="/lib/systemd/system"
+        if ! [ -d "${dest_dir}" ]; then
+            exit 0
+        fi
+
+        # Find the unit file we need to install.
+        unit_file="${pkg}.service"
+        for dir in \
+            "${prefix}/share/doc/${pkg}" \
+            "${dest_dir}"; do
+            if [ -e "${dir}/${unit_file}" ]; then
+                src_dir="${dir}"
+                break
             fi
+        done
+        if [ -z "${src_dir}" ]; then
+            echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
+            exit 0
+        fi
+
+        # Install/update the unit file if necessary.
+        if [ "${src_dir}" != "${dest_dir}" ]; then
+            cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
         fi
 
+        # Enable service, and make sure systemd re-reads the unit
+        # file, in case we changed it.
         if [ -e /run/systemd/system ]; then
-            eval "$(systemctl -p UnitFileState show "${systemd_unit}")"
+            systemctl daemon-reload || true
+            eval "$(systemctl -p UnitFileState show "${pkg}")"
             case "${UnitFileState}" in
                 disabled)
                     # Failing to enable or start the service is not a
                     # package error, so don't let errors here
                     # propagate up.
-                    systemctl enable "${systemd_unit}" || true
-                    systemctl start "${systemd_unit}" || true
+                    systemctl enable "${pkg}" || true
+                    systemctl start "${pkg}" || true
                     ;;
                 enabled)
-                    systemctl daemon-reload || true
-                    systemctl reload-or-try-restart "${systemd_unit}" || true
+                    systemctl reload-or-try-restart "${pkg}" || true
                     ;;
             esac
         fi
index c6ec18ca106cb1bba11e761363715fb1ce40c0d2..26baa62aa1b74266fd853062e5cb25bb4ec6a93d 100755 (executable)
@@ -2,26 +2,29 @@
 
 set -e
 
-# NOTE: This package name detection will only work on Debian.
-# If this prerm script ever starts doing work on Red Hat,
-# we'll need to adapt this code accordingly.
-script="$(basename "${0}")"
-pkg="${script%.prerm}"
-systemd_unit="${pkg}.service"
+if [ "%{name}" != "%\{name\}" ]; then
+    # Red Hat ("%{...}" is interpolated at package build time)
+    pkg="%{name}"
+    pkgtype=rpm
+    prefix="${RPM_INSTALL_PREFIX}"
+else
+    # Debian
+    script="$(basename "${0}")"
+    pkg="${script%.prerm}"
+    pkgtype=deb
+    prefix=/usr
+fi
 
-case "${1}" in
-    remove)
+case "${pkgtype}-${1}" in
+    deb-remove | rpm-0)
         if [ -e /run/systemd/system ]; then
-            systemctl stop "${systemd_unit}" || true
-            systemctl disable "${systemd_unit}" || true
+            systemctl stop "${pkg}" || true
+            systemctl disable "${pkg}" || true
         fi
-
-        # Unit files from Python packages get installed by postinst so
-        # we have to remove them explicitly here.
-        py_unit="/usr/share/doc/${pkg}/${pkg}.service"
-        if [ -e "${py_unit}" ]
-        then
-            rm "/lib/systemd/system/${pkg}.service" || true
+        if [ -e "${prefix}/share/doc/${pkg}/${pkg}.service" ]; then
+            # Unit files from Python packages get installed by
+            # postinst so we have to remove them explicitly here.
+            rm "/lib/systemd/system/${pkg}/${pkg}.service" || true
         fi
         ;;
 esac
index 6db5e4af2974b707d773d4f4547b37d8eaf7498f..6b7ec90e6394e4a2105ae4453d2648f56bfb7cc3 100644 (file)
@@ -18,38 +18,11 @@ Create a file @/etc/arvados/docker-cleaner/docker-cleaner.json@ in an editor, wi
 
 *Choosing a quota:* Most deployments will want a quota that's at least 10G.  From there, a larger quota can help reduce compute overhead by preventing reloading the same Docker image repeatedly, but will leave less space for other files on the same storage (usually Docker volumes).  Make sure the quota is less than the total space available for Docker images.
 
-*On Debian-based systems,* the @arvados-docker-cleaner@ service is enabled automatically when installed. Restart the service after updating the configuration file:
+Restart the service after updating the configuration file.
 
 <notextile>
 <pre><code>~$ <span class="userinput">sudo systemctl restart arvados-docker-cleaner</span>
 </code></pre>
 </notextile>
 
-*On Red Hat-based systems,* first install the systemd unit file included in the distribution.
-
-<notextile>
-<pre><code>~$ <span class="userinput">sudo cp /usr/share/doc/arvados-docker-cleaner/arvados-docker-cleaner.service /lib/systemd/system/</span>
-</code></pre>
-</notextile>
-
-{% include 'notebox_begin' %}
-
-If your deployment uses a Python 3 Software Collection, the package files will be installed to a different location, and you must modify the ExecStart line as described in the comments in the unit file.
-
-<notextile>
-<pre><code>~$ <span class="userinput">sudo cp /opt/rh/python33/root/usr/share/doc/arvados-docker-cleaner/arvados-docker-cleaner.service /lib/systemd/system/</span>
-~$ <span class="userinput">sudo nano /lib/systemd/system/arvados-docker-cleaner.service</span>
-</code></pre>
-</notextile>
-
-{% include 'notebox_end' %}
-
-Next, use @systemctl@ to enable and start the service.
-
-<notextile>
-<pre><code>~$ <span class="userinput">sudo systemctl enable arvados-docker-cleaner</span>
-~$ <span class="userinput">sudo systemctl start arvados-docker-cleaner</span>
-</code></pre>
-</notextile>
-
 *If you are using a different daemon supervisor,* or if you want to test the daemon in a terminal window, run @arvados-docker-cleaner@. Run @arvados-docker-cleaner --help@ for more configuration options.
index 416ea4422caa3d241b0618e66b2a841186a6fd66..466e971fee4fb91714361ef90871bdf6f21b8e29 100644 (file)
@@ -9,11 +9,7 @@ Type=simple
 Restart=always
 RestartSec=10s
 RestartPreventExitStatus=2
-#
-# If your deployment uses a Python 3 Software Collection, uncomment the
-# ExecStart line below, and delete the following one:
-#ExecStart=/usr/bin/env scl enable python33 arvados-docker-cleaner
-ExecStart=/usr/bin/env arvados-docker-cleaner
+ExecStart=/bin/sh -c 'if [ -e /opt/rh/python33/root/bin/arvados-docker-cleaner ]; then exec scl enable python33 arvados-docker-cleaner; else exec arvados-docker-cleaner; fi'
 
 [Install]
 WantedBy=multi-user.target