| [Unit] |
| Description=Docker container for {{ name }} |
| Requires=docker.service |
| After=docker.service |
| |
| {#- Ugly, but covers the cases where variable evaluates to false, is empty, or non-existent #} |
| {%- set runoptions = container.get("runoptions") or [] %} |
| {%- set stopoptions = container.get("stopoptions") or [] %} |
| {%- set cmd = container.get("cmd") or "" %} |
| |
| {%- if runoptions == "None" %} |
| {%- set runoptions = [] %} |
| {%- endif %} |
| |
| {%- if cmd == "None" %} |
| {%- set cmd = "" %} |
| {%- endif %} |
| |
| |
| [Service] |
| Restart=always |
| ExecStart=/usr/bin/docker run -d {% for option in runoptions %}{{ option }} {% endfor %} --name={{ name }} {{ container.image }} {{ cmd }} |
| ExecStop=/usr/bin/docker stop {{ name }} |
| ExecStopPost=/usr/bin/docker rm -f {{ name }} |
| |
| [Install] |
| WantedBy=local.target |