Debian Codegraph @

sbin/drbl-aoe-serv

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: Program to start service for AoE images on DRBL server.
5
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9 [scip-shell system . . `[`. -e /etc/drbl/drbl-ocs.confscip-shell filesystem . . `/etc/drbl/drbl-ocs.conf`. ] && . /etc/drbl/drbl-ocs.confscip-shell source . . `/etc/drbl/drbl-ocs.conf`.
10 [scip-shell system . . `[`. -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
11
12 #
13 prog="$(basenamescip-shell system . . basename. $0)"
14 #
15 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
16 echoscip-shell system . . echo. "Usage: $prog [OPTION] {start|stop|restart|status}"
17 echoscip-shell system . . echo. "-d, --img-dir DIR Scan the AoE image directory DIR when starting"
18 echoscip-shell system . . echo. "Ex:"
19 echoscip-shell system . . echo. "To start AoE service for images in default image dir $sanboot_img_dump_dir:"
20 echoscip-shell system . . echo. " $prog start"
21 echoscip-shell system . . echo. "To start AoE service for images in /work/img/:"
22 echoscip-shell system . . echo. " $prog -d /work/img/ start"
23 echoscip-shell system . . echo. "To start AoE service for images in /work/img1/ and /work/img2/:"
24 echoscip-shell system . . echo. " $prog -d \"/work/img1/ /work/img2/\" start"
25 echoscip-shell system . . echo. "To stop AoE service:"
26 echoscip-shell system . . echo. " $prog stop"
27 }
28 #
29 startscip-shell shell shell-project 0.0.0 start().() {
30 if ! type vblade &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
31 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
32 echoscip-shell system . . echo. "vblade not found!"
33 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
34 echoscip-shell system . . echo. "$msg_program_stop!!"
35 fi
36 sys_eth_ports="$(LC_ALL=C get-all-nic-ip --drbl-client-eth-port)"
37 IP_MAC_TMP="$(mktempscip-shell system . . mktemp. /tmp/ip_mac_tmp.XXXXXXscip-shell filesystem . . `/tmp/ip_mac_tmp.XXXXXX`.)"
38 trap "[ -f "$IP_MAC_TMP" ] && rm -f $IP_MAC_TMP" HUP INT QUIT TERM EXIT
39 parse_dhcpd_conf $IP_MAC_TMP
40 # The output of parse_dhcpd_confi is like:
41 # hostname IP ADD MAC ADD
42 # debian101 192.168.61.1 00:02:e3:53:34:30
43 # debian102 192.168.61.2 00:02:e3:54:73:39
44
45 # image name is like: sanboot.aoe-0-0-for-00-50-56-02-01-02
46 echoscip-shell system . . echo. "The AoE image dir: $aoe_img_dir"
47 for img_dir in $aoe_img_dir; do
48 for i in $img_dir/*.aoe-*; do
49 if [scip-shell system . . `[`. ! -e "$i" ]; then
50 echoscip-shell system . . echo. "$i is not a normal file. Skip this."
51 continue
52 fi
53 # If the filename is not the format, skip it
54 if [scip-shell system . . `[`. -z "$(basenamescip-shell system . . basename. $i | grepscip-shell system . . grep. -E "for-([[:alnum:]]+-){5}[[:alnum:]]+$")" ]; then
55 echoscip-shell system . . echo. "$i is not in DRBL AoE image file name format. Skip this."
56 continue
57 fi
58 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
59 echoscip-shell system . . echo. "AoE image found: $i"
60 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
61 shelf_no="$(echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -Eo "aoe-[[:digit:]]+-[[:digit:]]+-for-.*" | awkscip-shell system . . awk. -F'-' '{print $2}')"
62 slot_no="$(echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -Eo "aoe-[[:digit:]]+-[[:digit:]]+-for-.*" | awkscip-shell system . . awk. -F'-' '{print $3}')"
63 mac_address_dash="$(echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -Eo "aoe-[[:digit:]]+-[[:digit:]]+-for-.*" | sedscip-shell system . . sed. -e 's/^aoe-.*-for-//g')"
64 mac_address_normal="$(echoscip-shell system . . echo. $mac_address_dash | sedscip-shell system . . sed. -e 's/-/:/g')"
65 mac_name_cfg_for_pxe="01-${mac_address_dash}"
66 echoscip-shell system . . echo. "Checking if vblade service for aoe:e${shelf_no}.${slot_no} is running..."
67 ps_status="$(psscip-shell system . . ps. -ef | grepscip-shell system . . grep. -Ew "vblade[[:space:]]+${shelf_no}[[:space:]]+${slot_no}" | grepscip-shell system . . grep. -v "grep")"
68 if [scip-shell system . . `[`. -n "$ps_status" ]; then
69 echoscip-shell system . . echo. "vblade service for aoe.e${shelf_no}.${slot_no} is running. Skip this one"
70 continue
71 fi
72 # Find the right eth port instead of running on all. This can be done by parsing the dhcpd.conf if MAC addresses are used in dhcpd.conf.
73 client_ip="$(grepscip-shell system . . grep. -iEw "$mac_address_normal" $IP_MAC_TMP | awkscip-shell system . . awk. -F' ' '{print $2}')"
74 if [scip-shell system . . `[`. -n "$client_ip" ]; then
75 # We can find the IP address from dhcpd.conf
76 # The output of "ip route get 192.168.205.10" is like:
77 # 192.168.205.10 dev eth2 src 192.168.205.254
78 eth_ports_list="$(ip route get $client_ip | grepscip-shell system . . grep. -iEo 'dev[[:space:]]+.*src' | awkscip-shell system . . awk. -F' ' '{print $2}')"
79 echoscip-shell system . . echo. "This server uses ethernet port $eth_ports_list to connect client $mac_address_normal"
80 else
81 # "range" is used in dhcpd.conf, we have to run vblade on all the available ether port except uplink port.
82 eth_ports_list="$sys_eth_ports"
83 echoscip-shell system . . echo. "No idea which ethernet port on the server connects to client $mac_address_normal. Running virtual blade on all available ethernet ports except uplink port..."
84 fi
85
86 if [scip-shell system . . `[`. -z "$eth_ports_list" ]; then
87 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
88 echoscip-shell system . . echo. "No ethernet port on the server connecting to client $mac_address_normal was found!"
89 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
90 echoscip-shell system . . echo. "$msg_program_stop!!"
91 fi
92 echoscip-shell system . . echo. -n "Starting virtual blade for ${i##*/} on "
93 for j in $eth_ports_list; do
94 echoscip-shell system . . echo. -n "$j, "
95 vbladed ${shelf_no} ${slot_no} $j $i
96 rc=$?
97 if [scip-shell system . . `[`. "$rc" -gt 0 ]; then
98 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
99 echoscip-shell system . . echo. "Error when starting vbladed by: vbladed ${shelf_no} ${slot_no} $j $i"
100 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
101 continue
102 fi
103 done
104 echoscip-shell system . . echo.
105
106 # Set pxelinux config file
107 cpscip-shell system . . cp. -f $PXE_CONF_DEF $PXELINUX_DIR/$mac_name_cfg_for_pxe
108 hide_reveal_pxe_img "AoE-client" reveal $PXELINUX_DIR/$mac_name_cfg_for_pxe
109 set-default-pxe-img -i "AoE-client" -c $PXELINUX_DIR/$mac_name_cfg_for_pxe
110 # Change the line: append aoe:e0.0
111 drbl-tune-pxecfg-block AoE-client "^([[:space:]]*)append aoe:.*" "\$1append aoe:e${shelf_no}.${slot_no}" $PXELINUX_DIR/$mac_name_cfg_for_pxe
112 done
113 done
114 [scip-shell system . . `[`. -e "$IP_MAC_TMP" ] && rmscip-shell system . . rm. -f $IP_MAC_TMP
115
116 # Use gpxelinux.0 instead of pxelinux.0 in dhcpd.conf
117 if ! grepscip-shell system . . grep. -iEq '^[[:space:]]*filename[[:space:]]*=[[:space:]]*[\"]*gpxelinux.0[\"]*' $DHCPDCONF_DIR/dhcpd.conf; then
118 echoscip-shell system . . echo. "Use gpxelinux.0 instead of pxelinux.0 in dhcpd.conf..."
119 perlscip-shell system . . perl. -pi -e 's|(^filename[[:space:]]*=[[:space:]]*"*pxelinux.0"*.*)|#$1|g' $DHCPDCONF_DIR/dhcpd.conf
120 perlscip-shell system . . perl. -pi -e 's|(^[#]*[[:space:]]*filename[[:space:]]*=[[:space:]]*"*gpxelinux.0"*.*)|filename = "gpxelinux.0";|g' $DHCPDCONF_DIR/dhcpd.conf
121 # Restart dhcpd service, since different distributions have different names
122 for serv_st in dhcpd isc-dhcp-server dhcp3-server; do
123 [scip-shell system . . `[`. -e "/etc/init.d/$serv_st" ] && /etc/init.d/$scip-shell filesystem . . `/etc/init.d/$serv_st`.serv_st restart
124 done
125 fi
126 } # end of start
127
128 stopscip-shell shell shell-project 0.0.0 stop().() {
129 local pxe_mac_files
130 echoscip-shell system . . echo. -n "Stopping vblade process... "
131 pkillscip-shell system . . pkill. -9 vblade
132 echoscip-shell system . . echo. "done!"
133 #
134 for i in $PXELINUX_DIR/01-*; do
135 [scip-shell system . . `[`. -e "$i" ] && pxe_mac_files="$pxe_mac_files $(basenamescip-shell system . . basename. $i)"
136 done
137 # Remove spaces in the line head
138 pxe_mac_files="$(echoscip-shell system . . echo. $pxe_mac_files | sedscip-shell system . . sed. -e "s/^[[:space:]]*//g")"
139 if [scip-shell system . . `[`. -n "$pxe_mac_files" ]; then
140 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
141 echoscip-shell system . . echo. "The pxelinux config files used for AoE clients in dir $PXELINUX_DIR/ are: ${pxe_mac_files// /, }"
142 echoscip-shell system . . echo. "Do you want to remove them now ?"
143 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
144 echoscip-shell system . . echo. -n "[Y/n] "
145 read ans_rm_pxelinux_cfg
146 case "$ans_rm_pxelinux_cfg" in
147 n|N|[nN][oO]) truescip-shell system . . true. ;;
148 *)
149 for i in $pxe_mac_files; do
150 rmscip-shell system . . rm. -fv $PXELINUX_DIR/$i
151 done
152 ;;
153 esac
154 fi
155 # Ask if want to use gpxelinux.0 instead of pxelinux.0 in dhcpd.conf
156 if grepscip-shell system . . grep. -iEq '^[[:space:]]*filename[[:space:]]*=[[:space:]]*[\"]*gpxelinux.0[\"]*' $DHCPDCONF_DIR/dhcpd.conf; then
157 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
158 echoscip-shell system . . echo. "Since AoE booting service was stopped. Do you want to use pxelinux.0 instead of gpxelinux.0 in your dhcpd.conf ?"
159 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
160 echoscip-shell system . . echo. -n "[Y/n] "
161 read ans_use_pxelinux_0
162 case "$ans_use_pxelinux_0" in
163 n|N|[nN][oO]) truescip-shell system . . true. ;;
164 *)
165 echoscip-shell system . . echo. "Use pxelinux.0 instead of gpxelinux.0 in dhcpd.conf..."
166 perlscip-shell system . . perl. -pi -e 's|(^[#]*[[:space:]]*filename[[:space:]]*=[[:space:]]*"*pxelinux.0"*.*)|filename = "pxelinux.0";|g' $DHCPDCONF_DIR/dhcpd.conf
167 perlscip-shell system . . perl. -pi -e 's|(^filename[[:space:]]*=[[:space:]]*"*gpxelinux.0"*.*)|#$1|g' $DHCPDCONF_DIR/dhcpd.conf
168 # Restart dhcpd service, since different distributions have different names
169 for serv_st in dhcpd isc-dhcp-server dhcp3-server; do
170 [scip-shell system . . `[`. -e "/etc/init.d/$serv_st" ] && /etc/init.d/$scip-shell filesystem . . `/etc/init.d/$serv_st`.serv_st restart
171 done
172 ;;
173 esac
174 fi
175 } # end of stop
176
177 #
178 restartscip-shell shell shell-project 0.0.0 restart().() {
179 stopscip-shell shell shell-project 0.0.0 stop().
180 echoscip-shell system . . echo. -n "Wait for 2 secs..."
181 sleepscip-shell system . . sleep. 2
182 echoscip-shell system . . echo.
183 startscip-shell shell shell-project 0.0.0 start().
184 }
185
186 statusscip-shell shell shell-project 0.0.0 status().() {
187 psscip-shell system . . ps. -efw | grepscip-shell system . . grep. -iE "vblade [[:digit:]]+ [[:digit:]]+"
188 }
189
190 ##############
191 #### main ####
192 ##############
193 #
194 while [scip-shell system . . `[`. $# -gt 0 ]; do
195 case "$1" in
196 -d|--img-dir)
197 shift
198 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
199 # skip the -xx option, in case
200 aoe_img_dir="$1"
201 shift
202 fi
203 ;;
204 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
205 USAGEscip-shell shell shell-project 0.0.0 USAGE(). >& 2
206 exit 2 ;;
207 *) break ;;
208 esac
209 done
210 #
211 [scip-shell system . . `[`. -z "$aoe_img_dir" ] && aoe_img_dir="$sanboot_img_dump_dir"
212
213 #
214 ask_and_load_lang_set
215
216 #
217 case $1 in
218 start) startscip-shell shell shell-project 0.0.0 start().;;
219 stop) stopscip-shell shell shell-project 0.0.0 stop().;;
220 restart) restartscip-shell shell shell-project 0.0.0 restart().;;
221 status) statusscip-shell shell shell-project 0.0.0 status().;;
222 *) echoscip-shell system . . echo. "Usage: $0 {start|stop|restart|status}"
223 exit 1
224 esac