Magellan Linux

Diff of /trunk/include/mtools.minc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/magellan-next/include/mtools.minc revision 20 by niro, Thu Jun 2 21:36:05 2011 UTC trunk/include/mtools.minc revision 63 by niro, Wed Oct 9 12:23:06 2013 UTC
# Line 14  mstartservice() Line 14  mstartservice()
14   return   return
15   fi   fi
16    
17     # don't run if feature !autosvc was set
18     if mqueryfeature "!autosvc"
19     then
20     echo "!autosvc detected; auto management of services disabled."
21     return
22     fi
23    
24   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
25    
26   # add service to default runlevels   # add service to default runlevels
# Line 49  mstopservice() Line 56  mstopservice()
56   return   return
57   fi   fi
58    
59   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   # don't run if feature !autosvc was set
60     if mqueryfeature "!autosvc"
61     then
62     echo "!autosvc detected; auto management of services disabled."
63     return
64     fi
65    
66     if [[ -z ${service_exec} ]]
67     then
68     service_exec="$(which ${service})"
69     elif [[ x$(basename ${service_exec}) = x${service_exec} ]]
70     then
71     # expand full path
72     service_exec="$(which ${service_exec})"
73     fi
74    
75   # only stop the service if ${service_exec} does not exist   # only stop the service if ${service_exec} does not exist
76   [[ -f ${MROOT}/${service_exec} ]] && return   [[ -x ${MROOT}/${service_exec} ]] && return
77    
78   # del services from runlevel regardless if they exist or not   # del services from runlevel regardless if they exist or not
79   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."
# Line 85  mreloadservice() Line 106  mreloadservice()
106   return   return
107   fi   fi
108    
109     # don't run if feature !autosvc was set
110     if mqueryfeature "!autosvc"
111     then
112     echo "!autosvc detected; auto management of services disabled."
113     return
114     fi
115    
116   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
117    
118   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
# Line 98  mreloadservice() Line 126  mreloadservice()
126   fi   fi
127  }  }
128    
   
129  # adds systemd units to runlevels and starts them  # adds systemd units to runlevels and starts them
130  # mstartunit service {/path/to/service_exec}  # mstartunit service {/path/to/service_exec}
131  mstartunit()  mstartunit()
132  {  {
133   local service="$1"   local service="$1"
134   local service_exec="$2"   local service_exec="$2"
135     local opts
136     local chroot
137    
138   # only run if systemd was found   # only run if systemd was found
139   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]]
140   then   then
141   echo "systemd not found, not adding unit ${service} to runlevels!"   echo "systemd not found, not adding unit ${service} to runlevels!"
142   return   return
143   fi   fi
144    
145   # we do not support $MROOT atm   # don't run if feature !autosvc was set
146   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if mqueryfeature "!autosvc"
147   then   then
148   echo "\$MROOT is set, doing nothing!"   echo "!autosvc detected; auto management of services disabled."
  echo "Please add unit ${service} manually to the runlevels!"  
  echo "Run 'systemctl enable ${service}' in your chroot later on."  
