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 17 by niro, Thu Jun 2 18:01:44 2011 UTC trunk/include/mtools.minc revision 63 by niro, Wed Oct 9 12:23:06 2013 UTC
# Line 1  Line 1 
1  # $Header: /magellan-cvs/mage/include/mtools.minc,v 1.3 2008/02/10 12:13:56 niro Exp $  # $Id$
2    
3  # adds services to runlevels and starts them  # adds services to runlevels and starts them
4  # mstartservice service {/path/to/service_exec}  # mstartservice service {/path/to/service_exec}
# Line 7  mstartservice() Line 7  mstartservice()
7   local service="$1"   local service="$1"
8   local service_exec="$2"   local service_exec="$2"
9    
10     # only run if sysV init was found
11     if [[ ! -f /etc/rc.d/init.d/functions ]]
12     then
13     echo "sysV init not found, not adding service ${service} to runlevels!"
14     return
15     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 35  mstopservice() Line 49  mstopservice()
49   local service="$1"   local service="$1"
50   local service_exec="$2"   local service_exec="$2"
51    
52   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
53     if [[ ! -f /etc/rc.d/init.d/functions ]]
54     then
55     echo "sysV init not found, not adding service ${service} to runlevels!"
56     return
57     fi
58    
59     # 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 64  mreloadservice() Line 99  mreloadservice()
99   local service="$1"   local service="$1"
100   local service_exec="$2"   local service_exec="$2"
101    
102   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
103     if [[ ! -f /etc/rc.d/init.d/functions ]]
104     then
105     echo "sysV init not found, not adding service ${service} to runlevels!"
106     return
107     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})"
117    
118   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
119   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
# Line 77  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   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   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} ]]
165     then
166     case ${service} in
167     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
168     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
169     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
170     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
171     *) service_exec="$(which ${service} 2> /dev/null)" ;;
172     esac
173     fi
174    
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 123  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   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
217     then
218     opts="--root ${MROOT}"
219     fi
220    
221     if [[ -z ${service_exec} ]]
222     then
223     case ${service} in
224     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
225     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
226     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
227     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
228     *) service_exec="$(which ${service} 2> /dev/null)" ;;
229     esac
230     elif [[ x$(basename ${service_exec}) = x${service_exec} ]]
231     then
232     # expand full path
233     service_exec="$(which ${service_exec})"
234     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 171  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   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
283     then
284     opts="--root ${MROOT}"
285     fi
286    
287     if [[ -z ${service_exec} ]]
288     then
289     case ${service} in
290     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
291     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
292     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
293     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
294     *) service_exec="$(which ${service} 2> /dev/null)" ;;
295     esac
296     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} = / ]]

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