Logoj0ke.net Open Build Service > Projects > internetx:php7 > apache-rpm-macros-control > macros.apache-control
Sign Up | Log In

File macros.apache-control of Package apache-rpm-macros-control

 
1
# flag pattern: %%{apache_restart_flag}        restart all
2
#               %%{apache_restart_flag}@       restart apache2.service
3
#               %%{apache_restarT_flag}@<name> restart apache2@<name>.service
4
%apache_restart_flag /var/run/httpd.restart.flag
5
6
#
7
# macro: apache_module_request_restart -- request restart of the apache
8
#        instance(s) after rpm or zypper transaction
9
#
10
#        usage: apache_request_restart [-m module]
11
#
12
#        module: restart every instance for which a2enmod -q <module> is true; if
13
#                no module specified, request restart of all instances
14
#
15
%apache_request_restart(m:) \
16
  if [ -x /usr/bin/systemctl ]; then \
17
    MODULE=%{-m:%{-m*}} \
18
    if [ -z "$MODULE" ]; then \
19
      # restart all instances \
20
      touch %{apache_restart_flag} \
21
      echo 'Requesting apache restart (all instances)' \
22
    else \
23
      running_units=$(systemctl list-units | grep 'apache2\\(@.*\\)\\?.service' | sed 's:\\(\\.service\\).*:\\1:') \
24
      for unit in $running_units; do \
25
        instance_name=$(echo $unit | sed 's:apache2@\\?\\(.*\\).service:\\1:') \
26
        if HTTPD_INSTANCE="$instance_name" a2enmod -q $MODULE; then \
27
          # restart only specified instance, %%{apache_restart_flag}@ \
28
          # means _only_ apache2.service \
29
          echo "$instance_name" > %{apache_restart_flag}@$instance_name \
30
          echo "Requesting apache restart ($instance_name instance)" \
31
        fi \
32
      done \
33
    fi \
34
  fi \
35
  %nil
36
#
37
# macro: apache_module_restart_if_needed 
38
#
39
#
40
%apache_restart_if_needed() \
41
  if [ -x /usr/bin/systemctl ]; then \
42
    if [ -e %{apache_restart_flag} ]; then \
43
      /usr/bin/systemctl daemon-reload > /dev/null 2>&1 || : \
44
      /usr/bin/systemctl restart apache2.target > /dev/null 2>&1 || : \
45
      echo 'Restarting apache (all instances)' \
46
      # all instances was restarted, removing all flags \
47
      rm %{apache_restart_flag}* \
48
    else \
49
      /usr/bin/systemctl daemon-reload > /dev/null 2>&1 || : \
50
      for flag in %{apache_restart_flag}@*; do \
51
        if [ ! -e $flag ]; then \
52
          # %%{apache_restart_flag}@* have not matched anything \
53
          break \
54
        fi \
55
        instance_name=$(cat $flag) \
56
        if [ -z "$instance_name" ]; then \
57
          instance_suffix="" \
58
        else \
59
          instance_suffix="@$instance_name" \
60
        fi \
61
        echo "Restarting apache ($instance_name instance)" \
62
        /usr/bin/systemctl restart apache2${instance_suffix}.service > /dev/null 2>&1 || : \
63
        rm %{apache_restart_flag}@$instance_name \
64
      done \
65
    fi \
66
  fi \
67
  %nil
68
69