What's new

Entware TZ Issue

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

sbsnb

Very Senior Member
Entware applications that load at boot are not picking up the TZ despite following the directions in https://github.com/Entware/Entware/wiki/Using-time-zones. I have the following in /jffs/post-mount:
Code:
logger "$0:" "Setting up timezone for Entware..."
if [ ! -f /etc/localtime -a -f /opt/share/zoneinfo/US/Pacific ]; then
  ln -sf /opt/share/zoneinfo/US/Pacific /etc/localtime
fi

And it's working and firing before rc.unslung runs, but still DNSCrypt-proxy launches with the wrong timezone.

Code:
May  4 22:05:37 custom_script: Running /jffs/scripts/post-mount (args: /tmp/mnt/entware)
May  4 22:05:37 admin: /jffs/scripts/post-mount: Setting up timezone for Entware...
May  4 22:05:38 admin: Started dnscrypt-proxy from .
May  5 05:05:38 dnscrypt-proxy[1136]: Source [opennic.md] loaded
May  5 05:05:38 dnscrypt-proxy[1136]: dnscrypt-proxy 2.0.23
May  5 05:05:38 dnscrypt-proxy[1136]: Now listening to 127.0.0.1:65053 [UDP]
May  5 05:05:38 dnscrypt-proxy[1136]: Now listening to 127.0.0.1:65053 [TCP]

If I restart dnscrypt-proxy it picks up the timezone correctly. It's just at boot time that it doesn't. The only thing I can think of is that at boot it's starting before ntpd updates the time, and restarts are after.
 
Version of Merlin? Are you trying to use DoT with dnscrypt?

Sent from my SM-T380 using Tapatalk
 
You can clearly see it happen in the logs with ./S09dnscrypt-proxy2 restart:
Code:
Jun  8 14:08:24 dnscrypt-proxy[1136]: Stopped.
Jun  8 07:08:24 admin: Started dnscrypt-proxy from .
 
Have you set timezone in DNSCrypt-proxy?
 
Is this an option? The example-dnscrypt-proxy.toml config file doesn't mention timezone.
 
Is this an option? The example-dnscrypt-proxy.toml config file doesn't mention timezone.
In the DNSCrypt installer menu
 
I'm not using the installer. It's just installed through entware. I'm curious how the installer deals with it. I'll check it out. In the mean time I'm trying this in my /entware/etc/init.d/S09dnscrypt-proxy2:
Code:
#!/bin/sh

ENABLED=yes
PROCS=dnscrypt-proxy
ARGS="-config /opt/etc/dnscrypt-proxy.toml"
PREARGS="nohup"
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/>

ntptimer=0
while [ "$(nvram get ntp_ready)" = "0" ] && [ "$ntptimer" -lt 60 ]; do
    ntptimer=$((ntptimer+1))
    sleep 1
done

. /opt/etc/init.d/rc.func

I know it will hang startup until NTP syncs, but that's the goal. I don't know if it will just block dnscrypt startup, or block the whole router's boot sequence. Guess we'll find out when I can reboot again without incurring the wrath of the family.

EDIT - I put in a sanity check in case it block the rest of the boot sequence.
 
Last edited:
Looks like this is the relevant part of the installer script:

