Ability to configure pool/servers

This commit is contained in:
Paul Sinclair 2019-03-17 11:41:03 -04:00
parent 8f1323fed0
commit a17cd3dcd8
No known key found for this signature in database
GPG key ID: 779C7A23E1AA845D
7 changed files with 99 additions and 13 deletions

View file

@ -1,3 +1,4 @@
---
include: https://raw.githubusercontent.com/hassio-addons/organization/master/gitlabci/addon.yml
variables:

View file

@ -1,6 +1,5 @@
# Community Hass.io Add-ons: chrony
[![GitHub Release][releases-shield]][releases]
![Project Stage][project-stage-shield]
[![License][license-shield]](LICENSE.md)
@ -20,7 +19,6 @@
[![Buy me a coffee][buymeacoffee-shield]][buymeacoffee]
chrony NTP Server.
## About
@ -35,9 +33,9 @@ The installation of this add-on is pretty straightforward and not different in
comparison to installing any other Hass.io add-on.
1. [Add our Hass.io add-ons repository][repository] to your Hass.io instance.
2. Install the "chrony" add-on.
3. Start the "chrony" add-on
4. Check the logs of the "chrony" add-on to see if everything went well.
1. Install the "chrony" add-on.
1. Start the "chrony" add-on
1. Check the logs of the "chrony" add-on to see if everything went well.
**NOTE**: Do not add this repository to Hass.io, please use:
`https://github.com/hassio-addons/repository`.
@ -74,6 +72,26 @@ more severe level, e.g., `debug` also shows `info` messages. By default,
the `log_level` is set to `info`, which is the recommended setting unless
you are troubleshooting.
### Option: `mode`
The `mode` option configures chrony to use either `pool` or `server` mode.
These options are:
- `pool`: References a pool of servers such as pool.ntp.org (Recommended).
- `server`: References a list of specific names or addresses.
Based on the mode the `ntp_pool` or `ntp_server` option will be used.
### Option: `ntp_pool`
Used by pool mode and configures the pool name to be used, should be a DNS
record with multiple entries. The application will select which to reference.
### Option: `ntp_server`
Used by server mode, an array of server names or IP Addresses used as the
time source. The application will select which to reference.
## Known issues and limitations
- This does not control the local system time and is purely an NTP server.

View file

@ -15,8 +15,6 @@ time on devices with controlled internet access (such as cameras).
[Click here for the full documentation][docs]
![Grocy screenshot][screenshot]
{% if channel == "edge" %}
## WARNING! THIS IS AN EDGE VERSION!

View file

@ -19,9 +19,16 @@
"ports": {
"123/udp": 123
},
"options": { },
"options": {
"mode": "pool",
"ntp_pool": "pool.ntp.org",
"ntp_server": ["54.39.13.155","briareus.schulte.org"]
},
"schema": {
"log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?"
"log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?",
"ntp_pool": "str?",
"ntp_server": ["str?"],
"mode": "match(^(pool|server)$)"
},
"environment": {
"LOG_FORMAT": "{LEVEL}: {MESSAGE}"

View file

@ -1,5 +1,3 @@
# default config
pool pool.ntp.org iburst
initstepslew 10 pool.ntp.org
allow all

View file

@ -0,0 +1,37 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: chrony
# This files check if all user configuration requirements are met
# ==============================================================================
# Check running mode
if bashio::config.equals 'mode' 'pool' \
&& bashio::config.is_empty 'ntp_pool';
then
bashio::log.fatal
bashio::log.fatal 'Configuration of this add-on is incomplete.'
bashio::log.fatal
bashio::log.fatal 'pool mode is configured but the ntp_pool'
bashio::log.fatal 'is empty'
bashio::log.fatal
bashio::log.fatal 'If using pool mode please set the'
bashio::log.fatal '"ntp_pool" option in the add-on'
bashio::log.fatal 'configuration.'
bashio::log.fatal
bashio::exit.nok
fi
if bashio::config.equals 'mode' 'server' \
&& bashio::config.is_empty 'ntp_server';
then
bashio::log.fatal
bashio::log.fatal 'Configuration of this add-on is incomplete.'
bashio::log.fatal
bashio::log.fatal 'server mode is configured but the ntp_server'
bashio::log.fatal 'is empty'
bashio::log.fatal
bashio::log.fatal 'If using server mode please set the'
bashio::log.fatal '"ntp_server" option in the add-on'
bashio::log.fatal 'configuration.'
bashio::log.fatal
bashio::exit.nok
fi

View file

@ -0,0 +1,27 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: chrony
# This files configures the conf file from the options set
# ==============================================================================
readonly CHRONY_CONF='/etc/chrony/chrony.conf'
readonly NTPMODE=$(bashio::config 'mode')
declare configline
if bashio::config.equals 'mode' 'pool';
then
readonly SOURCE=$(bashio::config 'ntp_pool')
elif bashio::config.equals 'mode' 'server';
then
readonly SOURCE=$(bashio::config 'ntp_server')
fi
for server in ${SOURCE}; do
configline=${NTPMODE}
configline+=" "
configline+=$server
configline+=" iburst"
bashio::log.debug "Setting config to ${configline}"
echo >> ${CHRONY_CONF}
echo "${configline}" >> ${CHRONY_CONF}
done