WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TC9.0 /etc/init.d/settime.sh broken  (Read 957 times)

Offline y_satou70

  • WikiUser
  • *
  • Posts: 11
Re: TC9.0 /etc/init.d/settime.sh broken
« Reply #15 on: July 27, 2018, 11:22:33 AM »
also logically this part is also wrong in /etc/init.d/tc-config:

Code: [Select]
# After restore items
if [ -n "$NODHCP" ]; then
echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
else
[ -z "$DHCP_RAN" ] && /etc/init.d/dhcp.sh &
[ -z "$NORTC" ] || /etc/init.d/settime.sh &
fi

by this logic, settime.sh won't be ran if "nodhcp" is set in boot option.
settime.sh has dependency for network availability (as it tries to set time by NTP), but network availability shouldn't be depending on using DHCP or not. Even static IP + gateway/route setting (use /etc/init.d/rcS as described in http://forum.tinycorelinux.net/index.php?topic=21290.0), network becomes working state, then enable to sync time with NTP.

so my proposal is

Code: [Select]
--- tc-config.orig
+++ tc-config
@@ -613,8 +613,8 @@
  echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
 else
  [ -z "$DHCP_RAN" ] && /etc/init.d/dhcp.sh &
- [ -z "$NORTC" ] || /etc/init.d/settime.sh &
 fi
+[ -n "$NTPSERVER" ] && /etc/init.d/settime.sh &

 [ -n "$CRON" ] && /etc/init.d/services/crond start

--- settime.sh.orig
+++ settime.sh
@@ -16,14 +16,6 @@
     NRT=0
     while sleep 0
     do
-        XXX=$(/bin/date -I)
-        XXX=${XXX:0:4}
-
-        if [ "$XXX" -ge "2015" ];
-        then
-            break
-        fi
-
         if [ $CNT -gt 10 ];
         then
             /usr/bin/getTime.sh
tc@tc-008064c770c2:/etc/init.d$

and the rule is:

* if want to skip (do not want) setting OS/kernel time from RTC/hardware clock, then set "nortc"
* if want to set OS/kernel time from NTPserver, then set "ntpserver=(IPaddr)" or "ntpserver=(FQDN)"

do we see any problem with this rule for RPi devices ?

Offline centralware

  • Sr. Member
  • ****
  • Posts: 313
Re: TC9.0 /etc/init.d/settime.sh broken
« Reply #16 on: July 29, 2018, 03:19:08 AM »
Attempting to maintain everyone's input with the option to skip everything (ie: if there's no NIC detected settime.sh would be a waste of effort/time)
I've also added to my notes (for a later date) to consider DHCP NTP option (especially if there's a local NTP!) and a few other items.
  • To manually force the ntp call, settime.sh -m
  • To force the call at boot time, add ntpserver=time.server.uri as a boot code
  • To prevent the call at boot time, add nosettime as a boot code
  • If nortc is a boot code, it's assumed settime will call ntp
  • If it's a RasPi and YEAR -le 2015, assume the call to ntp

Code: [Select]
#!/bin/sh

##############
# SetTime.sh # /etc/init.d/settime.sh
###############################################################################
# This script is intended as a replacement for the existing init.d/settime.sh #
# which SHOULD take into account RasPi (with or without RTC), motherboards    #
# with dead clock batteries or systems which are perfectly fine regardless.   #
###############################################################################
#           Copyright © 1994-2018, CentralWare Development Centers            #
###############################################################################
# * ntpserver=time.nist.gov can be used to SET the server and FORCE the call  #
# * nosettime as a boot code will forcefully SKIP doing anything below        #
###############################################################################
. /etc/init.d/tc-functions


UPDATE=0; BOTHER=1; NODHCP=0; SKIP=0; CALL_UPDATE=0
test=$(cat /proc/cmdline | grep ntpserver);
if [ ! "${test}" == "" ]; then
for i in `cat /proc/cmdline`; do
  case $i in
    *=*)
      case $i in
        ntpserver*) NTPSERVER=${i#*=}; BOTHER=1; UPDATE=1; CALL_UPDATE=1 ;;
      esac
      ;;
    *)
      case $i in
        nosettime) SKIP=1 ;;
        nodhcp)    NODHCP=1 ;;
        nortc)     BOTHER=1; UPDATE=1; CALL_UPDATE=1 ;;
      esac
      ;;
  esac
done
fi


if [ $SKIP -ge 1 ]; then BOTHER=0; UPDATE=0; exit 0; fi


for i in $@; do
  case $i in
    -m) UPDATE=1; BOTHER=1; CALL_UPDATE=1 ;;
  esac
done


CUR=$(date -I); CUR=${CUR:0:4} # Current YEAR


# See if we're running on a Raspberry Pi
PICORE=0; if [ ! "$(uname -r | grep piCore)" == "" ]; then PICORE=1; fi


# There's no sense even doing anything NETWORK related if there's no NIC #
NICS=$(ifconfig -a | grep HWaddr); if [ "${NICS}" == "" ]; then BOTHER=0; fi



if [ $BOTHER -ge 1 ]; then


    if [ $UPDATE -ge 1 ]; then


        # Assuming static ifconfig or DHCP, wait for the network to settle
        echo -n "${CYAN}Waiting for network${NORMAL}: "
        CNT=0
        until ifconfig | grep -q Bcast; do
            [ $((CNT++)) -gt 60 ] && break || sleep 1
        done


        test=$(ifconfig | grep Bcast)
        if [ ! "${test}" == "" ]; then echo "${GREEN}OK${NORMAL}"; else echo "${RED}OFFLINE${NORMAL}"; UPDATE=0; fi


        if [ $UPDATE -ge 1 ]; then
            OLD=$(cat /etc/sysconfig/tcedir/curyear >/dev/null 2>&1)
            if [ ! "${OLD}" == "${CUR}" ]; then CALL_UPDATE=1; fi
        fi


    fi


fi


if [ $PICORE -ge 1 ]; then if [ $CUR -le 2015 ]; then CALL_UPDATE=1; fi; fi


if [ $CALL_UPDATE -ge 1 ]; then
    if [ "${NTPSERVER}" == "" ]; then NTPSERVER=$(cat /etc/sysconfig/ntpserver); fi
    echo -n "${CYAN}Calling Time Server${NORMAL}: "
    /usr/sbin/ntpd -d -q -n -N -p $NTPSERVER >/tmp/ntpd.test 2>&1
    test=`cat /tmp/ntpd.test | grep offset`
    if [ ! "${test}" == "" ]; then echo "${GREEN}OK${NORMAL}"; else echo "${RED}FAILED${NORMAL}"; echo $test; fi
fi