Skip to content

Instantly share code, notes, and snippets.

@nstott
Last active May 24, 2016 20:37
Show Gist options
  • Save nstott/0e1fa9b839986c1bee3399e9ca13a1d6 to your computer and use it in GitHub Desktop.
Save nstott/0e1fa9b839986c1bee3399e9ca13a1d6 to your computer and use it in GitHub Desktop.
shutdown behaviour of rkt containers
#!/usr/bin/bash
shopt -s nullglob
SYSCTL=/usr/bin/systemctl
# just adding some debug to the reaper
echo "in the reaper"
if [ $# -eq 1 ]; then
app=$1
${SYSCTL} status "${app}.service" >> /rkt/reaper.log
status=$(${SYSCTL} show --property ExecMainStatus "${app}.service")
echo "${status#*=}" > "/rkt/status/$app"
if [ "${status#*=}" != 0 ] ; then
# The command "systemctl exit $status" sets the return value that will
# be used when the pod exits (via shutdown.service).
# This command is available since systemd v227. On older versions, the
# command will fail and rkt will just exit with return code 0.
${SYSCTL} exit ${status#*=} 2>/dev/null
fi
exit 0
fi
if i run a tester container, and `kill -INT 5` (the `ugh` process), then the container exits properly and the reaper is called
```
root@vagrant-ubuntu-trusty-64:~# rkt run sha512-55af61e90580fb573666d07b3a9c6d09 --interactive
image: using image from file /usr/local/bin/stage1-coreos.aci
image: using image from the store with hash sha512-55af61e90580fb573666d07b3a9c6d098dabc94816681c14495f130ada598a85
networking: loading networks from /etc/rkt/net.d
networking: overriding "default" network with 20-default.conf
networking: loading network default with type bridge
starting up
got a signal! interrupt
bye bye
in the reaper
root@vagrant-ubuntu-trusty-64:~#
```
if i run the tester container, and `kill -INT 1` (the init process), then the container exits poorly and the reaper isn't called
```
root@vagrant-ubuntu-trusty-64:~# rkt run sha512-55af61e90580fb573666d07b3a9c6d09 --interactive
image: using image from file /usr/local/bin/stage1-coreos.aci
image: using image from the store with hash sha512-55af61e90580fb573666d07b3a9c6d098dabc94816681c14495f130ada598a85
networking: loading networks from /etc/rkt/net.d
networking: overriding "default" network with 20-default.conf
networking: loading network default with type bridge
starting up
got a signal! hangup
Failed to retrieve machine ID: No such file or directory
```
the interesting thing about that 'machine-id' error, is that the machine-id actually exists (stage1/rootfs/etc/machine-id) while the pod is running, but seems to be removed at some point in the shutdown process
it's also possible that the machine-id error doesn't manifest, for example, this run
```
root@vagrant-ubuntu-trusty-64:~# rkt run sha512-55af61e90580fb573666d07b3a9c6d09 --interactive
image: using image from file /usr/local/bin/stage1-coreos.aci
image: using image from the store with hash sha512-55af61e90580fb573666d07b3a9c6d098dabc94816681c14495f130ada598a85
networking: loading networks from /etc/rkt/net.d
networking: overriding "default" network with 20-default.conf
networking: loading network default with type bridge
starting up
in the reaper
got a signal! hangup
root@vagrant-ubuntu-trusty-64:~#
```
{
"acKind": "ImageManifest",
"acVersion": "0.7.4",
"app": {
"exec": [
"/usr/bin/ugh"
],
"group": "0",
"user": "0"
},
"dependencies": [
{
"imageName": "registry-1.docker.io/library/ubuntu",
"labels": [
{
"name": "os",
"value": "linux"
},
{
"name": "arch",
"value": "amd64"
},
{
"name": "version",
"value": "14.04.2"
}
]
}
],
"labels": [
{
"name": "arch",
"value": "amd64"
},
{
"name": "os",
"value": "linux"
}
],
"name": "tester"
}
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
handler := make(chan os.Signal, 1)
signal.Notify(handler, syscall.SIGPIPE, syscall.SIGCHLD, syscall.SIGHUP, syscall.SIGALRM, syscall.SIGINT, syscall.SIGTERM)
go func() {
for sig := range handler {
fmt.Printf("got a signal! %v\n", sig)
time.Sleep(20 * time.Second)
fmt.Println("bye bye")
os.Exit(1)
}
}()
fmt.Println("starting up")
time.Sleep(1 * time.Hour)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment