Debian Codegraph @

sbin/drbl-client-service

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Written by Steven Shiau <[email protected]> to use in DRBL for RedHat
3 # License: GPL
4
5 # Load DRBL setting and functions
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9
10 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
11 echoscip-shell system . . echo. "Usage: $0 Options SERVICE_NAME {on|off|reset|add|del|list}"
12 echoscip-shell system . . echo. " Options:"
13 echoscip-shell system . . echo. " -h, --host IP_ADDRESS: set only for the host with IP_ADDRESS instead of all DRBL clients"
14 echoscip-shell system . . echo. " -g, --no-gen-ssi Do NOT generate DRBL SSI template tarball."
15 echoscip-shell system . . echo. " Example: use the following to turn on the DRBL clients' kudzu"
16 echoscip-shell system . . echo. " $0 kudzu on"
17 }
18
19 # main
20 check_if_root
21
22 #
23 unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.
24
25 while [scip-shell system . . `[`. $# -gt 0 ]; do
26 case "$1" in
27 -h|--host)
28 shift; specified_host="$1"
29 shift
30 ;;
31 -g|--no-gen-ssi)
32 gen_ssi="no"
33 shift;;
34 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
35 USAGEscip-shell shell shell-project 0.0.0 USAGE(). >& 2
36 exit 2 ;;
37 *) break ;;
38 esac
39 done
40
41 service=$1
42 switch=$2
43
44 [scip-shell system . . `[`. -z "${service}" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
45 [scip-shell system . . `[`. -z "$switch" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
46
47 #
48 if [scip-shell system . . `[`. -n "$specified_host" ]; then
49 [scip-shell system . . `[`. ! -d "$drblroot/$specified_host" ] && echoscip-shell system . . echo. "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Program terminated!" && exit 1
50 [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "specified_host: $specified_host"
51 fi
52
53 # set the host to be processed
54 # host_list is the IP address of client, like 192.168.1.1...
55 host_list=""
56 if [scip-shell system . . `[`. -n "$specified_host" ]; then
57 # set the host path
58 host_list=$drblroot/$specified_host
59 else
60 # withoud specified_host, it must be all clients, append each one to $host_list
61 for ihost in $drblroot/*; do
62 host_list="$host_list $ihost"
63 done
64 fi
65
66 #
67 for ihost in $host_list; do
68 case "$switch" in
69 on)
70 echoscip-shell system . . echo. "Turning on the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
71 if is_systemd_init; then
72 if [scip-shell system . . `[`. -e "$drbl_common_root/lib/systemd/system/${service}.service" ]; then
73 # systemctl can't work in chroot environment :`chroot $drbl_common_root/ /sbin/chkconfig --add $i`
74 # Therefore manually link it:
75 _systemctl_target=$(grepscip-shell system . . grep. -e "^WantedBy=" $drbl_common_root/lib/systemd/system/${service}.service | sedscip-shell system . . sed. -e "s/WantedBy=//")
76 if [scip-shell system . . `[`. ! -z "$_systemctl_target" ]; then
77 echoscip-shell system . . echo. "to target: '$_systemctl_target'";
78 for ti in $_systemctl_target; do
79 lnscip-shell system . . ln. -s -v /lib/systemd/system/${service}.service $ihost/etc/systemd/system/$ti.wants/${service}.service
80 done
81 else
82 echoscip-shell system . . echo. "Skip ...";
83 fi
84 fi
85 elif [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
86 # Debian-like
87 get_debian_ubuntu_init_serv_control_prog
88 # prepare the update-rc.d env, perl is necessary for update-rc.d
89 prepare_update_rc_d_env $ihost
90 if [scip-shell system . . `[`. "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
91 # Use insserv
92 chrootscip-shell system . . chroot. $ihost/ insserv ${service} &> /dev/nullscip-shell filesystem . . `/dev/null`.
93 else
94 # Use update-rc.d
95 chrootscip-shell system . . chroot. $ihost/ /usr/sbin/update-rc.dscip-shell filesystem . . `/usr/sbin/update-rc.d`. ${service} defaults &> /dev/nullscip-shell filesystem . . `/dev/null`.
96 fi
97 #clean_update_rc_d_env $ihost
98 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
99 # SuSE
100 create_insserv_env $ihost
101 chrootscip-shell system . . chroot. $ihost/ /sbin/insservscip-shell filesystem . . `/sbin/insserv`. -f ${service}
102 else
103 # RH-like
104 create_chkconfig_env $ihost
105 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. ${service} on
106 #clean_chkconfig_env $ihost
107 echoscip-shell system . . echo. "done!"
108 fi
109 ;;
110 off)
111 echoscip-shell system . . echo. "Turning off the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
112 if is_systemd_init; then
113 if [scip-shell system . . `[`. -e "$drbl_common_root/lib/systemd/system/${service}.service" ]; then
114 # systemctl can't work in chroot environment :`chroot $drbl_common_root/ /sbin/chkconfig --add $i`
115 # Therefore manually link it:
116 _systemctl_target=$(grepscip-shell system . . grep. -e "^WantedBy=" $drbl_common_root/lib/systemd/system/${service}.service | sedscip-shell system . . sed. -e "s/WantedBy=//")
117 if [scip-shell system . . `[`. ! -z "$_systemctl_target" ]; then
118 echoscip-shell system . . echo. "to target: '$_systemctl_target'";
119 for ti in $_systemctl_target; do
120 rmscip-shell system . . rm. -fv $ihost/etc/systemd/system/$ti.wants/${service}.service
121 done
122 else
123 echoscip-shell system . . echo. "Skip ...";
124 fi
125 fi
126 elif [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
127 # Debian-like
128 get_debian_ubuntu_init_serv_control_prog
129 # prepare the update-rc.d env, perl is necessary for update-rc.d
130 prepare_update_rc_d_env $ihost
131 if [scip-shell system . . `[`. "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
132 # Use insserv
133 chrootscip-shell system . . chroot. $ihost/ insserv -r ${service} &> /dev/nullscip-shell filesystem . . `/dev/null`.
134 else
135 # Use update-rc.d
136 chrootscip-shell system . . chroot. $ihost/ /usr/sbin/update-rc.dscip-shell filesystem . . `/usr/sbin/update-rc.d`. -f ${service} remove &> /dev/nullscip-shell filesystem . . `/dev/null`.
137 fi
138 #clean_update_rc_d_env $ihost
139 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
140 # SuSE
141 create_insserv_env $ihost
142 chrootscip-shell system . . chroot. $ihost/ /sbin/insservscip-shell filesystem . . `/sbin/insserv`. -f -r ${service}
143 else
144 create_chkconfig_env $ihost
145 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. ${service} off
146 #clean_chkconfig_env $ihost
147 echoscip-shell system . . echo. "done!"
148 fi
149 ;;
150 reset)
151 echoscip-shell system . . echo. "Resetting the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
152 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
153 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
154 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
155 # SuSE
156 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
157 else
158 create_chkconfig_env $ihost
159 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. ${service} reset
160 #clean_chkconfig_env $ihost
161 echoscip-shell system . . echo. "done!"
162 fi
163 ;;
164 add)
165 echoscip-shell system . . echo. "Adding the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
166 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
167 echoscip-shell system . . echo. "Add service for DRBL clients in not supported! Sorry!"
168 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
169 # SuSE
170 echoscip-shell system . . echo. "Add service for DRBL clients in not supported! Sorry!"
171 else
172 create_chkconfig_env $ihost
173 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. --add ${service}
174 #clean_chkconfig_env $ihost
175 echoscip-shell system . . echo. "done!"
176 fi
177 ;;
178 del)
179 echoscip-shell system . . echo. "Deleting the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
180 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
181 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
182 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
183 # SuSE
184 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
185 else
186 create_chkconfig_env $ihost
187 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. --del ${service}
188 #clean_chkconfig_env $ihost
189 echoscip-shell system . . echo. "done!"
190 fi
191 ;;
192 list)
193 echoscip-shell system . . echo. "Listing the service \"${service}\" for DRBL client `basenamescip-shell system . . basename. $ihost`..."
194 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
195 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
196 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
197 # SuSE
198 echoscip-shell system . . echo. "Reset service in DRBL clients is not supported! Sorry!"
199 else
200 create_chkconfig_env $ihost
201 chrootscip-shell system . . chroot. $ihost/ /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. --list ${service}
202 #clean_chkconfig_env $ihost
203 echoscip-shell system . . echo. "done!"
204 fi
205 ;;
206 *)
207 USAGEscip-shell shell shell-project 0.0.0 USAGE().
208 exit 1
209 esac
210 done
211
212 #
213 if [scip-shell system . . `[`. "$gen_ssi" != "no" ]; then
214 echoscip-shell system . . echo. "-------------------------------------------------------"
215 echoscip-shell system . . echo. "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
216 drbl-gen-ssi-files
217 fi