Merge remote-tracking branch 'thingos/dev' into dev

This commit is contained in:
Calin Crisan 2019-01-27 17:39:39 +02:00
commit 30bfb09f74
3 changed files with 62 additions and 24 deletions

View File

@ -1,6 +1,6 @@
date_timeout=10 DATE_TIMEOUT=10
date_method=http DATE_METHOD=http
date_host="google.com" DATE_HOST="google.com"
date_interval=900 DATE_INTERVAL=900
date_ntp_server="" DATE_NTP_SERVER=""

View File

@ -0,0 +1,36 @@
#!/bin/bash
SYS_CONF="/etc/sysctl.conf"
BOOT_CONF="/boot/sysctl.conf"
CONF="/data/etc/sysctl.conf"
PROG="/sbin/sysctl"
test -n "${OS_VERSION}" || source /etc/init.d/base
if [[ ! -f ${CONF} && ! -f ${SYS_CONF} && ! -f ${BOOT_CONF} ]]; then
exit 0
fi
case "$1" in
start)
msg_begin "Applying sysctl parameters"
test -f ${SYS_CONF} && sysctl -q -p ${SYS_CONF}
test -f ${CONF} && sysctl -q -p ${CONF}
test -f ${BOOT_CONF} && sysctl -q -p ${BOOT_CONF}
msg_done
;;
stop)
true
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit $?

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
# Date executable points to /bin/busybox\ date explicitly in the cases that date binary gets overwritten PROG_DATE="/bin/date"
DATE_PROG=/bin/busybox\ date PROG_NTPD="/usr/sbin/ntpd"
PROG_NTPDATE="/usr/sbin/ntpdate"
SYS_CONF="/etc/date.conf" SYS_CONF="/etc/date.conf"
BOOT_CONF="/boot/date.conf" BOOT_CONF="/boot/date.conf"
@ -21,33 +22,34 @@ test -f ${CONF} || exit 0
test "${OS_NETWORKLESS}" == "true" && exit 0 test "${OS_NETWORKLESS}" == "true" && exit 0
date_timeout=10 DATE_TIMEOUT=10
date_method=http DATE_METHOD=http
date_host="google.com" DATE_HOST="google.com"
date_interval="900" DATE_INTERVAL="900"
DATE_NTP_SERVER=""
source ${CONF} source ${CONF}
set_current_date_http() { set_current_date_http() {
date_str=$(curl -v -s -m ${date_timeout} -X GET http://${date_host} 2>&1 | grep Date | sed -e 's/< Date: //') date_str=$(curl -v -s -m ${DATE_TIMEOUT} -X GET http://${DATE_HOST} 2>&1 | grep Date | sed -e 's/< Date: //')
test -z "${date_str}" && return 1 test -z "${date_str}" && return 1
${DATE_PROG} -u -D "%a, %d %b %Y %H:%M:%S" -s "${date_str}" > /dev/null ${PROG_DATE} -u -D "%a, %d %b %Y %H:%M:%S" -s "${date_str}" > /dev/null
return $? return $?
} }
set_current_date_ntp() { set_current_date_ntp() {
cat ${NTP_CONF} | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ntpdate -t ${date_timeout} -s cat ${NTP_CONF} | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ${PROG_NTPDATE} -t ${DATE_TIMEOUT} -s
} }
start_http() { start_http() {
msg_begin "Setting current date using http" msg_begin "Setting current date using http"
set_current_date_http || set_current_date_http set_current_date_http || set_current_date_http
test $? == 0 && msg_done "$(${DATE_PROG})" || msg_fail test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
msg_begin "Starting http date updater" msg_begin "Starting http date updater"
while true; do while true; do
sleep ${date_interval} sleep ${DATE_INTERVAL}
set_current_date_http set_current_date_http
done & done &
msg_done msg_done
@ -58,8 +60,8 @@ start_ntp() {
cat ${NTP_CONF} | grep -v iburst > ${NTP_CONF}.tmp cat ${NTP_CONF} | grep -v iburst > ${NTP_CONF}.tmp
if [[ -n "${date_ntp_server}" ]]; then if [[ -n "${DATE_NTP_SERVER}" ]]; then
echo "server ${date_ntp_server} iburst" > ${NTP_CONF} echo "server ${DATE_NTP_SERVER} iburst" > ${NTP_CONF}
else else
cat ${SYS_NTP_CONF} | grep iburst > ${NTP_CONF} cat ${SYS_NTP_CONF} | grep iburst > ${NTP_CONF}
fi fi
@ -69,10 +71,10 @@ start_ntp() {
msg_begin "Setting current date using ntp" msg_begin "Setting current date using ntp"
set_current_date_ntp || set_current_date_ntp set_current_date_ntp || set_current_date_ntp
test $? == 0 && msg_done "$(${DATE_PROG})" || msg_fail test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
msg_begin "Starting ntpd" msg_begin "Starting ntpd"
ntpd -g -c ${NTP_CONF} ${PROG_NTPD} -g -c ${NTP_CONF}
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }
@ -84,22 +86,22 @@ stop_http() {
stop_ntp() { stop_ntp() {
msg_begin "Stopping ntpd" msg_begin "Stopping ntpd"
killall ntpd &>/dev/null killall -q $(basename ${PROG_NTPD})
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
} }
start() { start() {
if [[ "${date_method}" == "http" ]]; then if [[ "${DATE_METHOD}" == "http" ]]; then
start_http start_http
else else
start_ntp start_ntp
fi fi
echo "system date is $(${DATE_PROG} '+%Y-%m-%d %H:%M:%S')" > /dev/kmsg echo "system date is $(${PROG_DATE} '+%Y-%m-%d %H:%M:%S')" > /dev/kmsg
} }
stop() { stop() {
if [[ "${date_method}" == "http" ]]; then if [[ "${DATE_METHOD}" == "http" ]]; then
stop_http stop_http
else else
stop_ntp stop_ntp