2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # Detect rpm-based systems: the exit code of the following command is zero
8 /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1
10 if [ "$?" = "0" ]; then
11 # Red Hat ("%{...}" is interpolated at package build time)
14 prefix="${RPM_INSTALL_PREFIX}"
17 script="$(basename "${0}")"
18 pkg="${script%.postinst}"
24 case "${pkgtype}-${1}" in
25 deb-configure | rpm-1)
26 dest_dir="/lib/systemd/system"
27 if ! [ -d "${dest_dir}" ]; then
31 # Find the unit file we need to install.
32 unit_file="${pkg}.service"
34 "${prefix}/share/doc/${pkg}" \
36 if [ -e "${dir}/${unit_file}" ]; then
41 if [ -z "${src_dir}" ]; then
42 echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
46 # Install/update the unit file if necessary.
47 if [ "${src_dir}" != "${dest_dir}" ]; then
48 cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
51 # Enable service, and make sure systemd re-reads the unit
52 # file, in case we changed it.
53 if [ -e /run/systemd/system ]; then
54 systemctl daemon-reload || true
55 eval "$(systemctl -p UnitFileState show "${pkg}")"
56 case "${UnitFileState}" in
58 # Failing to enable or start the service is not a
59 # package error, so don't let errors here
61 systemctl enable "${pkg}" || true
62 systemctl start "${pkg}" || true
65 systemctl reload-or-try-restart "${pkg}" || true