14860: Exposes the bug with a new test.
[arvados.git] / build / rails-package-scripts / step2.sh
1 #!/bin/sh
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # This code runs after package variable definitions, before the actual
7 # pre/post package work, to set some variable and function defaults.
8
9 if [ -z "$INSTALL_PATH" ]; then
10     cat >&2 <<EOF
11
12 PACKAGE BUILD ERROR: $0 is missing package metadata.
13
14 This package is buggy.  Please mail <support@curoverse.com> to let
15 us know the name and version number of the package you tried to
16 install, and we'll get it fixed.
17
18 EOF
19     exit 3
20 fi
21
22 RELEASE_PATH=$INSTALL_PATH/current
23 RELEASE_CONFIG_PATH=$RELEASE_PATH/config
24 SHARED_PATH=$INSTALL_PATH/shared
25
26 RAILSPKG_SUPPORTS_CONFIG_CHECK=${RAILSPKG_SUPPORTS_CONFIG_CHECK:-1}
27 if ! type setup_extra_conffiles >/dev/null 2>&1; then
28     setup_extra_conffiles() { return; }
29 fi
30 if ! type setup_before_nginx_restart >/dev/null 2>&1; then
31     setup_before_nginx_restart() { return; }
32 fi
33
34 if [ -e /run/systemd/system ]; then
35     USING_SYSTEMD=1
36 else
37     USING_SYSTEMD=0
38 fi
39
40 if which service >/dev/null 2>&1; then
41     USING_SERVICE=1
42 else
43     USING_SERVICE=0
44 fi
45
46 guess_service_manager() {
47     if [ 1 = "$USING_SYSTEMD" ]; then
48         echo systemd
49     elif [ 1 = "$USING_SERVICE" ]; then
50         echo service
51     else
52         return 1
53     fi
54 }
55
56 list_services_systemd() {
57     test 1 = "$USING_SYSTEMD" || return
58     # Print only service names, without the `.service` suffix.
59     systemctl list-unit-files '*.service' \
60         | awk '($1 ~ /\.service/){print substr($1, 1, length($1) - 8)}'
61 }
62
63 list_services_service() {
64     test 1 = "$USING_SERVICE" || return
65     # Output is completely different across Debian and Red Hat.
66     # We can't really parse it.
67     service --status-all 2>/dev/null
68 }
69
70 service_command() {
71     local service_manager="$1"; shift
72     local command="$1"; shift
73     local service="$1"; shift
74     case "$service_manager" in
75         systemd) systemctl "$command" "$service" ;;
76         service) service "$service" "$command" ;;
77     esac
78 }
79
80 if ! guess_service_manager >/dev/null; then
81     echo "WARNING: Unsupported init system. Can't manage web service." >&2
82 fi