Project

General

Profile

Running command before TVH startup / Time fix --- SOLVED

Added by Zac Daman over 7 years ago

I am Configuring a new system. Running TVH in Lubuntu in Qnap VM. Qnap Virtual Machine time is set wrong in boot (UTC+3 -> UTC in VM) and I need to fix it before tvheadend start. Otherwise the error makes VM system time wrongly offset +3 hours.

TVH seems to have a bug reading the UTC time right. The only combination working well is when UTC time in system is right and TVH network time is set to UTC. (Not UTC+3 which is the right time). Otherwise TVH EPG timings are totally mess up = missing first 2 hours in all channels or whole EPG offset is wrong.

To correct VM time issue I use SAMBA timing to get the right time from Qnap itself:
sudo net time set -S 192.168.1.4

But after booting VM I need to run this fix manually. Stop TVH service, delete epgdb.v2 and restart TVH. Not convenient way in a long run and definitely not set-and-forget. I need to monitor the system if VM or Qnap boot f.ex. because of power failure or maintenance.

QUESTION: How can I run the fix command BEFORE the tvheadend service start/boot?

I tried to add the line to /etc/rc.local but no effect. If I leave system clock to wrong time there is no way to compensate it in TVH. Changing of TVH network EIT offset to any other UTC+- or Local server time only mess up the whole EPG.

I have tested 4.2.2-84 and 4.3-285. Both with same effect.


Replies (3)

RE: Running command before TVH startup / Time fix - Added by Robert Cameron over 7 years ago

If I am understanding correctly:

QNAP is set to UTC+3
When a VM is started, its system clock is set to the QNAP's as UTC (but this is really UTC+3)

I can think of a couple solutions:

1. Set the QNAP to UTC. Let its system time remain at UTC, but use the zoneinfo files to indicate its offset. (If this is already the case, then shame on QNAP for sending localtime as system time.)
2. NTP: Set up NTP on the VM, so that it pulls its time from the network and uses that to syncronize its clock.
3. Set your system to use its "RTC" as localtime, not UTC.

1 should already be happening, so if it's not, QNAP is in the wrong. 2 should be easy to achieve. Without knowing which version of Ubuntu your image is based on, I can't exactly tell you which way is easiest to enable NTP. On recent versions, this is now handled by systemd. For that, you can do:

# timedatectl set timezone [TIMEZONE]
# timedatectl set-ntp true

(You can use timedatectl list-timezones to see what the acceptable entries are.)

For 3, using systemd you can easily do this with:

# timedatectl set-local-rtc true

Now the system will know that its internal clock (as provided by QNAP) is its localtime, not UTC.

If your system is not using systemd, you can check out the hwclock man pages to see how to achieve 1 and 3. For 2, it will require possibly installing and configuring an NTP client.

RE: Running command before TVH startup / Time fix - Added by Zac Daman over 7 years ago

Thank you Robert for the answer.

QNAP is set to UTC+3
When a VM is started, its system clock is set to the QNAP's as UTC (but this is really UTC+3)

The case is exactly so. There are also others wondering the same issue https://forum.qnap.com/viewtopic.php?t=120108

1. Set the QNAP to UTC. Let its system time remain at UTC, but use the zoneinfo files to indicate its offset. (If this is already the case, then shame on QNAP for sending localtime as system time.)

This is already the case. My Qnap gets its' time using NTP. In Qnap QTS the time is set manually and selecting the zone (only GMT+- options are available), or using NTP.

2. NTP: Set up NTP on the VM, so that it pulls its time from the network and uses that to syncronize its clock.

I tried to install and use NTP in VM but could not get it work (or do anything noticable). Installed and set all but no effect. On the other hand I was keen on idea where VM gets the time from QTS (host/server). That should be the fastest and most reliable way. The times are the same.

3. Set your system to use its "RTC" as localtime, not UTC.

If you mean by system you mean Qnap QTS (host)? The only options in QTS timezone are GMT+-. No UTC, localtime or RTC.

1 should already be happening, so if it's not, QNAP is in the wrong. 2 should be easy to achieve. Without knowing which version of Ubuntu your image is based on, I can't exactly tell you which way is easiest to enable NTP. On recent versions, this is now handled by systemd. For that, you can do:

Image is Lubuntu 17.04 (zesty zapys) x64. Only added services in that VM image are FTP, SSH, telnet, tvheadend, and network protocols. Updated and upgraded.

  1. timedatectl set timezone [TIMEZONE]

I used sudo dpkg-reconfigure tzdata
That should do the trick also.

# timedatectl set-ntp true

That did the trick!!

But this theoretically means that host and VM can be in different times. But in practice both use NTP and update in a few days therefore the time should pretty much be the same. When I have more time I need to put QTS NTP service on and get the VM time from that host. Then there is no traffic outside from my firewall.

For some reason I did not find the way to setup NTP service on even thou I saw the status in timedatectl.

If your system is not using systemd, you can check out the hwclock man pages to see how to achieve 1 and 3. For 2, it will require possibly installing and configuring an NTP client.

I did some checking with hwclock but did not dare to change it because I was wondering that hwclock actually will mess with host clock (?)

Thank you very much Robert!! You are the master.

I agree with you Robert that Shame on Qnap for sending to VM local time as system time.

But still at the same time I must say that I am very pleased with my Qnap 653pro. I use it in my home to many purposes, like 1) backup station and network drive (Raid), 2) host Sophos UTM firewall (in VM), 3) host tvheadend DVR service and recordings (in VM), 4) HDMI to TV to do all kinds of normal computer stuff (no 4k thou), 5) host openhab to control my smart home, 6) host surveillance camera system, and many other services for different personal and entrepreneur purposes.

RE: Running command before TVH startup / Time fix --- SOLVED - Added by Robert Cameron over 7 years ago

Sorry I was a little unclear. As far as option 3 for setting the RTC to localtime, that was for the VM. All of the suggestions were to be done on the VM.

As far as timedatectl set-ntp true, what that does is enable the systemd-timesyncd service, which is the native NTP client in systemd. Since you are using a current Ubuntu image, systemd is managing the system rather than the previously used Upstart or rc.d scripts.

By default the systemd-timesyncd settings are in /etc/systemd/timesyncd.conf. In there you can select which NTP server to use by default, and which fallback servers to use.

    (1-3/3)