[lxc-devel] [PATCH] [Cancel] Additional logic for dealing with container shutdown / reboot

Serge Hallyn serge.hallyn at ubuntu.com
Mon Jan 13 15:25:28 UTC 2014


Quoting Michael H. Warfield (mhw at WittsEnd.com):
> This patch hasn't made it into the repository yet and there have been a

Hm.  I applied this patch quite some time ago, but indeed even then
the create_hwaddr fn was already gone.  So only the halt handling code
was added to both templates.

-serge

> lot of other changes.  I'm canceling this and will reissue a patch which
> includes some additional changes from discussion with Serge and others.
> Please drop this change.
> 
> On Sat, 2013-12-28 at 12:35 -0500, Michael H. Warfield wrote: 
> > Additional logic for dealing with container shutdown / reboot
> > 
> > Fix a problem with CentOS containers and legacy Fedora (<16) containers
> > not shutting down or rebooting properly.  Copy /etc/init.d/halt to
> > /etc/init.d/lxc-halt, deleting everything from the "hwclock save" and
> > all after and append a force halt or reboot at the end of the new
> > script, to prevent reexecing init.  Link that script in as
> > S00lxc-halt in rc0.d and S00lxc-reboot in rc6.d to intercept the
> > shutdown process before it gets to S01halt / S01reboot causing the hang.
> > 
> > Fixed some typos in the CentOS template that were introduced in the
> > previous patch for hwaddr settings and missed in regression testing.
> > 
> > Cleaned up some instruction typos and tabs from previous patch.
> > 
> > Signed-off-by: Michael H. Warfield <mhw at WittsEnd.com>
> > ---
> >  templates/lxc-centos.in | 40 ++++++++++++++++++++++++++++++++++------
> >  templates/lxc-fedora.in | 35 +++++++++++++++++++++++++++++++++--
> >  2 files changed, 67 insertions(+), 8 deletions(-)
> > 
> > diff --git a/templates/lxc-centos.in b/templates/lxc-centos.in
> > index 5bb5349..3fbb5a9 100644
> > --- a/templates/lxc-centos.in
> > +++ b/templates/lxc-centos.in
> > @@ -178,7 +178,35 @@ configure_centos()
> >          )
> >      fi
> >  
> > -   # configure the network using the dhcp
> > +    # Deal with some dain bramage in the /etc/init.d/halt script.
> > +    # Trim it and make it our own and link it in before the default
> > +    # halt script so we can intercept it.  This also preventions package
> > +    # updates from interferring with our interferring with it.
> > +    #
> > +    # There's generally not much in the halt script that useful but what's
> > +    # in there from resetting the hardware clock down is generally very bad.
> > +    # So we just eliminate the whole bottom half of that script in making
> > +    # ourselves a copy.  That way a major update to the init scripts won't
> > +    # trash what we've set up.
> > +    if [ -f ${rootfs_path}/etc/init.d/halt ]
> > +    then
> > +        sed -e '/hwclock/,$d' \
> > +            < ${rootfs_path}/etc/init.d/halt \
> > +            > ${rootfs_path}/etc/init.d/lxc-halt
> > +
> > +        echo '$command -f' >> ${rootfs_path}/etc/init.d/lxc-halt
> > +        chmod 755 ${rootfs_path}/etc/init.d/lxc-halt
> > +
> > +        # Link them into the rc directories...
> > +        (
> > +             cd ${rootfs_path}/etc/rc.d/rc0.d
> > +             ln -s ../init.d/lxc-halt S00lxc-halt
> > +             cd ${rootfs_path}/etc/rc.d/rc6.d
> > +             ln -s ../init.d/lxc-halt S00lxc-reboot
> > +        )
> > +    fi
> > +
> > +    # configure the network using the dhcp
> >      cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
> >  DEVICE=eth0
> >  BOOTPROTO=dhcp
> > @@ -434,8 +462,8 @@ install_centos()
> >  
> >  create_hwaddr()
> >  {
> > -    echo $(dd if=/dev/urandom bs=8 count=1 2>/dev/null | md5sum
> > -        | sed -e 's/\(..\)\(..\)\(..\)\(..\)\(..\).*/fe:\1:\2:\3:\4:\5/')
> > +    echo $(dd if=/dev/urandom bs=8 count=1 2>/dev/null | md5sum |
> > +        sed -e 's/\(..\)\(..\)\(..\)\(..\)\(..\).*/fe:\1:\2:\3:\4:\5/')
> >  }
> >  
> >  copy_configuration()
> > @@ -455,12 +483,12 @@ lxc.rootfs = $rootfs_path
> >          # This should catch variable expansions from the default config...
> >          if expr "${LINE}" : '.*\$' > /dev/null 2>&1
> >          then
> > -		LINE=$(eval "echo \"${LINE}\"")
> > +                LINE=$(eval "echo \"${LINE}\"")
> >          fi
> >  
> >          # There is a tab and a space in the regex bracket below!
> >          # Seems that \s doesn't work in brackets.
> > -        KEY=$(expr $LINE : '\s*\([^	 ]*\)\s*=')
> > +        KEY=$(expr "${LINE}" : '\s*\([^	 ]*\)\s*=')
> >  
> >          if [[ "${KEY}" != "lxc.network.hwaddr" ]]
> >          then
> > @@ -724,7 +752,7 @@ echo "The temporary password for root is: '$root_password'
> >  
> >  You may want to note that password down before starting the container.
> >  
> > -The password set up as "expired" and will require it to be changed it at
> > +The password is set up as "expired" and will require it to be changed it at
> >  first login, which you should do as soon as possible.  If you lose the
> >  root password or wish to change it without starting the container, you
> >  can change it from the host by running the following command (which will
> > diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in
> > index b0c214a..0ae394e 100644
> > --- a/templates/lxc-fedora.in
> > +++ b/templates/lxc-fedora.in
> > @@ -147,6 +147,37 @@ configure_fedora()
> >          )
> >      fi
> >  
> > +    # Deal with some dain bramage in the /etc/init.d/halt script.
> > +    # Trim it and make it our own and link it in before the default
> > +    # halt script so we can intercept it.  This also preventions package
> > +    # updates from interferring with our interferring with it.
> > +    #
> > +    # There's generally not much in the halt script that useful but what's
> > +    # in there from resetting the hardware clock down is generally very bad.
> > +    # So we just eliminate the whole bottom half of that script in making
> > +    # ourselves a copy.  That way a major update to the init scripts won't
> > +    # trash what we've set up.
> > +    #
> > +    # This is mostly for legacy distros since any modern systemd Fedora
> > +    # release will not have this script so we won't try to intercept it.
> > +    if [ -f ${rootfs_path}/etc/init.d/halt ]
> > +    then
> > +        sed -e '/hwclock/,$d' \
> > +            < ${rootfs_path}/etc/init.d/halt \
> > +            > ${rootfs_path}/etc/init.d/lxc-halt
> > +
> > +        echo '$command -f' >> ${rootfs_path}/etc/init.d/lxc-halt
> > +        chmod 755 ${rootfs_path}/etc/init.d/lxc-halt
> > +
> > +        # Link them into the rc directories...
> > +        (
> > +             cd ${rootfs_path}/etc/rc.d/rc0.d
> > +             ln -s ../init.d/lxc-halt S00lxc-halt
> > +             cd ${rootfs_path}/etc/rc.d/rc6.d
> > +             ln -s ../init.d/lxc-halt S00lxc-reboot
> > +        )
> > +    fi
> > +
> >      # configure the network using the dhcp
> >      cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
> >  DEVICE=eth0
> > @@ -925,7 +956,7 @@ lxc.rootfs = $rootfs_path
> >          # This should catch variable expansions from the default config...
> >          if expr "${LINE}" : '.*\$' > /dev/null 2>&1
> >          then
> > -		LINE=$(eval "echo \"${LINE}\"")
> > +                LINE=$(eval "echo \"${LINE}\"")
> >          fi
> >  
> >          # There is a tab and a space in the regex bracket below!
> > @@ -1222,7 +1253,7 @@ echo "The temporary password for root is: '$root_password'
> >  
> >  You may want to note that password down before starting the container.
> >  
> > -The password set up as "expired" and will require it to be changed it at
> > +The password is set up as "expired" and will require it to be changed it at
> >  first login, which you should do as soon as possible.  If you lose the
> >  root password or wish to change it without starting the container, you
> >  can change it from the host by running the following command (which will
> > -- 
> > 1.8.3.1
> > 
> > 
> > 
> 
> -- 
> Michael H. Warfield (AI4NB) | (770) 978-7061 |  mhw at WittsEnd.com
>    /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
>    NIC whois: MHW9          | An optimist believes we live in the best of all
>  PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
> 



> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel



More information about the lxc-devel mailing list