Commit 30e083d8 authored by Martin Peres's avatar Martin Peres
Browse files

initscript: allow setting the time using ntp

parent 563676d9
......@@ -60,6 +60,11 @@ Here is a list of options:
* none (default): Do not use any cache, guaranteeing a fresh environment every time
* auto: Re-use a previously-setup drive, or pick a suitable one, and partition it! (**WILL ERASE YOUR DATA**)
* /dev/XXX: A path to a block device, or a partition. If the path is to a block device and it does not have a partition labeled `B2C_CACHE`, it will recreate the partition table and format the partition. If the path is to a partition, it will use it directly if it is labeled `B2C_CACHE`, otherwise it will reformat it. (**WILL ERASE YOUR DATA**)
* **b2c.ntp_peer**: Set the clock on boot by querying the specified NTP server.
The value can be an IP address, a fully qualified name, or one of the
following values:
* none (default): Do not set the time at boot
* auto: Use `pool.ntp.org` as a peer
## How to?
......
......@@ -49,6 +49,7 @@ ARG_MODULES=""
ARG_CONTAINER=""
ARG_POST_CONTAINER=""
ARG_CACHE_DEVICE="none"
ARG_NTP_PEER="none"
function parse_cmdline {
cmdline=$(busybox cat /proc/cmdline)
......@@ -75,6 +76,9 @@ function parse_cmdline {
b2c.post_container=*)
ARG_POST_CONTAINER="$ARG_POST_CONTAINER$value\n"
;;
b2c.ntp_peer=*)
ARG_NTP_PEER=$value
;;
esac
done
IFS=$OLDIFS
......@@ -100,6 +104,27 @@ function connect {
log "Getting IP: DONE"
}
function ntp_set {
case $1 in
none)
log "WARNING: Did not reset the time, use b2c.ntp_peer=auto to set it on boot"
return 0
;;
auto)
peer_addr="pool.ntp.org"
;;
*)
peer_addr=$1
esac
# Limit the maximum execution time to prevent the boot sequence to be stuck
# for too long
status="DONE"
time timeout 5 ntpd -dnq -p "$peer_addr" || status="FAILED"
log "Getting the time from the NTP server $peer_addr: DONE"
}
function find_container_partition {
dev_name=`blkid | grep "LABEL=\"$CACHE_PARTITION_LABEL\"" | head -n 1 | cut -d ':' -f 1`
if [ -n "$dev_name" ]; then
......@@ -325,6 +350,9 @@ load_modules $ARG_MODULES
# Connect to the network, now that the modules are loaded
connect
# Set the time
ntp_set $ARG_NTP_PEER
# Mount the cache partition
mount_cache_partition
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment