Do not stop hosts' SSH + mdadm services in cleanup procedure
authorMichael Prokop <mika@grml.org>
Tue, 10 Mar 2015 13:49:41 +0000 (14:49 +0100)
committerMichael Prokop <mika@grml.org>
Tue, 10 Mar 2015 13:49:41 +0000 (14:49 +0100)
The init script uses start-stop-daemon with the pidfile
/var/run/sshd.pid. We can't just stop the service from
outside the chroot because this terminates the process of the
host system instead of the process *inside* the chroot.

Thanks: Sebastian Pipping for debugging and bug report
Fixes #63 (GH-37, PR 71)

grml-debootstrap

index a97f5ec..739fd86 100755 (executable)
@@ -205,8 +205,11 @@ cleanup() {
   if [ -n "$MNTPOINT" ] ; then
     if grep -q "$MNTPOINT" /proc/mounts ; then
       # make sure nothing is left inside chroot so we can unmount it
   if [ -n "$MNTPOINT" ] ; then
     if grep -q "$MNTPOINT" /proc/mounts ; then
       # make sure nothing is left inside chroot so we can unmount it
-      [ -x "$MNTPOINT"/etc/init.d/ssh   ] && "$MNTPOINT"/etc/init.d/ssh stop
-      [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
+      for service in ssh mdadm ; do
+        if [ -x "${MNTPOINT}/etc/init.d/${service}" ] ; then
+          chroot "$MNTPOINT" "/etc/init.d/${service}" stop
+        fi
+      done
 
       [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1
 
 
       [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1