Magellan Linux

Contents of /branches/magellan-next/include/mtools.minc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations) (download)
Thu Jun 2 18:01:44 2011 UTC (12 years, 11 months ago) by niro
File size: 5586 byte(s)
-fixed a logic error
1 # $Header: /magellan-cvs/mage/include/mtools.minc,v 1.3 2008/02/10 12:13:56 niro Exp $
2
3 # adds services to runlevels and starts them
4 # mstartservice service {/path/to/service_exec}
5 mstartservice()
6 {
7 local service="$1"
8 local service_exec="$2"
9
10 [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
11
12 # add service to default runlevels
13 echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."
14 [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null
15
16 # do not start services on bootstrap or MROOT!=/
17 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
18 then
19 # start service
20 if [[ -n $(pidof ${service_exec}) ]]
21 then
22 # restart service
23 /etc/init.d/${service} restart
24 else
25 # start service
26 /etc/init.d/${service} start
27 fi
28 fi
29 }
30
31 # removes services from runlevels and stops them
32 # mstopservice service {/path/to/service_exec}
33 mstopservice()
34 {
35 local service="$1"
36 local service_exec="$2"
37
38 [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
39
40 # only stop the service if ${service_exec} does not exist
41 [[ -f ${MROOT}/${service_exec} ]] && return
42
43 # del services from runlevel regardless if they exist or not
44 echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."
45 rc-config del ${service} &> /dev/null
46
47 # do not stop services on bootstrap or MROOT!=/
48 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
49 then
50 # stop service if running
51 if [[ -n $(pidof ${service_exec}) ]]
52 then
53 killall -15 ${service_exec} &> /dev/null
54 sleep 1
55 killall -9 ${service_exec} &> /dev/null
56 fi
57 fi
58 }
59
60 # reloads a service if already running
61 # mreloadservice service {/path/to/service_exec}
62 mreloadservice()
63 {
64 local service="$1"
65 local service_exec="$2"
66
67 [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
68
69 # do not stop services on bootstrap or MROOT!=/
70 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
71 then
72 # only reload the service if running
73 if [[ -n $(pidof ${service_exec}) ]]
74 then
75 /etc/init.d/${service} reload
76 fi
77 fi
78 }
79
80
81 # adds systemd units to runlevels and starts them
82 # mstartunit service {/path/to/service_exec}
83 mstartunit()
84 {
85 local service="$1"
86 local service_exec="$2"
87
88 # only run if systemd was found
89 if [[ ! -x /bin/systemctl ]]
90 then
91 echo "systemd not found, not adding unit ${service} to runlevels!"
92 return
93 fi
94
95 # we do not support $MROOT atm
96 if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
97 then
98 echo "\$MROOT is set, doing nothing!"
99 echo "Please add unit ${service} manually to the runlevels!"
100 echo "Run 'systemctl enable ${service}' in your chroot later on."
101 return
102 fi
103
104 [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
105
106 # add service to default runlevels
107 echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
108 # reload daemon to honor changed unit files
109 systemctl daemon-reload
110 systemctl enable ${service}
111
112 # do not start services on bootstrap or MROOT!=/
113 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
114 then
115 # start or restart the service
116 systemctl try-restart ${service}
117 fi
118 }
119
120 # removes systemd units from runlevels and stops them
121 # mstopunit service {/path/to/service_exec}
122 mstopunit()
123 {
124 local service="$1"
125 local service_exec="$2"
126
127 # only run if systemd was found
128 if [[ ! -x /bin/systemctl ]]
129 then
130 echo "systemd not found, not removing unit ${service} from runlevels!"
131 return
132 fi
133
134 # we do not support $MROOT atm
135 if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
136 then
137 echo "\$MROOT is set, doing nothing!"
138 echo "Please remove unit ${service} manually from the runlevels!"
139 echo "Run 'systemctl disable ${service}' in your chroot later on."
140 return
141 fi
142
143 [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
144
145 # only stop the service if ${service_exec} does not exist
146 [[ -f ${MROOT}/${service_exec} ]] && return
147
148 # del services from runlevel regardless if they exist or not
149 echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
150 # reload daemon to honor changed unit files
151 systemctl daemon-reload
152 systemctl disable ${service}
153
154 # do not stop services on bootstrap or MROOT!=/
155 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
156 then
157 systemctl stop ${service}
158 # try harder
159 if [[ -n $(pidof ${service_exec}) ]]
160 then
161 killall -15 ${service_exec} &> /dev/null
162 sleep 1
163 killall -9 ${service_exec} &> /dev/null
164 fi
165 fi
166 }
167
168 # reloads a systemd unit if already running
169 # mreloadunit service {/path/to/service_exec}
170 mreloadunit()
171 {
172 local service="$1"
173 local service_exec="$2"
174
175 # only run if systemd was found
176 if [[ ! -x /bin/systemctl ]]
177 then
178 echo "systemd not found, not removing unit ${service} from runlevels!"
179 return
180 fi
181
182 # we do not support $MROOT atm
183 if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
184 then
185 echo "\$MROOT is set, doing nothing!"
186 echo "Please remove unit ${service} manually from the runlevels!"
187 echo "Run 'systemctl disable ${service}' in your chroot later on."
188 return
189 fi
190
191 [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
192
193 # do not stop services on bootstrap or MROOT!=/
194 if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
195 then
196 # only reload the service if running
197 systemctl reload-or-try-restart ${service}
198 fi
199 }