Contents of /branches/magellan-next/include/mtools.minc
Parent Directory | Revision Log
Revision 5 -
(show annotations)
(download)
Fri Jun 12 17:23:41 2009 UTC (15 years, 3 months ago) by niro
Original Path: trunk/include/mtools.minc
File size: 2216 byte(s)
Fri Jun 12 17:23:41 2009 UTC (15 years, 3 months ago) by niro
Original Path: trunk/include/mtools.minc
File size: 2216 byte(s)
-colored output
1 | # $Header: /magellan-cvs/mage/include/mtools.minc,v 1.3 2008/02/10 12:13:56 niro Exp $ |
2 | |
3 | # adds services to runlevels and starts them |
4 | # mstartservice service {/path/to/service_exec} |
5 | mstartservice() |
6 | { |
7 | local service="$1" |
8 | local service_exec="$2" |
9 | |
10 | [[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
11 | |
12 | # add service to default runlevels |
13 | echo " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..." |
14 | [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null |
15 | |
16 | # do not start services on bootstrap or MROOT!=/ |
17 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
18 | then |
19 | # start service |
20 | if [[ -n $(pidof ${service_exec}) ]] |
21 | then |
22 | # restart service |
23 | /etc/init.d/${service} restart |
24 | else |
25 | # start service |
26 | /etc/init.d/${service} start |
27 | fi |
28 | fi |
29 | } |
30 | |
31 | # removes services from runlevels and stops them |
32 | # mstopservice service {/path/to/service_exec} |
33 | mstopservice() |
34 | { |
35 | local service="$1" |
36 | local service_exec="$2" |
37 | |
38 | [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
39 | |
40 | # only stop the service if ${service_exec} does not exist |
41 | [[ -f ${MROOT}/${service_exec} ]] && return |
42 | |
43 | # del services from runlevel regardless if they exist or not |
44 | echo " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..." |
45 | rc-config del ${service} &> /dev/null |
46 | |
47 | # do not stop services on bootstrap or MROOT!=/ |
48 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
49 | then |
50 | # stop service if running |
51 | if [[ -n $(pidof ${service_exec}) ]] |
52 | then |
53 | killall -15 ${service_exec} &> /dev/null |
54 | sleep 1 |
55 | killall -9 ${service_exec} &> /dev/null |
56 | fi |
57 | fi |
58 | } |
59 | |
60 | # reloads a service if already running |
61 | # mreloadservice service {/path/to/service_exec} |
62 | mreloadservice() |
63 | { |
64 | local service="$1" |
65 | local service_exec="$2" |
66 | |
67 | [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
68 | |
69 | # do not stop services on bootstrap or MROOT!=/ |
70 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
71 | then |
72 | # only reload the service if running |
73 | if [[ -n $(pidof ${service_exec}) ]] |
74 | then |
75 | /etc/init.d/${service} reload |
76 | fi |
77 | fi |
78 | } |