Giter Site home page Giter Site logo

lifecycle's Introduction

Application (Container) Lifecycle on resin.io:

Note: This project was run on resinOS 1.24.1 and 2.0.0-beta10.rev1 on the Raspberry Pi 3. On older versions, its not guaranteed that the signals will be propagated from docker to the container as these things were changed in recent versions (I think around 1.11+).

This project catches the SIGTERM signal when the container is restarted or the device is rebooted from the dashboard. Obviously if you yank the power out, you won't get an SIGTERM. The python project both tries to print to screen and write to a file when it catches the SIGTERM. Sometime it won't send the print statement to the logs fast enough, but hopefully should always write to the file.

If you are using a bash script to start your code, you will need to trap the SIGTERM in the bash script and propagate it onto the child processes (unless systemd is enables, then I believe this will be handled for you.) For more info on how to do this, check out this article: http://veithen.github.io/2014/11/16/sigterm-propagation.html

Example Output with systemd enabled:

17.02.17 18:57:02 [+0000] Started application 'registry.resinstaging.io/rpi3/123deadbeeef'
17.02.17 18:57:02 [+0000] Systemd init system enabled.
17.02.17 18:57:02 [+0000] systemd 215 running in system mode. (+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCO
MP -APPARMOR)
17.02.17 18:57:02 [+0000] Detected virtualization 'other'.
17.02.17 18:57:02 [+0000] Detected architecture 'arm'.
17.02.17 18:57:02 [+0000] Set hostname to <dad94d5-dad94d5>.
17.02.17 18:57:05 [+0000] my pid is 156
17.02.17 18:57:05 [+0000] RESIN envvars
17.02.17 18:57:05 [+0000]
17.02.17 18:57:05 [+0000] RESIN 1
17.02.17 18:57:05 [+0000] RESIN_APP_ID 18002
17.02.17 18:57:05 [+0000] RESIN_SUPERVISOR_ADDRESS http://127.0.0.1:48484
17.02.17 18:57:05 [+0000] RESIN_SUPERVISOR_VERSION 3.0.0
17.02.17 18:57:05 [+0000] RESIN_APP_NAME rpi3
17.02.17 18:57:05 [+0000] RESIN_SUPERVISOR_PORT 48484
17.02.17 18:57:05 [+0000] RESIN_SUPERVISOR_API_KEY cdeadbeef4449fe8b3034dbeefeea5eef23e123452d7fce912c83ea7
17.02.17 18:57:05 [+0000] RESIN_DEVICE_UUID dad94d5f6fea724b1f1374f14304d4f6e0f88c8bfa2f8a31608f845eefef83
17.02.17 18:57:05 [+0000] RESIN_DEVICE_NAME_AT_INIT restless-star
17.02.17 18:57:05 [+0000] RESIN_HOST_OS_VERSION Resin OS 2.0.0-beta10.rev1
17.02.17 18:57:05 [+0000] RESIN_SUPERVISOR_HOST 127.0.0.1
17.02.17 18:57:05 [+0000] RESIN_DEVICE_TYPE raspberrypi3
17.02.17 18:57:05 [+0000] RESIN_APP_RELEASE 123deadbeeef
17.02.17 18:57:05 [+0000] Now I'm just gonna wait around here for something to happen...
17.02.17 18:57:15 [+0000] still waiting around...
17.02.17 18:57:25 [+0000] still waiting around...
17.02.17 18:57:35 [+0000] still waiting around...
17.02.17 18:57:45 [+0000] still waiting around...
17.02.17 18:57:15 [+0000] still waiting around...
17.02.17 18:57:25 [+0000] still waiting around...
17.02.17 18:57:35 [+0000] still waiting around...
17.02.17 18:57:45 [+0000] still waiting around...
17.02.17 18:57:55 [+0000] still waiting around...
17.02.17 18:58:03 [+0000] Updating application 'registry.resinstaging.io/rpi3/123deadbeeef'
17.02.17 18:58:03 [+0000] Killing application 'registry.resinstaging.io/rpi3/123deadbeeef'
17.02.17 18:58:03 [+0000] got SIGTERM
17.02.17 18:58:03 [+0000]
17.02.17 18:58:03 [+0000] Sending SIGTERM to remaining processes...
17.02.17 18:58:03 [+0000] Sending SIGKILL to remaining processes...
17.02.17 18:58:03 [+0000] Unmounting file systems.
17.02.17 18:58:03 [+0000] Unmounting /sys/kernel/debug.
17.02.17 18:58:03 [+0000] Unmounting /dev/mqueue.
17.02.17 18:58:03 [+0000] All filesystems unmounted.
17.02.17 18:58:03 [+0000] Halting system.
17.02.17 18:58:03 [+0000]
17.02.17 18:58:03 [+0000] Application exited 'registry.resinstaging.io/rpi3/123deadbeeef'

lifecycle's People

Contributors

shaunmulligan avatar

Watchers

James Cloos avatar

Forkers

nghiant2710

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.