Magellan Linux

Annotation of /trunk/include/sysvinit.minc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download)
Wed Oct 9 13:02:57 2013 UTC (10 years, 7 months ago) by niro
File size: 3238 byte(s)
-split mtools.minc into systemd.minc and sysvinit.minc
1 niro 64 # $Id$
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     # 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})"
25    
26     # add service to default runlevels
27     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..."
28     [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null
29    
30     # do not start services on bootstrap or MROOT!=/
31     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
32     then
33     # start service
34     if [[ -n $(pidof ${service_exec}) ]]
35     then
36     # restart service
37     /etc/init.d/${service} restart
38     else
39     # start service
40     /etc/init.d/${service} start
41     fi
42     fi
43     }
44    
45     # removes services from runlevels and stops them
46     # mstopservice service {/path/to/service_exec}
47     mstopservice()
48     {
49     local service="$1"
50     local service_exec="$2"
51    
52     # 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
76     [[ -x ${MROOT}/${service_exec} ]] && return
77    
78     # del services from runlevel regardless if they exist or not
79     echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..."
80     rc-config del ${service} &> /dev/null
81    
82     # do not stop services on bootstrap or MROOT!=/
83     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
84     then
85     # stop service if running
86     if [[ -n $(pidof ${service_exec}) ]]
87     then
88     killall -15 ${service_exec} &> /dev/null
89     sleep 1
90     killall -9 ${service_exec} &> /dev/null
91     fi
92     fi
93     }
94    
95     # reloads a service if already running
96     # mreloadservice service {/path/to/service_exec}
97     mreloadservice()
98     {
99     local service="$1"
100     local service_exec="$2"
101    
102     # 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!=/
119     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
120     then
121     # only reload the service if running
122     if [[ -n $(pidof ${service_exec}) ]]
123     then
124     /etc/init.d/${service} reload
125     fi
126     fi
127     }