Magellan Linux

Diff of /trunk/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 29 by niro, Fri Aug 26 22:19:37 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    # adds systemd units to runlevels and starts them
102    # mstartunit service {/path/to/service_exec}
103    mstartunit()
104    {
105     local service="$1"
106     local service_exec="$2"
107    
108     # only run if systemd was found
109     if [[ ! -x /bin/systemctl ]]
110     then
111     echo "systemd not found, not adding unit ${service} to runlevels!"
112     return
113     fi
114    
115     # we do not support $MROOT atm
116     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
117     then
118     echo "\$MROOT is set, doing nothing!"
119     echo "Please add unit ${service} manually to the runlevels!"
120     echo "Run 'systemctl enable ${service}' in your chroot later on."
121     return
122     fi
123    
124     if [[ -z ${service_exec} ]]
125     then
126     case ${service} in
127     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
128     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
129     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
130     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
131     *) service_exec="$(which ${service} 2> /dev/null)" ;;
132     esac
133     fi
134    
135     # add service to default runlevels
136     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
137     # reload daemon to honor changed unit files
138     systemctl daemon-reload
139     systemctl enable ${service}
140    
141     # do not start services on bootstrap or MROOT!=/
142     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
143     then
144     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..."
145     # start or restart the service
146     # dont use try-restart, works only with active services!
147     systemctl restart ${service}
148     fi
149    }
150    
151    # removes systemd units from runlevels and stops them
152    # mstopunit service {/path/to/service_exec}
153    mstopunit()
154    {
155     local service="$1"
156     local service_exec="$2"
157    
158     # only run if systemd was found
159     if [[ ! -x /bin/systemctl ]]
160     then
161     echo "systemd not found, not removing unit ${service} from runlevels!"
162     return
163     fi
164    
165     # we do not support $MROOT atm
166     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
167     then
168     echo "\$MROOT is set, doing nothing!"
169     echo "Please remove unit ${service} manually from the runlevels!"
170     echo "Run 'systemctl disable ${service}' in your chroot later on."
171     return
172     fi
173    
174     if [[ -z ${service_exec} ]]
175     then
176     case ${service} in
177     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
178     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
179     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
180     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
181     *) service_exec="$(which ${service} 2> /dev/null)" ;;
182     esac
183     fi
184    
185     # only stop the service if ${service_exec} does not exist
186     [[ -f ${MROOT}/${service_exec} ]] && return
187    
188     # del services from runlevel regardless if they exist or not
189     echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
190     # reload daemon to honor changed unit files
191     systemctl daemon-reload
192     systemctl disable ${service}
193    
194     # do not stop services on bootstrap or MROOT!=/
195     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
196     then
197     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..."
198     systemctl stop ${service}
199     # try harder
200     if [[ -n $(pidof ${service_exec}) ]]
201     then
202     killall -15 ${service_exec} &> /dev/null
203     sleep 1
204     killall -9 ${service_exec} &> /dev/null
205     fi
206     fi
207    }
208    
209    # reloads a systemd unit if already running
210    # mreloadunit service {/path/to/service_exec}
211    mreloadunit()
212    {
213     local service="$1"
214     local service_exec="$2"
215    
216     # only run if systemd was found
217     if [[ ! -x /bin/systemctl ]]
218     then
219     echo "systemd not found, not removing unit ${service} from runlevels!"
220     return
221     fi
222    
223     # we do not support $MROOT atm
224     if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
225     then
226     echo "\$MROOT is set, doing nothing!"
227     echo "Please remove unit ${service} manually from the runlevels!"
228     echo "Run 'systemctl disable ${service}' in your chroot later on."
229     return
230     fi
231    
232     if [[ -z ${service_exec} ]]
233     then
234     case ${service} in
235     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
236     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
237     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
238     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
239     *) service_exec="$(which ${service} 2> /dev/null)" ;;
240     esac
241     fi
242    
243     # reload daemon to honor changed unit files
244     systemctl daemon-reload
245    
246     # do not stop services on bootstrap or MROOT!=/
247     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
248     then
249     # only reload the service if running
250     systemctl reload-or-try-restart ${service}
251     fi
252    }

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