Magellan Linux

Diff of /trunk/include/mtools.minc

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

revision 17 by niro, Thu Jun 2 18:01:44 2011 UTC revision 32 by niro, Tue Dec 13 17:33:23 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
# 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
# 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 77  mreloadservice() Line 98  mreloadservice()
98   fi   fi
99  }  }
100    
   
101  # adds systemd units to runlevels and starts them  # adds systemd units to runlevels and starts them
102  # mstartunit service {/path/to/service_exec}  # mstartunit service {/path/to/service_exec}
103  mstartunit()  mstartunit()
104  {  {
105   local service="$1"   local service="$1"
106   local service_exec="$2"   local service_exec="$2"
107     local opts
108    
109   # only run if systemd was found   # only run if systemd was found
110   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]]
# Line 92  mstartunit() Line 113  mstartunit()
113   return   return
114   fi   fi
115    
  # we do not support $MROOT atm  
116   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
117   then   then
118   echo "\$MROOT is set, doing nothing!"   opts="--root ${MROOT}"
  echo "Please add unit ${service} manually to the runlevels!"  
  echo "Run 'systemctl enable ${service}' in your chroot later on."  
  return  
119   fi   fi
120    
121   [[ -z ${service_exec} ]] && service_exec="$(which ${service})"   if [[ -z ${service_exec} ]]
122     then
123     case ${service} in
124     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
125     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
126     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
127     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
128     *) service_exec="$(which ${service} 2> /dev/null)" ;;
129     esac
130     fi
131    
132   # add service to default runlevels   # add service to default runlevels
133   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."   echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
134   # reload daemon to honor changed unit files   # reload daemon to honor changed unit files
135   systemctl daemon-reload   systemctl ${opts} daemon-reload
136   systemctl enable ${service}   systemctl ${opts} enable ${service}
137    
138   # do not start services on bootstrap or MROOT!=/   # do not start services on bootstrap or MROOT!=/
139   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
140   then   then
141     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..."
142   # start or restart the service   # start or restart the service
143   systemctl try-restart ${service}   # dont use try-restart, works only with active services!
144     systemctl restart ${service}
145   fi   fi
146  }  }
147    
# Line 123  mstopunit() Line 151  mstopunit()
151  {  {
152   local service="$1"   local service="$1"
153   local service_exec="$2"   local service_exec="$2"
154     local opts
155    
156   # only run if systemd was found   # only run if systemd was found
157   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]]
# Line 131  mstopunit() Line 160  mstopunit()
160   return   return
161   fi   fi
162    
  # we do not support $MROOT atm  
163   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
164   then   then
165   echo "\$MROOT is set, doing nothing!"   opts="--root ${MROOT}"
  echo "Please remove unit ${service} manually from the runlevels!"  
  echo "Run 'systemctl disable ${service}' in your chroot later on."  
  return  
166   fi   fi
167    
168   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   if [[ -z ${service_exec} ]]
169     then
170     case ${service} in
171     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
172     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
173     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
174     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
175     *) service_exec="$(which ${service} 2> /dev/null)" ;;
176     esac
177     fi
178    
179   # only stop the service if ${service_exec} does not exist   # only stop the service if ${service_exec} does not exist
180   [[ -f ${MROOT}/${service_exec} ]] && return   [[ -f ${MROOT}/${service_exec} ]] && return
# Line 148  mstopunit() Line 182  mstopunit()
182   # del services from runlevel regardless if they exist or not   # del services from runlevel regardless if they exist or not
183   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."   echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
184   # reload daemon to honor changed unit files   # reload daemon to honor changed unit files
185   systemctl daemon-reload   systemctl ${opts} daemon-reload
186   systemctl disable ${service}   systemctl ${opts} disable ${service}
187    
188   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
189   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
190   then   then
191     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..."
192   systemctl stop ${service}   systemctl stop ${service}
193   # try harder   # try harder
194   if [[ -n $(pidof ${service_exec}) ]]   if [[ -n $(pidof ${service_exec}) ]]
# Line 171  mreloadunit() Line 206  mreloadunit()
206  {  {
207   local service="$1"   local service="$1"
208   local service_exec="$2"   local service_exec="$2"
209     local opts
210    
211   # only run if systemd was found   # only run if systemd was found
212   if [[ ! -x /bin/systemctl ]]   if [[ ! -x /bin/systemctl ]]
# Line 179  mreloadunit() Line 215  mreloadunit()
215   return   return
216   fi   fi
217    
  # we do not support $MROOT atm  
218   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]   if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]]
219   then   then
220   echo "\$MROOT is set, doing nothing!"   opts="--root ${MROOT}"
221   echo "Please remove unit ${service} manually from the runlevels!"   fi
222   echo "Run 'systemctl disable ${service}' in your chroot later on."  
223   return   if [[ -z ${service_exec} ]]
224     then
225     case ${service} in
226     *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;;
227     *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;;
228     *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;;
229     *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;;
230     *) service_exec="$(which ${service} 2> /dev/null)" ;;
231     esac
232   fi   fi
233    
234   [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"   # reload daemon to honor changed unit files
235     systemctl ${opts} daemon-reload
236    
237   # do not stop services on bootstrap or MROOT!=/   # do not stop services on bootstrap or MROOT!=/
238   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]   if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]

Legend:
Removed from v.17  
changed lines
  Added in v.32