CentOS VPS show time same as in India though situated in US - mongodb

If right now VPS situated in US shows time "Mon Sep 25 20:23:56 UTC 2017",
my local machine in India show time "Mon Sep 25 20:25:36 UTC+5:30 2017"(appx 2 minutes early on VPS).
My problem is When I save date to mongodb remote it save as "createdAt" : ISODate("2017-09-25T20:23:56.461Z") and when I see website on my local machine the time shows Tue Sep 26 01:33 UTC 2017. I seriously don't understand what is wrong??
why UTC+5:30 on my local machine? and how come the VPS server time is same as Indian Standard time?

Check the system time with date command.
All the servers should sync time with NTP server to avoid this kind of issues.
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.org // You can use ur own NTP server
service ntpd start

Related

Yocto: set date and time without ntp

on my embedded device with YOCTO and none ethernet connection I would set a specific date and keep it udpdate after the device power-off.
I tryed with :
date --set '2022-05-25 11:17:00'
hwclock --utc --systohc
poweroff
but at power on the dat&time are switched back to old value
The same result using :
timedatectl
where ntp is disable, RTC local in TZ is enable and system clock synchromized is enable.
Where is my mistake?

Share host timezone with docker container

I'm trying to sync the timezone of a docker container with my host. My host is using ISM and the docker container (using a tomcat image) uses UTC by default. I've read that we should mount a volume to share the timezone of the host:
$ docker run -t -i -p 8080:8080 -p 8090:8090 -v /etc/localtime:/etc/localtime:ro tomcat:7.0.69-jre8 /bin/bash
After that I can check that the date retrieved is the same as the host:
$ date
Fri Jul 22 13:53:45 IST 2016
When I deploy my application and I try to update a date, I can see that the date 22/07/2016 is using my browser timezone, which is the same as the host where the docker container is running. But debbuging the server side of the app I can see that the date is converted into UTC timezone. This means that the docker container is not really using the host volume I did mount.
Am I missing anything?
Another way I tried and did work was updating the timezone in the docker container:
$ dpkg-reconfigure tzdata // Selecting the corresponding options afterwards
This way I can see the same timezone in both: client side and server side of my app.
After debugging and reading about date and time, I think it makes sense that the backend stores the date and time in UTC/GMT, that way is independent of the client's timezone when it's saved in the DB. So it wouldn't be a good practise to change the tomcat server timezone to match the host (it shouldn't really matter).
The issue I had was the front end was using date and time (UTC/GMT +1) and the time was set to 00:00h and when it reaches the back end, the date and time is converted to UTC/GMT which makes it 23:00 of the previous day. The persistence layer was just storing the date which it's wrong as we lose data (the time) and when we try to retrieve that record from the DB we will get the previous date without the time so it's not the result we would expect.
I hope my explanation makes sense

Azure Ubuntu 15.04 virtual machine can't change date/time

I'm ruining an Ubuntu 15.04 OS on Azure Virtual Machine. I can't manually change the date of the system by using the "date" command. Here's a sample run:
~# date
Tue Jul 7 00:24:58 HKT 2015
~# date -s "2014-07-04 10:53:59"
Fri Jul 4 10:53:59 HKT 2014
~# date
Tue Jul 7 00:25:01 HKT 2015
I have uninstalled ntpdate but it doesn't make a difference. Has anyone experienced this before?
Thanks!
Generally speaking you can't change the time of a VM which is hosted by an external provider, because the cost of providing an emulated clock is too high and thus it tends to pick up the clock time of the host machine instead.

could not connect to server with postgresql is the server running locally and PGSQL.5432

