{"id":26246417,"url":"https://github.com/mittwald/mittnite","last_synced_at":"2025-04-23T20:28:12.675Z","repository":{"id":40302103,"uuid":"186792863","full_name":"mittwald/mittnite","owner":"mittwald","description":"Small init system with templated config files; to be used as container entrypoint","archived":false,"fork":false,"pushed_at":"2025-03-13T02:01:55.000Z","size":407,"stargazers_count":33,"open_issues_count":7,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T03:11:55.119Z","etag":null,"topics":["containers","golang","init-system"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mittwald.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-15T09:21:52.000Z","updated_at":"2025-03-11T08:41:10.000Z","dependencies_parsed_at":"2024-06-19T00:24:40.425Z","dependency_job_id":"2d3e0f17-fb68-47f6-9a58-0858c95d1feb","html_url":"https://github.com/mittwald/mittnite","commit_stats":{"total_commits":125,"total_committers":12,"mean_commits":"10.416666666666666","dds":0.72,"last_synced_commit":"0cf509cdf930e470a201c888500201d57697637a"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mittwald%2Fmittnite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mittwald%2Fmittnite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mittwald%2Fmittnite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mittwald%2Fmittnite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mittwald","download_url":"https://codeload.github.com/mittwald/mittnite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250508497,"owners_count":21442238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["containers","golang","init-system"],"created_at":"2025-03-13T13:18:29.165Z","updated_at":"2025-04-23T20:28:12.651Z","avatar_url":"https://github.com/mittwald.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/mittwald/mittnite.svg?branch=master)](https://travis-ci.com/mittwald/mittnite)\n\n# Mittnite - Smart init system for containers\n\nMittnite is a small, but smart init system designed for usage as `ENTRYPOINT` in container images.\n\nIt offers the following features:\n\n- Render configuration files from templates using Go's [`text/template`](https://golang.org/pkg/text/template/) engine.\n- Start processes and manage their lifecycle\n- Watch configuration files and send configurable signals to processes on change\n- Wait until required services are up before starting processes (currently supporting filesystem mounts, HTTP services, MySQL, Redis, AMQP and MongoDB)\n\n## Table of contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Getting started](#getting-started)\n  - [CLI usage](#cli-usage)\n    - [Basic](#basic)\n    - [Render templates and execute custom command](#render-templates-and-execute-custom-command)\n  - [Docker](#docker)\n    - [Build your (go) application on top of the `mittnite` docker-image](#build-your-go-application-on-top-of-the-mittnite-docker-image)\n    - [Download `mittnite` in your own custom `Dockerfile`](#download-mittnite-in-your-own-custom-dockerfile)\n- [Configuration](#configuration)\n  - [Directives](#directives)\n    - [Job](#job)\n    - [Boot Jobs](#boot-jobs)\n    - [File](#file)\n    - [Probe](#probe)\n  - [HCL examples](#hcl-examples)\n    - [Start a process](#start-a-process)\n    - [Start a process lazily on first request](#start-a-process-lazily-on-first-request)\n    - [Render a file on startup](#render-a-file-on-startup)\n    - [Wait until a Redis connection is possible](#wait-until-a-redis-connection-is-possible)\n  - [More examples](#more-examples)\n- [mittnitectl](#mittnitectl)\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Getting started\n\n### CLI usage\n\n#### Basic\n```bash\n$ mittnite --help\n\nMittnite is a small, but smart init system designed for usage as `ENTRYPOINT` in container images\n\nUsage:\n  mittnite [flags]\n  mittnite [command]\n\nAvailable Commands:\n  help        Help about any command\n  renderfiles\n  up\n  version     Show extended information about the current version of mittnite\n\nFlags:\n  -c, --config-dir string   set directory to where your .hcl-configs are located (default \"/etc/mittnite.d\")\n  -h, --help                help for mittnite\n\nUse \"mittnite [command] --help\" for more information about a command.\n```\n\n#### Render templates and execute custom command\nThis will render all template files and execute the `sleep 10` afterwards.\n```bash\n$ mittnite renderfiles sleep 10\n```\n\n### Docker\n#### Build your (go) application on top of the `mittnite` docker-image\nIn order to run your own static application - e.g. a `golang`-binary with `mittnite`, we recommend to inherit the `mittnite` docker-image and copy your stuff on top.\n```dockerfile\nFROM            quay.io/mittwald/mittnite:stable\nCOPY            mittnite.d/ /etc/mittnite.d/\nCOPY            myApplication /usr/local/bin/\n# ENTRYPOINT and CMD are optional, because they are inherited by parent image\n```\n\n#### Download `mittnite` in your own custom `Dockerfile`\nIf you'd like to use `mittnite` for non-static applications like `node` or similar, you can download the `mittnite`-binary from Github.\n```dockerfile\nFROM        node:12-alpine\nENV         MITTNITE_VERSION=\"1.1.2\"\nRUN         wget -qO- https://github.com/mittwald/mittnite/releases/download/v${MITTNITE_VERSION}/mittnite_${MITTNITE_VERSION}_linux_x86_64.tar.gz \\\n                | tar xvz -C /usr/bin mittnite \u0026\u0026 \\\n            chmod +x /usr/bin/mittnite\nCOPY        mittnite.d/ /etc/mittnite.d/\nENTRYPOINT  [\"/usr/bin/mittnite\"]\nCMD         [\"up\",\"--config-dir\", \"/etc/mittnite.d\"]\n```\n\n## Configuration\n\nThe directory specified with `--config-dir`, or the shorthand `-c`, can contain any number of `.hcl` configuration files.\n\nAll files in that directory are loaded by `mittnite` on startup and can contain any of the configuration directives.\n\n### Directives\n\n#### Job\n\nA `Job` describes a runnable process that should be started by mittnite on startup.\n\nA `Job` consists of a `command` and (optional) `args`. When a process started by a Job fails, it will be restarted for a maximum of `maxAttempts` attempts. If it fails for more than `maxAttempts` time, mittnite itself will terminate to allow your container runtime to handle the failure.\n\n```hcl\njob \"foo\" {\n  command = \"/usr/local/bin/foo\"\n  args = [\"bar\"]\n  maxAttempts = 3\n  canFail = false\n  workingDirectory = \"/some/path\"\n}\n```\n\nSet `maxAttempts` to `-1` will restart the process \"forever\".\n\n```hcl\njob \"foo\" {\n  command = \"/usr/local/bin/foo\"\n  args = [\"bar\"]\n  maxAttempts = -1\n  canFail = false\n  workingDirectory = \"/some/path\"\n}\n```\n\nYou can append a custom environment to the process by setting `env`:\n\n```hcl\njob \"foo\" {\n  command = \"/usr/local/bin/foo\"\n  args = [\"bar\"]\n  env = [\"ENABLED=1\", \"BAR=\\\"BAZ\\\"\"]\n  maxAttempts = 3\n  canFail = false\n}\n```\n\nTo redirect the output of a job to a separate file, `stdout` and/or `stderr` can be specified:\n\n```hcl\njob \"foo\" {\n  command = \"/usr/local/bin/foo\"\n  args = [\"bar\"]\n  stdout = \"/tmp/foo.log\"\n  stderr = \"/tmp/foo-errors.log\"\n}\n```\n\nAdditionally, you can enable timestamps for the output of a job using `enableTimestamps` and specify a custom format using `timestampFormat`.\n\nFormats are named after their constant name in the Golang [`time` package](https://pkg.go.dev/time#pkg-constants) (lookup table at the bottom).\n\nYou can also specify your own format by setting `customTimestampFormat` to a custom format string like \"2006-01-02 15:04:05\". Whatever is set in `timestampFormat` will be ignored in that case.\n\n```hcl\njob \"foo\" {\n  command = \"/usr/local/bin/foo\"\n  args = [\"bar\"]\n  stdout = \"/tmp/foo.log\"\n  stderr = \"/tmp/foo-errors.log\"\n  enableTimestamps = true\n  timestampFormat = \"RFC3339\"  # default\n  customTimestampFormat = \"\"  # default\n}\n```\n\nYou can configure a Job to watch files and to send a signal to the managed process if that file changes. This can be used, for example, to send a `SIGHUP` to a process to reload its configuration file when it changes.\n  \n```hcl\njob \"foo\" {\n  // ...\n\n  watch \"/etc/conf.d/barfoo\" {\n    signal = 12\n  }\n}\n```\n\nIf the running process cannot handle a signal to reload the configuration, the `restart` parameter can be set to `true`. In this case the specified `signal` will be sent to gracefully terminate the process and restart it afterwards:\n\n```hcl\njob \"foo\" {\n  // ...\n\n  watch \"/etc/conf.d/barfoo\" {\n    signal = 15 # SIGTERM\n    restart = true\n  }\n}\n```\n\nIn addition, it is possible to execute a command before and/or after signaling.\nThis command should not modify the file being watched, otherwise the watcher might enter an infinite loop.\n\n```hcl\njob \"foo\" {\n  // ...\n\n  watch \"/etc/conf.d/barfoo\" {\n    signal = 12\n\n    preCommand {\n      command = \"echo\"\n      args = [\"before\"]\n    }\n\n    postCommand {\n      command = \"echo\"\n      args = [\"after\"]\n    }\n  }\n}\n```\n\nYou can also configure a Job to start its process only on the first incoming request (a bit like [systemd's socket activation](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)). In order to configure this, you need a `listener` and a `lazy` configuration:\n\n```hcl\njob \"foo\" {\n  command = \"http-server\"\n  args = [\"-p8081\", \"-a127.0.0.1\"]\n\n  lazy {\n    spinUpTimeout = \"5s\"\n    coolDownTimeout = \"15m\"\n  }\n\n  listen \"0.0.0.0:8080\" {\n    forward = \"127.0.0.1:8081\"\n  }\n}\n```\n\nThe `listen` block will instruct mittnite itself to listen on the specified address; each connection accepted on that port will be forwarded to the address specified by `forward` (**NOTE**: mittnite will do some simple layer-4 forwarding; if your upstream service depends on working with the actual client IP addresses, you'll only see the local IP address).\n\nIf there is a `lazy` block present, the process itself will only be started when the first connection is opened. If the process takes some time to start up, the connection will be held for that time (the client will not notice any of this, except for the time the process needs to spin up). mittnite will wait for a duration of at most `.lazy.spinUpTimeout` for the process to accept connection; if this timeout is exceeded, the client connection will be closed.\n\nWhen no connections have been active for a duration of at least `.lazy.coolDownTimeout`, mittnite will terminate the process again.\n\n#### Boot Jobs\n\nBoot jobs are \"special\" jobs that are executed before regular `job` definitions. Boot jobs are required to run to completion before any regular jobs are started.\n\n```hcl\nboot \"setup\" {\n  command = \"/bin/bash\"\n  args = [\"/init-script.sh\"]\n  timeout = \"30s\"\n  env = [\n    \"FOO=bar\"\n  ]\n}\n```\n\n#### File\n\nPossible directives to use in a file definition.\n\n```hcl\nfile \"/path/to/file.txt\" {\n  from = \"examples/test.d/test.txt.tpl\"\n  params = {\n    foo = \"bar\"\n  }\n}\n\nfile \"/path/to/second_file.txt\" {\n  from = \"examples/test.d/second_test.txt.tpl\"\n  overwrite = false\n  params = {\n    foo = \"bar\"\n  }\n}\n```\n\nFiles are rendered using Golang's [text rendering engine][].\nThe rendering capabilities have been enhanced with\n[sprig][] functions. The `env` function has been removed\nas environment variables can be accessed via the *Env*\ntemplate variable.\n\n```\nsome.param = {{ .Params.foo | default \"bac\" }}\nsome.env = {{ .Env.USER | upper }}\nsecret = {{ randAlphaNum 16 }}\n```\n\n[text rendering engine]: https://pkg.go.dev/text/template\n[sprig]: https://github.com/Masterminds/sprig\n\n#### Probe\n\nPossible directives to use in a probe definition.\n\n```hcl\nprobe \"redis\" {\n  wait = true\n  redis {\n    host = {\n      hostname = \"localhost\"\n      port = 6379\n    }\n    password = \"secret\"\n  }\n}\n\nprobe \"smtp\" {\n  wait = true\n  smtp {\n    host = {\n      hostname = \"localhost\"\n      port = 25\n    }\n  }\n}\n\nprobe \"mysql\" {\n  wait = true\n  mysql {\n    host = {\n      hostname = \"localhost\"\n      port = 3306\n    }\n    credentials = {\n      user = \"foo\"\n      password = \"bar\"\n    }\n  }\n}\n \nprobe \"amqp\" { \n  wait = true\n  amqp {\n    host = {\n      hostname = \"localhost\"\n      port = 5672\n    }\n    credentials = {\n      user = \"foo\"\n      password = \"bar\"\n    }\n    virtualhost = \"amqp.localhost.com\"\n  }\n}\n \nprobe \"mongodb\" {\n  wait = true \n  mongodb {\n    url = \"mongodb://localhost:27017/mongo\"\n  }\n}\n  \nprobe \"http\" {\n  wait = true\n  http {\n    scheme = \"http\"\n    host = {\n        hostname = \"localhost\"\n        port = 8080\n    }\n    path = \"/status\"\n    timeout = \"5s\"\n  }\n}\n\nprobe \"some-file\" {\n  wait = true\n  filesystem = \"/path/to/some/dir\"\n}\n```\n\nSpecifying a `port` is optional and defaults to the services default port.\n\n### HCL examples\n\n#### Start a process\n\n```hcl\njob webserver {\n  command = \"/usr/bin/http-server\"\n\n  watch \"/etc/conf.d/*.conf\" {\n    signal = 12 # USR2\n  }\n}\n```\n\n#### Start a process lazily on first request\n\n```hcl\njob webserver {\n  command = \"/usr/bin/http-server\"\n  args = [\"-p8081\", \"-a127.0.0.1\"]\n\n  lazy {\n    spinUpTimeout = \"5s\"\n    coolDownTimeout = \"15m\"\n  }\n\n  listen \"0.0.0.0:8080\" {\n    forward = \"127.0.0.1:8081\"\n  }\n}\n```\n\n#### Render a file on startup\n\n```hcl\nfile \"/etc/conf.d/test.txt\" {\n  from = \"examples/test.d/test.txt.tpl\"\n\n  params = {\n    foo = \"bar\"\n  }\n}\n```\n\n#### Wait until a Redis connection is possible\n\n```hcl\nprobe redis {\n  wait = true\n  redis {\n    host = {\n      hostname = \"localhost\"\n      port = 6379\n    }\n  }\n}\n```\n\n### More examples\nMore example files can be found in the [examples directory](examples/)\n\n## mittnitectl\n\n`mittnitectl` can be used to control the mittnite process as long as the required API is enabled (`mittnite up --api`).\nCurrently, it is possible to _start_, _stop_, _restart_ jobs and display the current _status_.\n\n```shell\n$ mittnitectl --help\nThis command can be used to control mittnite by command line.\n\nUsage:\n  mittnitectl [command]\n\nAvailable Commands:\n  help        Help about any command\n  job         Control a job via command line\n  version     Show extended information about the current version of mittnite\n\nFlags:\n      --api-address string   write mittnites process id to this file (default \"unix:///tmp/mittnite/mittnite.sock\")\n  -h, --help                 help for mittnitectl\n\nUse \"mittnitectl [command] --help\" for more information about a command.\n```\n```shell\n$ mittnitectl job --help\nThis command can be used to control a managed job.\n\nUsage:\n  mittnitectl job [command]\n\nAvailable Commands:\n  list        List jobs\n  logs        Get logs from job\n  restart     Restart a job\n  start       Start a job\n  status      Show job status\n  stop        Stop a job\n\nFlags:\n  -h, --help   help for job\n\nGlobal Flags:\n      --api-address string   write mittnites process id to this file (default \"unix:///var/run/mittnite.sock\")\n\nUse \"mittnitectl job [command] --help\" for more information about a command.\n```\n\n\n### job\n\nTo control a job, it must have set the `controllable` flag:\n\n```hcl\njob webserver {\n  # ...\n  controllable = true\n  # ...\n}\n```\n\n### Timestamp Formats\n\n| Name        | Format                              |\n|-------------|-------------------------------------|\n| Layout      | 01/02 03:04:05PM '06 -0700          |\n| ANSIC       | Mon Jan _2 15:04:05 2006            |                                             \n| UnixDate    | Mon Jan _2 15:04:05 MST 2006        |                                         \n| RubyDate    | Mon Jan 02 15:04:05 -0700 2006      |                                       \n| RFC822      | 02 Jan 06 15:04 MST                 |                                                  \n| RFC822Z     | 02 Jan 06 15:04 -0700               |                    \n| RFC850      | Monday, 02-Jan-06 15:04:05 MST      |                                       \n| RFC1123     | Mon, 02 Jan 2006 15:04:05 MST       |                                        \n| RFC1123Z    | Mon, 02 Jan 2006 15:04:05 -0700     |         \n| RFC3339     | 2006-01-02T15:04:05Z07:00           |                                            \n| RFC3339Nano | 2006-01-02T15:04:05.999999999Z07:00 |                                  \n| Kitchen     | 3:04PM                              |                                                               \n| Stamp       | Jan _2 15:04:05                     |                                                       \n| StampMilli  | Jan _2 15:04:05.000                 |                                                   \n| StampMicro  | Jan _2 15:04:05.000000              |                                                \n| StampNano   | Jan _2 15:04:05.000000000           |                                             \n| DateTime    | 2006-01-02 15:04:05                 |                                                   \n| DateOnly    | 2006-01-02                          |                                                            \n| TimeOnly    | 15:04:05                            |         \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmittwald%2Fmittnite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmittwald%2Fmittnite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmittwald%2Fmittnite/lists"}