Bug 1138528

Summary: lxc-stop not working as expected
Product: [Fedora] Fedora EPEL Reporter: Sklav <gnudna>
Component: lxcAssignee: Thomas Moschny <thomas.moschny>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: epel7CC: karlthered, mhw, sagarun, thomas.moschny
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-09-17 01:30:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Sklav 2014-09-05 05:46:34 UTC
Description of problem:

lxc-stop does not stop all types of containers. Example debian wheezy containers do not stop properly and are killed after 60 second timeout

Version-Release number of selected component (if applicable):

lxc-1.0.5-3.el7.x86_64

How reproducible:
On 2 different installs i have the same issue with debian containers running on centos 7

Steps to Reproduce:
1. lxc-stop -n container_name

Actual results:
container stops running after a delay of approx 60 seconds

Expected results:
container should stop running immediately or withing a few seconds aka less than 2 or 3 seconds

lxc-stop -n container_name -k    seems to work but from what i understand this forces a shutdown similar to cutting the power

Additional info:
Very annoying issue as in many cases it looks like the container has locked up

This causes issues if you ever reboot the host machine as it takes a few minutes if not more to power cycle

Comment 1 Michael H. Warfield 2014-09-14 18:10:43 UTC
This is an issue with SIGPWR handling in the container.  The lxc-stop command now issues a SIGPWR signal to the container init and then waits a time out period for the container to gracefully shut down and exit.  The container init process must handle that signal and shut down gracefully.  If it fails to shut down gracefully before a timeout, lxc-stop will then kill the container.

The Debian container (probably sysvinit or lsbinit) has to be configured to handle the SIGPWR signal an initiate a shutdown.  Alternative is to simply issue a "lxc-stop -k" or set a very short timeout.  But this doesn't do and orderly shutdown in the container.  The proper solution is to reconfigure the Debian container to shut down on SIGPWR.

That can probably (should probably) be set up in the Debian template but all existing (old) containers will have to be reconfigured manually.

The old behavior of lxc-stop pre-1.0 was to unceremoniously kill the container, which can lead to corrupted database and other mayhem from the container not shutting down gracefully.  The current lxc-stop is behaving as designed and as expected.  The problem is a configuration issue in the container.

Comment 2 Michael H. Warfield 2014-09-15 00:19:37 UTC
Strange...  I just now tested a Debian Wheezy container on my Fedora 20 server.  Running lxc-stop -n {container} shuts the container down in about 3 or 4 seconds, no problem.

Does your container have this line in /etc/inittab?

p0::powerfail:/sbin/init 0

Did you install and alternate init system (upstart or systemd)?

Comment 3 Sklav 2014-09-17 01:24:39 UTC
I can confirm that on my template in inittab
p0::powerfail:/sbin/init 0
was not being added.

this is due to the containers having been migrated from an older lxc base. 

I have added it to existing containers and all is working as expected. So we can consider this resolved. Sorry for the inconvenience