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 6 by niro, Fri Jun 12 17:25:14 2009 UTC branches/magellan-next/include/mtools.minc revision 19 by niro, Thu Jun 2 21:21:16 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   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   # 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     if [[ -z ${service_exec} ]]
18     then
19     case ${service} in
20     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
21     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
22     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
23     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
24     *) service_exec="$(which ${service} 2> /dev/null)" ;;
25     esac
26     fi
27    
28   # add service to default runlevels   # add service to default runlevels
29   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."
# Line 35  mstopservice() Line 51  mstopservice()
51   local service="$1"   local service="$1"
52   local service_exec="$2"   local service_exec="$2"
53    
54   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
55     if [[ ! -f /etc/rc.d/init.d/functions ]]
56     then
57     echo "sysV init not found, not adding service ${service} to runlevels!"
58     return
59     fi
60    
61     if [[ -z ${service_exec} ]]
62     then
63     case ${service} in
64     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
65     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
66     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
67     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
68     *) service_exec="$(which ${service} 2> /dev/null)" ;;
69     esac
70     fi
71    
72   # only stop the service if ${service_exec} does not exist   # only stop the service if ${service_exec} does not exist
73   [[ -f ${MROOT}/${service_exec} ]] && return   [[ -f ${MROOT}/${service_exec} ]] && return
# Line 64  mreloadservice() Line 96  mreloadservice()
96   local service="$1"   local service="$1"
97   local service_exec="$2"   local service_exec="$2"
98    
99   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # only run if sysV init was found
100     if [[ ! -f /etc/rc.d/init.d/functions ]]
101     then
102     echo "sysV init not found, not adding service ${service} to runlevels!"
103     return
104     fi
105    
106     if [[ -z ${service_exec} ]]
107     then
108     case ${service} in
109     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
110     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
111     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
112     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
113     *) service_exec="$(which ${service} 2> /dev/null)" ;;
114     esac
115     fi
116    
117   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
118   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
# Line 76  mreloadservice() Line 124  mreloadservice()
124   fi   fi
125   fi   fi
126  }  }
127    
128    
129    # adds systemd units to runlevels and starts them
130    # mstartunit service {/path/to/service_exec}
131    mstartunit()
132    {
133     local service="$1"
134     local service_exec="$2"
135    
136     # only run if systemd was found
137     if [[ ! -x /bin/systemctl ]]
138     then
139     echo "systemd not found, not adding unit ${service} to runlevels!"
140     return
141     fi
142    
143     # we do not support $MROOT atm
144     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
145     then
146     echo "\$MROOT is set, doing nothing!"
147     echo "Please add unit ${service} manually to the runlevels!"
148     echo "Run 'systemctl enable ${service}' in your chroot later on."
149     return
150     fi
151    
152     [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
153    
154     # add service to default runlevels
155     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
156     # reload daemon to honor changed unit files
157     systemctl daemon-reload
158     systemctl enable ${service}
159    
160     # do not start services on bootstrap or MROOT!=/
161     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
162     then
163     # start or restart the service
164     systemctl try-restart ${service}
165     fi
166    }
167    
168    # removes systemd units from runlevels and stops them
169    # mstopunit service {/path/to/service_exec}
170    mstopunit()
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     # only stop the service if ${service_exec} does not exist
194     [[ -f ${MROOT}/${service_exec} ]] && return
195    
196     # del services from runlevel regardless if they exist or not
197     echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
198     # reload daemon to honor changed unit files
199     systemctl daemon-reload
200     systemctl disable ${service}
201    
202     # do not stop services on bootstrap or MROOT!=/
203     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
204     then
205     systemctl stop ${service}
206     # try harder
207     if [[ -n $(pidof ${service_exec}) ]]
208     then
209     killall -15 ${service_exec} &> /dev/null
210     sleep 1
211     killall -9 ${service_exec} &> /dev/null
212     fi
213     fi
214    }
215    
216    # reloads a systemd unit if already running
217    # mreloadunit service {/path/to/service_exec}
218    mreloadunit()
219    {
220     local service="$1"
221     local service_exec="$2"
222    
223     # only run if systemd was found
224     if [[ ! -x /bin/systemctl ]]
225     then
226     echo "systemd not found, not removing unit ${service} from runlevels!"
227     return
228     fi
229    
230     # we do not support $MROOT atm
231     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
232     then
233     echo "\$MROOT is set, doing nothing!"
234     echo "Please remove unit ${service} manually from the runlevels!"
235     echo "Run 'systemctl disable ${service}' in your chroot later on."
236     return
237     fi
238    
239     [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
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.6  
changed lines
  Added in v.19