File: sysvinit-core.postinst

package info (click to toggle)
sysvinit 2.88dsf-59
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,300 kB
  • ctags: 1,736
  • sloc: ansic: 7,096; sh: 3,883; perl: 371; makefile: 315
file content (139 lines) | stat: -rwxr-xr-x 2,528 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#! /bin/sh
#
# sysvinit postinst
#

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

# Restart init, and migrate to /run/initctl if needed.
do_restart() {
	INITCTL=/run/initctl
	case "$(uname -s)" in
	  *FreeBSD)
		OLDINITCTL=/etc/.initctl
		;;
	  *)
		OLDINITCTL=/dev/initctl
		;;
	esac

	# PID of init; may not always be 1 but this code isn't run in
	# these cases (Hurd).  Use for sending signals and checking if
	# init is running.
	PID=1

	# Create /run/initctl if not present, and also create compatibility
	# symlinks
	if [ ! -p "$INITCTL" ]
	then
		# Create new control channel
		echo "sysvinit: creating $INITCTL"
		rm -f $INITCTL
		mkfifo -m 600 $INITCTL
        fi

	# Replace old control channel with symlink
	ln -s "$INITCTL" "$OLDINITCTL.new"
	mv "$OLDINITCTL.new" "$OLDINITCTL"

	# Reopen control channel (uses new channel).
	kill -s USR1 "$PID"

	# Tell init to re-exec itself.  We loop on failure to reduce
	# the chance of a race before the new control channel is
	# opened.
	echo -n "sysvinit: restarting..."
	for delay in 0 1 2 3 4 5 6 fail;
	do
		if init u
		then
			echo " done."
			break
		else
			if [ "$delay" = "fail" ]
			then
				echo " failed."
			else
				echo -n "."
				sleep "$delay"
			fi
		fi
	done

	# Remove old pipe if present.  No longer in use after re-exec.
	if [ -p "$OLDINITCTL" ]
	then
	        rm -f "$OLDINITCTL"
	fi
}

case "$1" in
  configure)
	oldver=$2
	;;
  abort-upgrade|abort-remove|abort-deconfigure)
	exit 0
	;;
esac

umask 022

rm -f /etc/ioctl.save

if [ ! -f /etc/inittab ]
then
	cp -p /usr/share/sysvinit/inittab /etc/inittab
elif [ "$(uname)" = GNU ]; then
	ITAB=/etc/inittab
	ITABNEW=${ITAB}.dpkg-new
	cp $ITAB $ITABNEW
	if fgrep -q '/libexec/getty' $ITABNEW; then
		sed -e 's|/libexec/getty|/sbin/getty|' \
		    -i $ITABNEW
	fi
	if ! grep -q '^c:' $ITABNEW; then
		sed -e '/^6:/a c:23:respawn:/sbin/getty 38400 console' \
		    -i $ITABNEW
	fi

	if ! diff $ITAB $ITABNEW >/dev/null; then
	    db_get sysvinit/hurd-fix-inittab
	    if [ "${RET}" = "true" ]; then
		    mv -- $ITAB ${ITAB}.dpkg-old
		    mv -- $ITABNEW $ITAB
	    fi
	else
	    rm -f -- $ITABNEW
	fi
fi

restart=yes

chroot=0
ischroot || chroot="$?"

if [ "$chroot" != "1" ]; then
	restart=no
fi

# If systemd is running, don't restart init or doing any initctl
# migration.
if [ -d /run/systemd/system ]; then
	restart=no
fi
if [ "$(uname -s)" = "GNU" ]; then
	restart=no
fi

if [ "$restart" = "yes" ]; then
	do_restart
else
	echo "Not restarting sysvinit"
fi

#DEBHELPER#

exit 0