author | Tero Marttila <tero.marttila@aalto.fi> |
Mon, 02 Mar 2015 20:02:14 +0200 | |
changeset 701 | 8ddc141af313 |
parent 664 | 10ac59f9d4e7 |
child 715 | 76ed62924d50 |
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" |
664
10ac59f9d4e7
lib/pvl pvl/hosts/update.sh: handle either file or directory based dhcp/hosts, zones/forward, zones/reverse sources
Tero Marttila <terom@paivola.fi>
parents:
662
diff
changeset
|
14 |
local srcs=($(list_tree $src)) |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
15 |
local msg="$out: Generating DHCP hosts: $src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
16 |
|
664
10ac59f9d4e7
lib/pvl pvl/hosts/update.sh: handle either file or directory based dhcp/hosts, zones/forward, zones/reverse sources
Tero Marttila <terom@paivola.fi>
parents:
662
diff
changeset
|
17 |
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
|
18 |
log_skip "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
19 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
20 |
log_apply "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
21 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
22 |
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
|
23 |
--hosts-include="$HOSTS_INCLUDE" \ |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
24 |
"$src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
25 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
26 |
} |
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 |
## 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
|
29 |
function update_dhcp_conf { |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
30 |
local out="$1" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
31 |
local src="$2" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
32 |
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
|
33 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
34 |
if apply_check "$out" "$src"; then |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
35 |
log_skip "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
36 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
37 |
log_apply "$msg" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
38 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
39 |
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
|
40 |
--include-path=$DHCP_INCLUDE \ |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
41 |
"$src" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
42 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
43 |
} |
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 |
## 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
|
46 |
# |
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
|
47 |
# check_dhcp |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
48 |
# |
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
|
49 |
# Uses the global $DHCPD_CONF, |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
50 |
function test_dhcp { |
632 | 51 |
if [ ! -e "$DHCP_SBIN" ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
52 |
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
|
53 |
return 0 |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
54 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
55 |
|
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
|
56 |
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
|
57 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
58 |
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
|
59 |
"$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
|
60 |
} |
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 |
## Reload dhcp hosts |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
63 |
# |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
64 |
# reload_dhcp |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
65 |
# |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
66 |
# 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
|
67 |
function reload_dhcp { |
629 | 68 |
if [ "$UPDATE_RELOAD" = 1 ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
69 |
log_force "Reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
70 |
|
629 | 71 |
elif [ "$UPDATE_RELOAD" = 0 ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
72 |
log_noop "Skip reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
73 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
74 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
75 |
|
632 | 76 |
elif [ ! -e "$DHCP_SBIN" ]; then |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
77 |
warn "Skip missing DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
78 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
79 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
80 |
|
632 | 81 |
elif ! service_status $DHCP_SERVICE; then |
82 |
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
|
83 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
84 |
return |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
85 |
|
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
86 |
else |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
87 |
log_apply "Reload DHCP" |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
88 |
fi |
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
89 |
|
632 | 90 |
service_restart $DHCP_SERVICE |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff
changeset
|
91 |
} |