diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3e538d3..044e0bf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,4 @@ +--- include: https://raw.githubusercontent.com/hassio-addons/organization/master/gitlabci/addon.yml variables: @@ -9,4 +10,4 @@ variables: ADDON_AMD64_BASE: "hassioaddons/base-amd64:3.0.0" ADDON_ARMHF_BASE: "hassioaddons/base-armhf:3.0.0" ADDON_ARMV7_BASE: "hassioaddons/base-armv7:3.0.0" - ADDON_I386_BASE: "hassioaddons/base-i386:3.0.0" \ No newline at end of file + ADDON_I386_BASE: "hassioaddons/base-i386:3.0.0" diff --git a/README.md b/README.md index 565a18e..568a2a2 100644 --- a/README.md +++ b/README.md @@ -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,13 +19,12 @@ [![Buy me a coffee][buymeacoffee-shield]][buymeacoffee] - chrony NTP Server. ## About An NTP server accessible by all hosts on the local network, useful for setting -time on devices with controlled internet access (such as cameras). +time on devices with controlled internet access (such as cameras). Please note this addon will not set the clock of the operating system. ## Installation @@ -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. diff --git a/chrony/.README.j2 b/chrony/.README.j2 index c198bd0..1674332 100644 --- a/chrony/.README.j2 +++ b/chrony/.README.j2 @@ -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! diff --git a/chrony/config.json b/chrony/config.json index 4c3d39d..13cd6cf 100644 --- a/chrony/config.json +++ b/chrony/config.json @@ -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}" diff --git a/chrony/rootfs/etc/chrony/chrony.conf b/chrony/rootfs/etc/chrony/chrony.conf index b34a7b5..1d99eaa 100644 --- a/chrony/rootfs/etc/chrony/chrony.conf +++ b/chrony/rootfs/etc/chrony/chrony.conf @@ -1,5 +1,3 @@ # default config -pool pool.ntp.org iburst -initstepslew 10 pool.ntp.org allow all \ No newline at end of file diff --git a/chrony/rootfs/etc/cont-init.d/10-requirements.sh b/chrony/rootfs/etc/cont-init.d/10-requirements.sh new file mode 100644 index 0000000..3a896c6 --- /dev/null +++ b/chrony/rootfs/etc/cont-init.d/10-requirements.sh @@ -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 \ No newline at end of file diff --git a/chrony/rootfs/etc/cont-init.d/20-configuration.sh b/chrony/rootfs/etc/cont-init.d/20-configuration.sh new file mode 100644 index 0000000..890f7bc --- /dev/null +++ b/chrony/rootfs/etc/cont-init.d/20-configuration.sh @@ -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 \ No newline at end of file