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
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
*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.
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