summary refs log tree commit diff
path: root/debian/runit.postinst
blob: 498ccc2bd4d3dd367a1ce281037934e0414e89da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
set -e

test "$1" = 'configure' || exit 0

mv_conffile() {
  test -e "$1" || return 0
  echo "Preserving user changes to $2..."
  mv -f "$2" "$2".dpkg-new
  mv -f "$1" "$2"
}

if dpkg --compare-versions "$2" lt '1.4.0-0'; then
  mv_conffile /etc/runit/getty-5/run /etc/sv/getty-5/run
  mv_conffile /etc/runit/getty-5/finish /etc/sv/getty-5/finish
  rmdir /etc/runit/getty-5 2>/dev/null || :
fi

if test -z "$2"; then
  # not upgrading
  if grep '^SV:' /etc/inittab >/dev/null; then
    cat <<\EOT >&2

There already is an SV entry in /etc/inittab.  In order to have this package
add an entry with the name SV to have runit's service supervision started
by sysvinit, you need to remove or rename the current SV entry first.

Installation failed.

EOT
    exit 1
  fi
fi

# retain backward compatibility symlink until rdepends have adopted
if test ! -h /var/service ||
 test "$(readlink /var/service)" != /etc/service; then
  if test -e /var/service; then
    rm -rf /var/service'{old}'
    mv /var/service /var/service'{old}'
  fi
  ln -s /etc/service /var/service
fi

if ! grep '^SV:' /etc/inittab >/dev/null; then
  echo 'Adding SV inittab entry...'
  cp /etc/inittab /etc/inittab'{new}'
  cat >>/etc/inittab'{new}' <<-\EOT
	#-- runit begin
	SV:123456:respawn:/usr/sbin/runsvdir-start
	#-- runit end
	EOT
  mv -f /etc/inittab'{new}' /etc/inittab
  exec kill -s HUP 1  
fi

if test -n "$2" && dpkg --compare-versions "$2" le '1.8.0-2'; then
  # d'oh, need to lookup runsvdir's pid to send HUP ;(
  ps -C runsvdir -o pid=,ppid= >/dev/null ||
    echo >&2 "WARNING: no runsvdir process with parent pid 1 found."
  ps -C runsvdir -o pid=,ppid= |
    while read pid ppid; do test "$ppid" != 1 || exec kill -s HUP $pid; done
fi