149   return   return
150   fi   fi
151    
152     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
153     then
154     # symlinks root path too, not exactly what we want
155     #opts="--root ${MROOT}"
156     if [ -x $(type -P systemd-nspawn) ]
157     then
158     chroot="$(type -P systemd-nspawn)"
159     else
160     chroot="chroot"
161     fi
162     fi
163    
164   if [[ -z ${service_exec} ]]   if [[ -z ${service_exec} ]]
165   then   then
166   case ${service} in   case ${service} in
# Line 136  mstartunit() Line 175  mstartunit()
175   # add service to default runlevels   # add service to default runlevels
176   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
177   # reload daemon to honor changed unit files   # reload daemon to honor changed unit files
178   systemctl daemon-reload   if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
179   systemctl enable ${service}   then
180     systemctl ${opts} daemon-reload
181     fi
182     ${chroot} systemctl ${opts} enable ${service}
183    
184   # do not start services on bootstrap or MROOT!=/   # do not start services on bootstrap or MROOT!=/
185   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
186   then   then
187     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..."
188   # start or restart the service   # start or restart the service
189   systemctl try-restart ${service}   # dont use try-restart, works only with active services!
190     systemctl restart ${service}
191   fi   fi
192  }  }
193    
# Line 153  mstopunit() Line 197  mstopunit()
197  {  {
198   local service="$1"   local service="$1"
199   local service_exec="$2"   local service_exec="$2"
200     local opts
201    
202   # only run if systemd was found   # only run if systemd was found
203   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]]
204   then   then
205   echo "systemd not found, not removing unit ${service} from runlevels!"   echo "systemd not found, not removing unit ${service} from runlevels!"
206   return   return
207   fi   fi
208    
209   # we do not support $MROOT atm   # don't run if feature !autosvc was set
210   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if mqueryfeature "!autosvc"
211   then   then
212   echo "\$MROOT is set, doing nothing!"   echo "!autosvc detected; auto management of services disabled."
  echo "Please remove unit ${service} manually from the runlevels!"  
  echo "Run 'systemctl disable ${service}' in your chroot later on."  
213   return   return
214   fi   fi
215    
216     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
217     then
218     opts="--root ${MROOT}"
219     fi
220    
221   if [[ -z ${service_exec} ]]   if [[ -z ${service_exec} ]]
222   then   then
223   case ${service} in   case ${service} in
# Line 179  mstopunit() Line 227  mstopunit()
227   *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;   *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
228   *) service_exec="$(which ${service} 2> /dev/null)" ;;   *) service_exec="$(which ${service} 2> /dev/null)" ;;
229   esac   esac
230     elif [[ x$(basename ${service_exec}) = x${service_exec} ]]
231     then
232     # expand full path
233     service_exec="$(which ${service_exec})"
234   fi   fi
235    
236   # only stop the service if ${service_exec} does not exist   # only stop the service if ${service_exec} does not exist
237   [[ -f ${MROOT}/${service_exec} ]] && return   [[ -x ${MROOT}/${service_exec} ]] && return
238    
239   # del services from runlevel regardless if they exist or not   # del services from runlevel regardless if they exist or not
240   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
241   # reload daemon to honor changed unit files   # reload daemon to honor changed unit files
242   systemctl daemon-reload   systemctl ${opts} daemon-reload
243   systemctl disable ${service}   systemctl ${opts} disable ${service}
244    
245   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
246   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
247   then   then
248     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..."
249   systemctl stop ${service}   systemctl stop ${service}
250   # try harder   # try harder
251   if [[ -n $(pidof ${service_exec}) ]]   if [[ -n $(pidof ${service_exec}) ]]
# Line 210  mreloadunit() Line 263  mreloadunit()
263  {  {
264   local service="$1"   local service="$1"
265   local service_exec="$2"   local service_exec="$2"
266     local opts
267    
268   # only run if systemd was found   # only run if systemd was found
269   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]]
270   then   then
271   echo "systemd not found, not removing unit ${service} from runlevels!"   echo "systemd not found, not removing unit ${service} from runlevels!"
272   return   return
273   fi   fi
274    
275   # we do not support $MROOT atm   # don't run if feature !autosvc was set
276   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if mqueryfeature "!autosvc"
277   then   then
278   echo "\$MROOT is set, doing nothing!"   echo "!autosvc detected; auto management of services disabled."
  echo "Please remove unit ${service} manually from the runlevels!"  
  echo "Run 'systemctl disable ${service}' in your chroot later on."  
279   return   return
280   fi   fi
281    
282     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
283     then
284     opts="--root ${MROOT}"
285     fi
286    
287   if [[ -z ${service_exec} ]]   if [[ -z ${service_exec} ]]
288   then   then
289   case ${service} in   case ${service} in
# Line 238  mreloadunit() Line 295  mreloadunit()
295   esac   esac
296   fi   fi
297    
298     # reload daemon to honor changed unit files
299     systemctl ${opts} daemon-reload
300    
301   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
302   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
303   then   then

Legend:
Removed from v.20  
changed lines
  Added in v.63