|
| 1 | +# Configuration File |
| 2 | + |
| 3 | +Configuration is used to tell Launch what to do. |
| 4 | + |
| 5 | +It is used to determine where logs go, what processes run and what data needs to be collected. |
| 6 | + |
| 7 | +An example of the configuration file can be obtained by running: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Get example configuration file |
| 11 | +./launch -example-config |
| 12 | +``` |
| 13 | + |
| 14 | +Below is each section of the configuration with the relevant values and details. If you would like more information regarding the configuration all data is layed out in the [configfile folder](../configfile). |
| 15 | + |
| 16 | +## Understanding double rendering |
| 17 | + |
| 18 | +Configuration files have templating built in, see later templating section. This allows for environment variables to be used in the configuration file. |
| 19 | +However many of those environment variables will be collected during the secrets and parameters collection phase. |
| 20 | + |
| 21 | +The configuration file is rendered twice when the Launch is started. |
| 22 | +The first render will be done on start up, it will produce the configuration with the available environment variables as the container starts. |
| 23 | +The Launch will then proceed to collect secrets and parameters. Once complete the configuration is rendered a second time. |
| 24 | +This allows the configuration to make use of parameters and secrets as part of the configuration. Previously blanked environment settings will now be filled in. |
| 25 | + |
| 26 | +An example use case is using an override for hostname in the syslog logging configuration, or setting a environment variable. |
| 27 | + |
| 28 | +Normal templating rules will be followed when using both renders. This means that you can still use the environment variables for secret collection but, they __MUST__ be available when the container starts. Eg. making use of docker -e|--env flags. |
| 29 | +This also means that any templating that makes use of the `required` and `env` functions together __MUST__ be available on the first render or the configuration will fail to render and cause the Launch to stop. |
| 30 | + |
| 31 | +Secrets are only collected once at startup. |
| 32 | + |
| 33 | +## process_manager |
| 34 | + |
| 35 | +`process_manager` configures the Launch process itself. It needs to know where to send it's logs and also if it needs to enable debug logging. |
| 36 | + |
| 37 | +Example: |
| 38 | + |
| 39 | +```yaml |
| 40 | +# Process manager is Launch itself |
| 41 | +process_manager: |
| 42 | + # logging_config is the logging the Launch process needs to use. |
| 43 | + logging_config: |
| 44 | + # This section contains a Logging config _see below_ |
| 45 | + # debug_logging will toggle on and off the debug logger inside |
| 46 | + # the Launch |
| 47 | + debug_logging: (true|false) |
| 48 | + # Debug options should be off by default. Use them only if you need to. |
| 49 | + debug_options: |
| 50 | + # Prints the configuration that will be used for running processes. This happens after secrets are collected |
| 51 | + # and the second config rendering has taken place. |
| 52 | + show_generated_config: (true|false) |
| 53 | +``` |
| 54 | +
|
| 55 | +## processes |
| 56 | +
|
| 57 | +`processes` tells the Launch what start and where to send the logs. There is 3 sections here: secret_processes, init_processes and main_processes |
| 58 | + |
| 59 | +Example: |
| 60 | + |
| 61 | +```yaml |
| 62 | +# processes tells Launch what to start and how. |
| 63 | +processes: |
| 64 | + # Secret processes start before logging so use the console logger. |
| 65 | + # Secrets can export to environment variables and are the only process |
| 66 | + # that can share environment variables. |
| 67 | + secret_processes: |
| 68 | + - name: Process1 |
| 69 | + # Path to executable |
| 70 | + command: /example/bin1 |
| 71 | + # List of arguments |
| 72 | + arguments: |
| 73 | + - --arg1 |
| 74 | + - two |
| 75 | + # How long to allow the process to run. This helps with run away processes. |
| 76 | + termination_timeout_seconds: 60 |
| 77 | + # skip stops this execution if required. |
| 78 | + # Use the template functions to set this value. |
| 79 | + skip: false |
| 80 | + # init_processes start after secrets and run sequentially |
| 81 | + # This is a list and can have as many items as required. |
| 82 | + init_processes: |
| 83 | + # name is a descriptive name for the process. |
| 84 | + - name: first init processes |
| 85 | + # command is the full path to executable |
| 86 | + command: /binary/to/execute |
| 87 | + # List of arguments to pass onto the executable |
| 88 | + arguments: |
| 89 | + # Strings, strings with spaces, and numbers are accepted |
| 90 | + # Add as many as you need |
| 91 | + - -c |
| 92 | + - /tmp/text.txt |
| 93 | + - 10 |
| 94 | + - words and more |
| 95 | + # termination_timeout_seconds how long the grace period is for processes to terminate. |
| 96 | + # The default is 1 second. |
| 97 | + termination_timeout_seconds: 3 |
| 98 | + # logging_config is used to forward on the logs from this process. |
| 99 | + logging_config: |
| 100 | + # This section contains a Logging config _see below_ |
| 101 | + # main_processes looks exactly the same as init_processes. |
| 102 | + main_processes: |
| 103 | + - name: first main |
| 104 | + command: /binary/to/execute |
| 105 | + arguments: |
| 106 | + - -a |
| 107 | + - 1 |
| 108 | + - -b |
| 109 | + - this and that |
| 110 | + logging_config: |
| 111 | + # This section contains a Logging config _see below_ |
| 112 | + - name: second main |
| 113 | + command: /another/binary/to/execute |
| 114 | + arguments: |
| 115 | + - -a |
| 116 | + - 1 |
| 117 | + - -b |
| 118 | + - foo and bar |
| 119 | + logging_config: |
| 120 | + # This section contains a Logging config _see below_ |
| 121 | +``` |
| 122 | + |
| 123 | +## default_logger_config |
| 124 | + |
| 125 | +`default_logger_config` is a section that allows you to put in any defaults that you don't want to repeat. |
| 126 | +It contains a `logging_config` but is intended to allow for all configuration for all engines to be defined here. |
| 127 | + |
| 128 | +Example: |
| 129 | + |
| 130 | +```yaml |
| 131 | +default_logger_config: |
| 132 | + logging_config: |
| 133 | + # This section contains a Logging config _see below_ |
| 134 | +``` |
| 135 | +## Logging |
| 136 | + |
| 137 | +Logging is used to tell the Launch to send logs to a logging engine eg. syslog, console, etc... |
| 138 | + |
| 139 | +Below is the logging configuration. However this is a slightly different one to the rest. |
| 140 | + |
| 141 | +In this configuration you put the details for the logging engine for the process and then select which logging engine you want to make use of. These will appear in all processes. |
| 142 | + |
| 143 | +valid engine names: |
| 144 | + |
| 145 | +- console |
| 146 | +- devnull |
| 147 | +- syslog |
| 148 | +- logfile |
| 149 | + |
| 150 | +Example: |
| 151 | + |
| 152 | +```yaml |
| 153 | +logging_config: |
| 154 | + # Engine is where the logs should go |
| 155 | + engine: any valid engine name from above |
| 156 | + # descriptive name for your binary. Shipped to logging engine if possible. |
| 157 | + process_name: amazing_project |
| 158 | + # Only one of the below is required when used on a process. |
| 159 | + # Normally the one that is related the engine selected. |
| 160 | + # Syslog and file logger both require extra config as below. |
| 161 | + syslog: |
| 162 | + # Overrides the process name with this value. Can be defaulted so all processes that |
| 163 | + # don't have a value set will get this one. |
| 164 | + # If your process does have this or a name you will get the hostname which is ugly. |
| 165 | + # So have at least one of them set. |
| 166 | + program_name: syslog program name |
| 167 | + # Tries to read the log level if specific condition are met |
| 168 | + extract_log_level: (true|false) |
| 169 | + # Override the hostname sent to papertrail |
| 170 | + override_hostname: hostname_to_use |
| 171 | + # These both add the containers hostname to the end of the value they control. |
| 172 | + # remember that you need to add your own separator. |
| 173 | + append_container_name_to_tag: (true|false) |
| 174 | + append_container_name_to_hostname: (true|false) |
| 175 | + file_config: |
| 176 | + # filepath is where to store these logs |
| 177 | + filepath: /var/logs/process_name.log |
| 178 | + # size_limit is how large the file can be before rotation happens. |
| 179 | + size_limit: 100mb |
| 180 | + # historical_files_limit is how many files are to be kept. |
| 181 | + historical_files_limit: 3 |
| 182 | +``` |
| 183 | + |
| 184 | +## Template Functions |
| 185 | + |
| 186 | +Template functions are used to make the configuration files somewhat dynamic. They allow values to be put in place at boot time of the process. Reading and rendering the configuration file is the very first thing Launch will do. Therefore if the configuration does not render correctly then it will not start. |
| 187 | + |
| 188 | +Below is a list of the functions available to you and an example of the syntax used. |
| 189 | + |
| 190 | +`hint: it's just golang's template syntax` |
| 191 | + |
| 192 | +Function | Description | Example |
| 193 | +---|---|--- |
| 194 | +env | Sets the value to an available Environment Variable | {{ env "ENVIRONMENT" }} |
| 195 | +default | Use this default value if function fails | {{ default .NonExisting "default value" }} |
| 196 | +required | This value must be satisfied or the launch will fail | {{ required (env "ALWAYS_THERE") }} |
| 197 | +zerolen | Allows you to check if a value is zero length, returns the value for true or false | {{ zerolen (env "SOMETHING") "true value" "false value" }} |
| 198 | + |
| 199 | +Example in configuration file. |
| 200 | + |
| 201 | +```yaml |
| 202 | +secrets: |
| 203 | + parameter_store: |
| 204 | + - key_path: {{ env "SECRET_PATH" }} |
| 205 | + recursive_lookup: true |
| 206 | + with_decryption: true |
| 207 | + skip: {{ zerolen (env "SECRET_PATH") "true" "false" }} |
| 208 | +``` |
0 commit comments