File: init

package info (click to toggle)
resolvconf 1.42
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 400 kB
  • ctags: 26
  • sloc: sh: 628; makefile: 32
file content (117 lines) | stat: -rwxr-xr-x 3,262 bytes parent folder | download
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
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          resolvconf
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# X-Start-Before:    networking ifupdown
# Should-Stop:       networking ifupdown
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Nameserver information manager
# Description:       This service manages the list of nameserver addresses
#                    used by the libc resolver and name service caches
### END INIT INFO
#
# This script is part of the resolvconf package
# See /usr/share/doc/resolvconf/copyright

# Don't use set -e; check return status instead

[ -x /sbin/resolvconf ] || exit 0

MYNAME="${0##*/}"
PATH=/sbin:/bin
RUN_DIR=/etc/resolvconf/run
IFACE_DIR="${RUN_DIR}/interface"
RESOLVCONF_FILE="${RUN_DIR}/resolv.conf"
ENABLE_UPDATES_FLAGFILE="${RUN_DIR}/enable-updates"

. /lib/lsb/init-functions

# $1 EXITSTATUS
# [$2 MESSAGE]
log_action_end_msg_and_exit()
{
	log_action_end_msg "$1" ${2:+"$2"}
	exit $1
}

update()
{
	[ -e "$ENABLE_UPDATES_FLAGFILE" ] || return 0
	cd "$IFACE_DIR"
	# "update" scripts must assume that interface files are in the PWD
	run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d
}

enable_updates()
{
	: >| "$ENABLE_UPDATES_FLAGFILE"
}

disable_updates()
{
	rm -f "$ENABLE_UPDATES_FLAGFILE"
}

case "$1" in
start)
	# The "start" method should _only_ be used at boot time.
	# If you want to update the resolv.conf file then use "reload".
	# On package upgrade, don't run this.
	log_action_begin_msg "Setting up resolvconf"
	umask 022
	if [ ! -d "$RUN_DIR" ] ; then
		[ -L "$RUN_DIR" ] || log_action_end_msg_and_exit 1 "$RUN_DIR is neither a directory nor a symbolic link"
		# Target of symlink is not a dir
		{ RUN_CANONICALDIR="$(readlink -f "$RUN_DIR")" && [ "$RUN_CANONICALDIR" ] ; } || log_action_end_msg_and_exit 1 "canonical path of the run directory could not be determined"
		# Create directory at the target
		mkdir "$RUN_CANONICALDIR" || log_action_end_msg_and_exit 1 "error creating directory $RUN_CANONICALDIR"
	fi
	# The run directory exists

	if [ -d "${RUN_DIR}/interface" ] ; then
		rm -f ${RUN_DIR}/interface/*
	else
		mkdir "${RUN_DIR}/interface" || log_action_end_msg_and_exit 1 "error creating directory ${RUN_DIR}/interface"
	fi
	# The interface directory exists

	enable_updates || log_action_end_msg_and_exit 1 "could not enable updates"
	update -i
	log_action_end_msg_and_exit "$?"
	;;
stop)
	# The "stop" method should only be used at shutdown time.
	log_action_begin_msg "Stopping resolvconf"
	disable_updates
	log_action_end_msg_and_exit "$?"
	;;
restart)
	log_action_begin_msg "Restarting resolvconf"
	[ -d "${RUN_DIR}/interface" ] || log_action_end_msg_and_exit 1 "${RUN_DIR}/interface is not a directory"
	enable_updates || log_action_end_msg_and_exit 1 "could not enabling updates"
	update
	log_action_end_msg_and_exit "$?"
	;;
reload|force-reload)
	# Do it silently
	[ -d "${RUN_DIR}/interface" ] || { log_failure_msg "${RUN_DIR}/interface is not a directory" ; exit 1 ; }
	update
	exit $?
	;;
enable-updates)
	enable_updates
	exit $?
	;;
disable-updates)
	disable_updates
	exit $?
	;;
*)
	echo "Usage: /etc/init.d/resolvconf {start|stop|reload|restart|force-reload|enable-updates|disable-updates}" >&2
	exit 3
	;;
esac