File: drbl-client-service

package info (click to toggle)
drbl 5.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,996 kB
  • sloc: sh: 43,555; perl: 8,820; xml: 867; makefile: 135
file content (217 lines) | stat: -rwxr-xr-x 7,277 bytes parent folder | download | duplicates (4)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# Written by Steven Shiau <steven@nchc.org.tw> to use in DRBL for RedHat
# License: GPL

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

USAGE() {
     echo "Usage: $0 Options SERVICE_NAME {on|off|reset|add|del|list}"
     echo " Options:"
     echo " -h, --host IP_ADDRESS:  set only for the host with IP_ADDRESS instead of all DRBL clients"
     echo " -g, --no-gen-ssi Do NOT generate DRBL SSI template tarball."
     echo " Example: use the following to turn on the DRBL clients' kudzu"
     echo " $0 kudzu on"
}

# main
check_if_root

# 
unalias ls 2>/dev/null

while [ $# -gt 0 ]; do
  case "$1" in
    -h|--host)
		shift; specified_host="$1"
		shift
                ;;
    -g|--no-gen-ssi)
		gen_ssi="no"
                shift;;
    -*)		echo "${0}: ${1}: invalid option" >&2
		USAGE >& 2
		exit 2 ;;
    *)		break ;;
  esac
done

service=$1
switch=$2

[ -z "${service}" ] && USAGE && exit 1
[ -z "$switch" ] && USAGE && exit 1

#
if [ -n "$specified_host" ]; then
 [ ! -d "$drblroot/$specified_host" ] && echo "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Program terminated!" && exit 1
 [ -n "$verbose" ] && echo "specified_host: $specified_host"
fi

# set the host to be processed
# host_list is the IP address of client, like 192.168.1.1...
host_list=""
if [ -n "$specified_host" ]; then
   # set the host path
   host_list=$drblroot/$specified_host
else
   # withoud specified_host, it must be all clients, append each one to $host_list
   for ihost in $drblroot/*; do
     host_list="$host_list $ihost"
   done
fi

#
for ihost in $host_list; do
  case "$switch" in
  on)
     echo "Turning on the service \"${service}\" for DRBL client `basename $ihost`..."
     if is_systemd_init; then
       if [ -e "$drbl_common_root/lib/systemd/system/${service}.service" ]; then
         # systemctl can't work in chroot environment :`chroot $drbl_common_root/ /sbin/chkconfig --add $i`
         # Therefore manually link it:
         _systemctl_target=$(grep -e "^WantedBy=" $drbl_common_root/lib/systemd/system/${service}.service | sed -e "s/WantedBy=//")
         if [ ! -z "$_systemctl_target" ]; then
           echo "to target: '$_systemctl_target'";
           for ti in $_systemctl_target; do
             ln -s -v /lib/systemd/system/${service}.service $ihost/etc/systemd/system/$ti.wants/${service}.service
           done
         else
           echo "Skip ...";
         fi
       fi
     elif [ -e /etc/debian_version ]; then
       # Debian-like
       get_debian_ubuntu_init_serv_control_prog
       # prepare the update-rc.d env, perl is necessary for update-rc.d
       prepare_update_rc_d_env $ihost
       if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
         # Use insserv
         chroot $ihost/ insserv ${service} &> /dev/null
       else
         # Use update-rc.d
         chroot $ihost/ /usr/sbin/update-rc.d ${service} defaults &> /dev/null
       fi
       #clean_update_rc_d_env $ihost
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       create_insserv_env $ihost
       chroot $ihost/ /sbin/insserv -f ${service}
     else
       # RH-like
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig ${service} on
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  off)
     echo "Turning off the service \"${service}\" for DRBL client `basename $ihost`..."
     if is_systemd_init; then
       if [ -e "$drbl_common_root/lib/systemd/system/${service}.service" ]; then
         # systemctl can't work in chroot environment :`chroot $drbl_common_root/ /sbin/chkconfig --add $i`
         # Therefore manually link it:
         _systemctl_target=$(grep -e "^WantedBy=" $drbl_common_root/lib/systemd/system/${service}.service | sed -e "s/WantedBy=//")
         if [ ! -z "$_systemctl_target" ]; then
           echo "to target: '$_systemctl_target'";
           for ti in $_systemctl_target; do
             rm -fv $ihost/etc/systemd/system/$ti.wants/${service}.service
           done
         else
           echo "Skip ...";
         fi
       fi
     elif [ -e /etc/debian_version ]; then
       # Debian-like
       get_debian_ubuntu_init_serv_control_prog
       # prepare the update-rc.d env, perl is necessary for update-rc.d
       prepare_update_rc_d_env $ihost
       if [ "$dbn_ubn_serv_control_prog" = "use-insserv" ]; then
         # Use insserv
         chroot $ihost/ insserv -r ${service} &> /dev/null
       else
         # Use update-rc.d
         chroot $ihost/ /usr/sbin/update-rc.d -f ${service} remove &> /dev/null
       fi
       #clean_update_rc_d_env $ihost
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       create_insserv_env $ihost
       chroot $ihost/ /sbin/insserv -f -r ${service}
     else
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig ${service} off
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  reset)
     echo "Resetting the service \"${service}\" for DRBL client `basename $ihost`..."
     if [ -e /etc/debian_version ]; then
       echo "Reset service in DRBL clients is not supported! Sorry!"
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       echo "Reset service in DRBL clients is not supported! Sorry!"
     else
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig ${service} reset
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  add)
     echo "Adding the service \"${service}\" for DRBL client `basename $ihost`..."
     if [ -e /etc/debian_version ]; then
       echo "Add service for DRBL clients in not supported! Sorry!"
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       echo "Add service for DRBL clients in not supported! Sorry!"
     else
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig --add ${service}
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  del)
     echo "Deleting the service \"${service}\" for DRBL client `basename $ihost`..."
     if [ -e /etc/debian_version ]; then
       echo "Reset service in DRBL clients is not supported! Sorry!"
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       echo "Reset service in DRBL clients is not supported! Sorry!"
     else
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig --del ${service}
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  list)
     echo "Listing the service \"${service}\" for DRBL client `basename $ihost`..."
     if [ -e /etc/debian_version ]; then
       echo "Reset service in DRBL clients is not supported! Sorry!"
     elif [ -e /etc/SuSE-release ]; then
       # SuSE
       echo "Reset service in DRBL clients is not supported! Sorry!"
     else
       create_chkconfig_env $ihost
       chroot $ihost/ /sbin/chkconfig --list ${service}
       #clean_chkconfig_env $ihost
       echo "done!"
     fi
     ;;
  *)
     USAGE
     exit 1
  esac
done

#
if [ "$gen_ssi" != "no" ]; then
  echo "-------------------------------------------------------"
  echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
  drbl-gen-ssi-files
fi