2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
8 if [ "%{name}" != "%\{name\}" ]; then
9 # Red Hat ("%{...}" is interpolated at package build time)
12 prefix="${RPM_INSTALL_PREFIX}"
15 script="$(basename "${0}")"
16 pkg="${script%.postinst}"
21 case "${pkgtype}-${1}" in
22 deb-configure | rpm-1)
23 dest_dir="/lib/systemd/system"
24 if ! [ -d "${dest_dir}" ]; then
28 # Find the unit file we need to install.
29 unit_file="${pkg}.service"
31 "${prefix}/share/doc/${pkg}" \
33 if [ -e "${dir}/${unit_file}" ]; then
38 if [ -z "${src_dir}" ]; then
39 echo >&2 "WARNING: postinst script did not find ${unit_file} anywhere."
43 # Install/update the unit file if necessary.
44 if [ "${src_dir}" != "${dest_dir}" ]; then
45 cp "${src_dir}/${unit_file}" "${dest_dir}/" || exit 0
48 # Enable service, and make sure systemd re-reads the unit
49 # file, in case we changed it.
50 if [ -e /run/systemd/system ]; then
51 systemctl daemon-reload || true
52 eval "$(systemctl -p UnitFileState show "${pkg}")"
53 case "${UnitFileState}" in
55 # Failing to enable or start the service is not a
56 # package error, so don't let errors here
58 systemctl enable "${pkg}" || true
59 systemctl start "${pkg}" || true
62 systemctl reload-or-try-restart "${pkg}" || true