I´ve read many similar forum discussions about this but I have not been able to solve the problem. I installed postgresql 9.1 on ubuntu 12.04 (not really a server machine, but virtualized in VirtualBox). Yesterday I was able to restart (and start) postgresql server but not today after many trials.
In postgresql.conf i have listen_addresses='*' and port=5432 and unix_socket_directory = 'var/run/postgresql'
I´ve looked into that directory but it seems to be empty.
I´ve tried: locate PGSQL.5432 but there´s no results
My server ip is set like 192.168.1.211 and ping -c 4 192.168.1.211 seems to be ok.
Tried many solutions (like chmod 777 /var/run/postgresql) and nothing seems to fix it.
It´s maybe and stupid issue and I´m not being able to solve it as i don´t have a high level of knowledge on those systems.
Full error messages: after sudo service postgresql restart -- > The postgresql server failed to start. Please check the log output. After sudo psql -- > could not connect to server: the file or directory does´nt exist. Is the server running locally and accepting connections on Unix domain socke "var/run/postgresql/.s.PGSQL.5432?
Postgresql version: 9.1
Just after starting ubuntu, this is the log that i get with tail /var/log/postgresql/postgresql-9.1-main.log:
CET LOG: could not open temporary statistics file "pg_stat_tmp/pgstat.tmp": permission denied.
CET LOG: received smart shutdown request
CET LOG: autovacuum launcher shutting down.
CET LOG: shutting down
CET PANIC: could not open control file "global/pg_control": permission denied
CET LOG: background writer process (PID 7151) was terminated by signal 6: Aborted
CET LOG: terminating any other active server processes
CET LOG: could not open temporary statistics file "pg_stat_tmp/pgstat.tmp": permission denied.
CET LOG: abnormal database systema shutdown.
Any idea about what to try?
Here the solution I´ve found, hope could help other users with similar issue:
I´ve just made:
sudo chown -R postgres:postgres /var/lib/postgresql
And now postgresql is starting fine. So wrong permissions, maybe modified by myself, I´m not sure.
Kind regards.
I faced the same issue, this was solved after making the changes in the postgresql.conf i.e.
listen_addresses='*'
And restarted the device it was solved,for more detail use the below given link, Restart the device after making changes in the config file it solves most of the firewall issues.
Help
This error generally means that the server is not running. Based on dpkg -l output and the thread of comments, it was due to the postgresql-9.5 main package being somehow uninstalled. Since the uninstall hasn't been called with the --purge option to dpkg, the data and configuration files are still there, so apt-get install postgresql-9.5 can fix the problem.

How to Update Date and Time of Raspberry Pi With out Internet

I have connect my Raspberry Pi to LAN but there is no internet available. Is there any method to update raspberry pi date time by using a PC (windows 7) in LAN? I want to get computer date and time to my Raspberry Pi when it is booting.
Remember that Raspberry Pi does not have real time clock. So even you are connected to internet have to set the time every time you power on or restart.
This is how it works:
Type sudo raspi-config in the Raspberry Pi command line
Internationalization options
Change Time Zone
Select geographical area
Select city or region
Reboot your pi
Next thing you can set time using this command
sudo date -s "Mon Aug 12 20:14:11 UTC 2014"
More about data and time
man date
When Pi is connected to computer should have to manually set data and time
Thanks for the replies.
What I did was,
1. I install meinberg ntp software application on windows 7 pc. (softros ntp server is also possible.) 2. change raspberry pi ntp.conf file (for auto update date and time)
server xxx.xxx.xxx.xxx iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
3. If you want to make sure that date and time update at startup run this python script in rpi,
import os
try:
client = ntplib.NTPClient()
response = client.request('xxx.xxx.xxx.xxx', version=4)
print "===================================="
print "Offset : "+str(response.offset)
print "Version : "+str(response.version)
print "Date Time : "+str(ctime(response.tx_time))
print "Leap : "+str(ntplib.leap_to_text(response.leap))
print "Root Delay : "+str(response.root_delay)
print "Ref Id : "+str(ntplib.ref_id_to_text(response.ref_id))
os.system("sudo date -s '"+str(ctime(response.tx_time))+"'")
print "===================================="
except:
os.system("sudo date")
print "NTP Server Down Date Time NOT Set At The Startup"
pass
I found more info in raspberry pi forum.
You will need to configure your Win7 PC as a Time Server, and then configure the RasPi to connect to it for NTP services.
Configure Win7 as authoritative time server.
Configure RasPi time server lookup.