Code:
set_timezone () {
  local TMP=/root
  local TZ_DATA=tzdata-2018c-1-any.pkg.tar.bz2

  download_file $TARG_DIR 755 $URL_GEN/manager
  download_file $TMP 644 $URL_GEN/$TZ_DATA
  local INDEX=`tar tjf $TMP/$TZ_DATA | awk -F'/' '!/\/$/ && !/PaxHeader/ && /\/posix\//' | wc -l`
  echo -e "$INFO Available timezones/locations:"
  tar tjf $TMP/$TZ_DATA | awk -F'/' '!/\/$/ && !/PaxHeader/ && /\/posix\//' | sort | awk -v INDEX=0 -F'/' '!/\/$/ {++INDEX;printf "  " INDEX") ";for (i=5; i<NF; i++)  printf $i "/"; print $NF}'
  read_input_num "Select your timezone/location" 1 $INDEX
  local TZ_FILE="`tar tjf $TMP/$TZ_DATA | awk -F'/' '!/\/$/ && !/PaxHeader/ && /\/posix\//' | sort | awk -v INDEX=$CHOSEN '{++i}i==INDEX{print $0}'`"
  echo -e "$INFO `basename $TZ_FILE` selected"
  tar xjf $TMP/$TZ_DATA -C $TMP usr/share/zoneinfo/posix
  mv "$TMP/$TZ_FILE" $TARG_DIR/localtime
  if [ $? -ne 0 ]; then
    echo -e "$ERROR Unable to set your timezone file"
    end_op_message
    return
fi

It seems as though it just creates the file localtime in the same directory where dnscrypt-proxy is installed. I don't know why that would function any differently than the configuration I have with /etc/localtime set to my timezone. The dnscrypt-proxy binary looks for /etc/localtime. Maybe /etc isn't ready when post-mount runs?
 
I put
Code:
export TZ=$(cat /etc/TZ)
in my init.d files. Seems to be necessary.
 
If TZ is defined, dnscrypt-proxy expects the value to be the location of the TZ file.

From the sources:
Code:
func initLocal() {

    // consult $TZ to find the time zone to use.

    // no $TZ means use the system default /etc/localtime.

    // $TZ="" means use UTC.

    // $TZ="foo" means use /usr/share/zoneinfo/foo.
 
I'm not using the installer. It's just installed through entware. I'm curious how the installer deals with it. I'll check it out. In the mean time I'm trying this in my /entware/etc/init.d/S09dnscrypt-proxy2:
Code:
#!/bin/sh

ENABLED=yes
PROCS=dnscrypt-proxy
ARGS="-config /opt/etc/dnscrypt-proxy.toml"
PREARGS="nohup"
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/>

ntptimer=0
while [ "$(nvram get ntp_ready)" = "0" ] && [ "$ntptimer" -lt 60 ]; do
    ntptimer=$((ntptimer+1))
    sleep 1
done

. /opt/etc/init.d/rc.func

I know it will hang startup until NTP syncs, but that's the goal. I don't know if it will just block dnscrypt startup, or block the whole router's boot sequence. Guess we'll find out when I can reboot again without incurring the wrath of the family.

EDIT - I put in a sanity check in case it block the rest of the boot sequence.
I tried this one and it didn't help. I tried making it wait until it was verified that /etc/localtime existed, but that didn't help either. The only other thing I can think of is the user context from which it is launched. I just don't know why that would matter:
Code:
admin@RT-AC88U:/tmp/etc# l localtime
lrwxrwxrwx    1 admin    root            30 May  4  2018 localtime -> /opt/share/zoneinfo/US/Pacific

If it's not the user context, it's something that's happening after ntp sets the date and after the timezone is set, but I keep looking over the logs and don't see anything obvious.
 
Last edited:
I think I know why now. rc.unslung is launched in the context of /jffs/services-start. When it runs, post-mount hasn't run yet, which means the timezone hasn't been set for entware. I'm betting if I move the timezone stuff into the service-start script before it launches rc.unslung we will have our fix.
 
I think I know why now. rc.unslung is launched in the context of /jffs/services-start. When it runs, post-mount hasn't run yet, which means the timezone hasn't been set for entware. I'm betting if I move the timezone stuff into the service-start script before it launches rc.unslung we will have our fix.
In other words, Entware is started the old fashioned way. No wonder.
 
In other words, Entware is started the old fashioned way. No wonder.
Still didn't fix it. I keep meaning to move entware start to post-mount, but I remember there's a reason I haven't done it yet. I'm just too old to remember what that reason was ;)

I still suspect context is an issue. I can't think of a reliable way to have /etc/localtime exist before services-start or post-mount are run so that they run in that timezone context.
 
Last edited:
I think setting /etc/localtime would be more reliable than a TZ environment variable since it's hard to be sure which environment scripts will be run with.

As long as entware is being started correctly you could set the time in an init.d file, beginning the name with S00 so it's run as early as possible. That way you don't have to mess with any post-mount/service-start scripts. It used to be part of the entware wiki, not sure why it was removed.

Code:
#!/bin/sh

start() {
    ln -sf /opt/share/zoneinfo/Europe/Moscow  /etc/localtime
}

stop() {
    rm -rf /etc/localtime
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    ;;
esac

If you do choose to use an environment variable instead, you can use :filepath instead of loading a binary file into it. For example
Code:
export TZ=':/opt/share/zoneinfo/Europe/Moscow'
 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top