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