author | Tero Marttila <tero.marttila@aalto.fi> |
Tue, 03 Mar 2015 12:09:22 +0200 | |
changeset 715 | 76ed62924d50 |
parent 701 | 8ddc141af313 |
child 719 | 4ddebf1d754a |
permissions | -rw-r--r-- |
632 | 1 |
DHCP_SBIN=/usr/sbin/dhcpd |
2 |
DHCP_CONF=/etc/dhcp/dhcpd.conf |
|
3 |
DHCP_SERVICE=isc-dhcp-server |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
4 |
|
662
4750b8b85aa1
lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents:
632
diff
changeset
|
5 |
# absolute path! |
4750b8b85aa1
lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents:
632
diff
changeset
|
6 |
DHCP_INCLUDE="$SRV/var/dhcp" |
4750b8b85aa1
lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents:
632
diff
changeset
|
7 |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
8 |
## Generate DHCP hosts config from hosts hosts using pvl.hosts-dhcp |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
9 |
# |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
10 |
# update_hosts_dhcpe $out $src |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
11 |
function update_hosts_dhcp { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
12 |
local out="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
13 |
local src="$2" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
14 |
local msg="$out: Generating DHCP hosts: $src" |
715
76ed62924d50
lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents:
701
diff
changeset
|
15 |
local include_cache=$(include_cache_path $src) |
76ed62924d50
lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents:
701
diff
changeset
|
16 |
local srcs=($(include_cache $include_cache)) |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
17 |
|
715
76ed62924d50
lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents:
701
diff
changeset
|
18 |
if apply_check "$out" ${srcs[@]:-}; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
19 |
log_skip "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
20 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
21 |
log_apply "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
22 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
23 |
apply_cmd "$out" $OPT/bin/pvl.hosts-dhcp \ |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
24 |
--hosts-include="$HOSTS_INCLUDE" \ |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
25 |
"$src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
26 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
27 |
} |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
28 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
29 |
## Generate dhcp confs from source using pvl.dhcp-conf: |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
30 |
function update_dhcp_conf { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
31 |
local out="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
32 |
local src="$2" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
33 |
local msg="$out: Generating DHCP conf: $src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
34 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
35 |
if apply_check "$out" "$src"; then |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
36 |
log_skip "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
37 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
38 |
log_apply "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
39 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
40 |
apply_cmd "$out" $OPT/bin/pvl.dhcp-conf \ |
662
4750b8b85aa1
lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents:
632
diff
changeset
|
41 |
--include-path=$DHCP_INCLUDE \ |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
42 |
"$src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
43 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
44 |
} |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
45 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
46 |
## Test DHCP configuration for validity using dhcpd -t: |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
47 |
# |
701
8ddc141af313
update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents:
664
diff
changeset
|
48 |
# check_dhcp |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
49 |
# |
701
8ddc141af313
update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents:
664
diff
changeset
|
50 |
# Uses the global $DHCPD_CONF, |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
51 |
function test_dhcp { |
632 | 52 |
if [ ! -e "$DHCP_SBIN" ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
53 |
log_warn "check_dhcp: dhcpd not installed, skipping: $conf" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
54 |
return 0 |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
55 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
56 |
|
701
8ddc141af313
update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents:
664
diff
changeset
|
57 |
log_check "Checking DHCP: $DHCP_CONF" |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
58 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
59 |
test_cmd "$conf" \ |
701
8ddc141af313
update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents:
664
diff
changeset
|
60 |
"$DHCP_SBIN" -cf "$DHCP_CONF" -t |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
61 |
} |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
62 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
63 |
## Reload dhcp hosts |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
64 |
# |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
65 |
# reload_dhcp |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
66 |
# |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
67 |
# noop's if we haven't reloaded zones |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
68 |
function reload_dhcp { |
629 | 69 |
if [ "$UPDATE_RELOAD" = 1 ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
70 |
log_force "Reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
71 |
|
629 | 72 |
elif [ "$UPDATE_RELOAD" = 0 ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
73 |
log_noop "Skip reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
74 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
75 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
76 |
|
632 | 77 |
elif [ ! -e "$DHCP_SBIN" ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
78 |
warn "Skip missing DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
79 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
80 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
81 |
|
632 | 82 |
elif ! service_status $DHCP_SERVICE; then |
83 |
log_skip "dhcpd not running; did not restart" |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
84 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
85 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
86 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
87 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
88 |
log_apply "Reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
89 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
90 |
|
632 | 91 |
service_restart $DHCP_SERVICE |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
92 |
} |