Magellan Linux

Diff of /branches/magellan-next/include/mtools.minc

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

revision 15 by niro, Thu Jun 2 16:16:12 2011 UTC revision 16 by niro, Thu Jun 2 17:44:13 2011 UTC
# Line 76  mreloadservice() Line 76  mreloadservice()
76   fi   fi
77   fi   fi
78  }  }
79    
80    
81    # adds systemd units to runlevels and starts them
82    # mstartunit service {/path/to/service_exec}
83    mstartunit()
84    {
85     local service="$1"
86     local service_exec="$2"
87    
88     # only run if systemd was found
89     if [[ ! -x /bin/systemctl ]]
90     then
91     echo "systemd not found, not adding unit ${service} to runlevels!"
92     return
93     fi
94    
95     # we do not support $MROOT atm
96     if [[ ${MROOT} != / ]] || [[ ! -z ${MROOT} ]]
97     then
98     echo "\$MROOT is set, doing nothing!"
99     echo "Please add unit ${service} manually to the runlevels!"
100     echo "Run 'systemctl enable ${service}' in your chroot later on."
101     return
102     fi
103    
104     [[ -z ${service_exec} ]] && service_exec="$(which ${service})"
105    
106     # add service to default runlevels
107     echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..."
108     # reload daemon to honor changed unit files
109     systemctl daemon-reload
110     systemctl enable ${service}
111    
112     # do not start services on bootstrap or MROOT!=/
113     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
114     then
115     # start or restart the service
116     systemctl try-restart ${service}
117     fi
118    }
119    
120    # removes systemd units from runlevels and stops them
121    # mstopunit service {/path/to/service_exec}
122    mstopunit()
123    {
124     local service="$1"
125     local service_exec="$2"
126    
127     # only run if systemd was found
128     if [[ ! -x /bin/systemctl ]]
129     then
130     echo "systemd not found, not removing unit ${service} from runlevels!"
131     return
132     fi
133    
134     # we do not support $MROOT atm
135     if [[ ${MROOT} != / ]] || [[ ! -z ${MROOT} ]]
136     then
137     echo "\$MROOT is set, doing nothing!"
138     echo "Please remove unit ${service} manually from the runlevels!"
139     echo "Run 'systemctl disable ${service}' in your chroot later on."
140     return
141     fi
142    
143     [[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)"
144    
145     # only stop the service if ${service_exec} does not exist
146     [[ -f ${MROOT}/${service_exec} ]] && return
147    
148     # del services from runlevel regardless if they exist or not
149     echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..."
150     # reload daemon to honor changed unit files
151     systemctl daemon-reload
152     systemctl disable ${service}
153    
154     # do not stop services on bootstrap or MROOT!=/
155     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
156     then
157     systemctl stop ${service}
158     # try harder
159     if [[ -n $(pidof ${service_exec}) ]]
160     then
161     killall -15 ${service_exec} &> /dev/null
162     sleep 1
163     killall -9 ${service_exec} &> /dev/null
164     fi
165     fi
166    }
167    
168    # reloads a systemd unit if already running
169    # mreloadunit service {/path/to/service_exec}
170    mreloadunit()
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     # do not stop services on bootstrap or MROOT!=/
194     if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
195     then
196     # only reload the service if running
197     systemctl reload-or-try-restart ${service}
198     fi
199    }

Legend:
Removed from v.15  
changed lines
  Added in v.16