Magellan Linux

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

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

trunk/include/mtools.minc revision 5 by niro, Fri Jun 12 17:23:41 2009 UTC branches/magellan-next/include/mtools.minc revision 20 by niro, Thu Jun 2 21:36:05 2011 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   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
18    
19   # add service to default runlevels   # add service to default runlevels
20   echo " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."
21   [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null   [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null
22    
23   # do not start services on bootstrap or MROOT!=/   # do not start services on bootstrap or MROOT!=/
# Line 35  mstopservice() Line 42  mstopservice()
42   local service="$1"   local service="$1"
43   local service_exec="$2"   local service_exec="$2"
44    
45   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
46     if [[ ! -f /etc/rc.d/init.d/functions ]]
47     then
48     echo "sysV init not found, not adding service ${service} to runlevels!"
49     return
50     fi
51    
52     [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
53    
54   # only stop the service if ${service_exec} does not exist   # only stop the service if ${service_exec} does not exist
55   [[ -f ${MROOT}/${service_exec} ]] && return   [[ -f ${MROOT}/${service_exec} ]] && return
56    
57   # del services from runlevel regardless if they exist or not   # del services from runlevel regardless if they exist or not
58   echo " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."
59   rc-config del ${service} &> /dev/null   rc-config del ${service} &> /dev/null
60    
61   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
# Line 64  mreloadservice() Line 78  mreloadservice()
78   local service="$1"   local service="$1"
79   local service_exec="$2"   local service_exec="$2"
80    
81   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
82     if [[ ! -f /etc/rc.d/init.d/functions ]]
83     then
84     echo "sysV init not found, not adding service ${service} to runlevels!"
85     return
86     fi
87    
88     [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
89    
90   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
91   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
# Line 76  mreloadservice() Line 97  mreloadservice()
97   fi   fi
98   fi   fi
99  }  }
100    
101    
102    # adds systemd units to runlevels and starts them
103    # mstartunit service {/path/to/service_exec}
104    mstartunit()
105    {
106     local service="$1"
107     local service_exec="$2"
108    
109     # only run if systemd was found
110     if [[ ! -x /bin/systemctl ]]
111     then
112     echo "systemd not found, not adding unit ${service} to runlevels!"
113     return
114     fi
115    
116     # we do not support $MROOT atm
117     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
118     then
119     echo "\$MROOT is set, doing nothing!"
120     echo "Please add unit ${service} manually to the runlevels!"
121     echo "Run 'systemctl enable ${service}' in your chroot later on."
122     return
123     fi
124    
125     if [[ -z ${service_exec} ]]
126     then
127     case ${service} in
128     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
129     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
130     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
131     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
132     *) service_exec="$(which ${service} 2> /dev/null)" ;;
133     esac
134     fi
135    
136     # add service to default runlevels
137     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
138     # reload daemon to honor changed unit files
139     systemctl daemon-reload
140     systemctl enable ${service}
141    
142     # do not start services on bootstrap or MROOT!=/
143     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
144     then
145     # start or restart the service
146     systemctl try-restart ${service}
147     fi
148    }
149    
150    # removes systemd units from runlevels and stops them
151    # mstopunit service {/path/to/service_exec}
152    mstopunit()
153    {
154     local service="$1"
155     local service_exec="$2"
156    
157     # only run if systemd was found
158     if [[ ! -x /bin/systemctl ]]
159     then
160     echo "systemd not found, not removing unit ${service} from runlevels!"
161     return
162     fi
163    
164     # we do not support $MROOT atm
165     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
166     then
167     echo "\$MROOT is set, doing nothing!"
168     echo "Please remove unit ${service} manually from the runlevels!"
169     echo "Run 'systemctl disable ${service}' in your chroot later on."
170     return
171     fi
172    
173     if [[ -z ${service_exec} ]]
174     then
175     case ${service} in
176     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
177     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
178     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
179     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
180     *) service_exec="$(which ${service} 2> /dev/null)" ;;
181     esac
182     fi
183    
184     # only stop the service if ${service_exec} does not exist
185     [[ -f ${MROOT}/${service_exec} ]] && return
186    
187     # del services from runlevel regardless if they exist or not
188     echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
189     # reload daemon to honor changed unit files
190     systemctl daemon-reload
191     systemctl disable ${service}
192    
193     # do not stop services on bootstrap or MROOT!=/
194     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
195     then
196     systemctl stop ${service}
197     # try harder
198     if [[ -n $(pidof ${service_exec}) ]]
199     then
200     killall -15 ${service_exec} &> /dev/null
201     sleep 1
202     killall -9 ${service_exec} &> /dev/null
203     fi
204     fi
205    }
206    
207    # reloads a systemd unit if already running
208    # mreloadunit service {/path/to/service_exec}
209    mreloadunit()
210    {
211     local service="$1"
212     local service_exec="$2"
213    
214     # only run if systemd was found
215     if [[ ! -x /bin/systemctl ]]
216     then
217     echo "systemd not found, not removing unit ${service} from runlevels!"
218     return
219     fi
220    
221     # we do not support $MROOT atm
222     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
223     then
224     echo "\$MROOT is set, doing nothing!"
225     echo "Please remove unit ${service} manually from the runlevels!"
226     echo "Run 'systemctl disable ${service}' in your chroot later on."
227     return
228     fi
229    
230     if [[ -z ${service_exec} ]]
231     then
232     case ${service} in
233     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
234     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
235     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
236     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
237     *) service_exec="$(which ${service} 2> /dev/null)" ;;
238     esac
239     fi
240    
241     # do not stop services on bootstrap or MROOT!=/
242     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
243     then
244     # only reload the service if running
245     systemctl reload-or-try-restart ${service}
246     fi
247    }

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