Skip to content

Instantly share code, notes, and snippets.

@arthurgeek
Last active December 30, 2015 20:57
Show Gist options
  • Select an option

  • Save arthurgeek/b87a70d59b03af04a1ad to your computer and use it in GitHub Desktop.

Select an option

Save arthurgeek/b87a70d59b03af04a1ad to your computer and use it in GitHub Desktop.

Revisions

  1. arthurgeek revised this gist Dec 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions application.service
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@
    Description=My application

    # Requirements
    Requires=etcd.service
    Requires=etcd2.service
    Requires=docker.service

    # Dependency ordering
    After=etcd.service
    After=etcd2.service
    After=docker.service

    [Service]
  2. arthurgeek created this gist Dec 30, 2015.
    43 changes: 43 additions & 0 deletions application.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    [Unit]
    Description=My application

    # Requirements
    Requires=etcd.service
    Requires=docker.service

    # Dependency ordering
    After=etcd.service
    After=docker.service

    [Service]
    # Let processes take awhile to start up (for first run Docker containers)
    TimeoutStartSec=0

    # Change killmode from "control-group" to "none" to let Docker remove
    # work correctly.
    KillMode=none

    # Run as user core, which have the necessary credentials for pulling from
    # private registry
    User=core

    # Environment variables to DRY up config
    Environment=APPLICATION=my-app
    Environment=IMAGE=user/my-app

    # Pre-start and Start
    ## Directives with "=-" are allowed to fail without consequence
    ExecStartPre=-/usr/bin/docker kill $APPLICATION
    ExecStartPre=-/usr/bin/docker rm $APPLICATION
    ExecStartPre=/usr/bin/docker pull $IMAGE

    ## The run command gets all config variables from etcd and construct the
    ## docker run command passing all variables
    ExecStart=/bin/sh -c '/usr/bin/docker run --name $APPLICATION \
    $(for e in $(etcdctl ls /daemons/config/$APPLICATION); do \
    echo "-e $(basename $e)=$(etcdctl get $e) "; \
    done) \
    $IMAGE'

    # Stop
    ExecStop=/usr/bin/docker stop $APPLICATION