How to check docker logs for specific time using any sudo user.
like I want to check logs for 2022-02-02 from 00:00 AM EST till 01:00 AM EST.
So, I was trying to access logs using Sudo docker logs -f but unfortunately it is giving me all the output.
Have a look at the official documentation. There are 2 options of interest:
--since
Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
--until
Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
Related
We're encountering a very strange problem at my company. Since a month ago, we used to publish images with Docker on Container Registry, then deploy them to Compute Engine (which creates an instance of a VM) and it worked fine.
Since 2 weeks ago, when we depoy an image from Container Registry to Compute Engine, the VM starts and works fine for some time, but after some hours it stops forever. We currently have a paying plan, so I guess this is not a payment issue.
Has anyone encountered this problem before? Is it a firewall issue? All the logs from the VM seem fine.
Here are the last logs of the VM:
[ 7214.995439] google_accounts_daemon[465]: Adding user toto to group google-sudoers
[ 7449.139530] google_accounts_daemon[465]: Removing user toto from group google-sudoers
[226991.170566] EXT4-fs (sda5): mounting ext2 file system using the ext4 subsystem
[226991.206891] EXT4-fs (sda5): mounted filesystem without journal. Opts:
[227024.855486] LoadPin: kernel-module pinning-excluded obj="/lib/modules/5.4.49+/kernel/fs/fat/fat.ko" pid=40981 cmdline="/sbin/modprobe -q -- fs-vfat"
[227024.880466] LoadPin: kernel-module pinning-excluded obj="/lib/modules/5.4.49+/kernel/fs/fat/vfat.ko" pid=40981 cmdline="/sbin/modprobe -q -- fs-vfat"
[227024.899845] LoadPin: kernel-module pinning-excluded obj="/lib/modules/5.4.49+/kernel/fs/nls/nls_cp437.ko" pid=40988 cmdline="/sbin/modprobe -q -- nls_cp437"
[227024.917675] LoadPin: kernel-module pinning-excluded obj="/lib/modules/5.4.49+/kernel/fs/nls/nls_iso8859-1.ko" pid=40990 cmdline="/sbin/modprobe -q -- nls_iso8859-1"
According to the GCP docs link, you can set the option of automatically restarting the vm to true. So it will restart the instance after failing.
To enable:
$ gcloud compute instances set-scheduling [instance-name] --zone [instance-zone] --restart-on-failure
While running JMeterbuild in jenkin, it run as infinite mode "never stops" even though the configuration is set in JMX.
How to stop JMeter build after a certain time ?
I have tried to provide command line arguments thinking it isn't rewarding jmx configuration.
PATH/jmeter -Jjmeter.save.saveservice.output_format=xml -Jduration=60 -n -t Main.jmx -l Mainreport.csv
Expecting JMeterbuild to stop after 60 seconds but it never ends, monitored for 30 minutes.
You need to get value using ${__P(duration,)} in JMeter Scheduler's duration field:
You can add __P default value in second argument, for example, for default 30
${__P(duration,30)}
I'm running Celery Flower in Docker (see this question for details). The command ends up being:
celery -A proj flower --persistent=True --db=/flower/flower
I've got a persistent volume all set up on /flower. However, it looks like Flower never writes anything to its database file, even after 30 minutes of uptime (during which ~120 tasks were processed):
-rw-r--r-- 1 user user 0 Mar 11 00:08 flower.bak
-rw-r--r-- 1 user user 0 Mar 10 23:29 flower.dat
-rw-r--r-- 1 user user 0 Mar 11 00:08 flower.dir
Stopping the Docker container gracefully doesn't work, and so Docker forcefully kills it, which means nothing ends up being written to the database and so it's as if nothing was persisted.
Is there a way to get Flower to either flush its database occasionally, or, better yet, to exit gracefully?
To flush out, you can set max_tasks to a suitable number.
celery -A proj flower --persistent=True --db=/flower/flower --max_tasks=100
This limits number of tasks that will be stored in the db. Once limit is reached, it will discard old tasks.
You can checkout docs for more configuration options.
There is no detail in the Flower document, but after checking the code, I found the only place it writes back to the db file is when Flower is stopped gracefully. This is the latest code (v0.9.2)1:
def stop(self):
if self.persistent:
logger.debug("Saving state to '%s'...", self.db)
state = shelve.open(self.db)
state['events'] = self.state
state.close()
This means you can do nothing on the Flower side, yet, unless you want to change the code.
However, on the Docker side, you may ensure that it graceful shutdown the container with docker container stop, so Flower's stop() function is invoked properly. To achieve this, you need to make sure your container command is using "exec form" over "shell form"2, as recommended in the document.
I also found a discussion over a similar problem with another service. Have a look there if you need more detailed explanation3.
Reference:
Flower code on Github
DockerFile CMD document
Discussion of a similar issue with SQL Server Docker on Github
I'm a new user of GCE instances.
I created instances a week ago and changed timezone to Asia/Shanghai by commands below:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Then yesterday, I found that my system timezone changed to UTC automatically and /etc/localtime was changed. So I run the command above agina. Until now it's OK.
After that I checked many resources and export TZ='Asia/Shanghai'. But I still not know if it's the root cause or not.
Also I find that someone adds xen.independent_wallclock=1 in sysctl.conf file to maintain independent times. But it's for Xen VM and I'm not sure if it's useful for GCE.
Could anyone please take a look at it ?
I've found a more user friendly approach here
Go root user
sudo -s
and use
dpkg-reconfigure tzdata
This will bring up a GUI which will guide you to change your timezone information
To make the permanent change edit $HOME/.profile or $HOME/.bash_profile appending the line and then log out and log in again:
TZ='Asia/Shanghai'; export TZ
for windows users open powershell as admin and type TZUtil.exe /s "<your new time zone>".
to see a list of all available time zones type TZUtil.exe /l.
for more info type TZUtil.exe /?.
I am running Jenkins on a Linux server and shows the wrong time :(
Situation:
I am running another java app (in tomcat that also runs Jenkins) that shows the correct time in the log files (I use Logback through slf4j).
The bios is set to the UTC time (system clock) like advises here: http://www.linuxsa.org.au/tips/time.html
In Linux it's indicated in /etc/sysconfig/clock that the system clock is set to UTC and in which timezone we are located. I am in UTC+1
Running date command on Linux shows the correct local time. Example:
Sun Jan 8 12:11:35 CET 2012
But Jenkins shows the time plus 1 hour :(...
The jenkins config shows:
user.timezone = Europe/Amsterdam (which is UTC+1).
I think that Jenkins (java) thinks the local clock is set to UTC such that 1 hour is added.
How do I solve this?
If you are running Jenkins with Docker, you can append -e JAVA_OPTS=-Duser.timezone=TZ to docker arguments.
docker run -e JAVA_OPTS=-Duser.timezone=$TZ jenkins
All available TZ can be found here.
See here: https://wiki.jenkins-ci.org/display/JENKINS/Change+time+zone
In short, you can set the system property, either modifying the JVM options,
java -Dorg.apache.commons.jelly.tags.fmt.timeZone=TZ ...
Or changing Jenkins configuration in /etc/default/jenkins (Debian) or /etc/sysconfig/jenkins (Red Hat):
JAVA_ARGS="-Dorg.apache.commons.jelly.tags.fmt.timeZone=America/New_York"
It also mentioned -Duser.timezone="..." is an option, but can cause problems / interfere with other contexts (some vague hand-waving & caveats: time travel is always unpredictable).
In general (in my experience), don't change the system time, since us, our servers & our data live in a global world & should be handling, sending, comparing all times in UTC until the latest possible moment: usually that's the GUI (presentation layer) just before being displayed (...if even then). (Our build system results actually produces data that is fed into another system in another time zone.)
On Jenkins 2.63 on Ubuntu 14.04.5 LTS setting
JAVA_ARGS="-Djava.awt.headless=true -Duser.timezone=America/Los_Angeles"
in /etc/default/jenkins and then doing
sudo service jenkins stop
sudo service jenkins start
worked for me to change the timezone from UTC to PDT.
Put this in a Dockerfile and it will work;
RUN echo "import hudson.model.*;" >
/var/jenkins_home/init.groovy.d/timezone.groovy && \
echo "import jenkins.model.*;" >>
/var/jenkins_home/init.groovy.d/timezone.groovy && \
echo "System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone',
'America/Denver')" >> /var/jenkins_home/init.groovy.d/timezone.groovy
$JENKINS_HOME/init.groovy.d/*.groovy will get executed at start up.
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone',
'America/Denver')
That sets the timezone.
For official Jenkins Docker image (lts:2.138.1), you should set Jenkins java options to your local TZ. You can use this env. variable in a docker run command or docker-compose as well.
See here: https://wiki.jenkins.io/display/JENKINS/Change+time+zone
JENKINS_JAVA_OPTIONS="-Duser.timezone=Europe/Paris"
In case you have additional slaves you can sync the clock by using ntp. On Linux you can run following commands for each slave:
sudo systemctl stop ntp
sudo ntpdate -qu 0.debian.pool.ntp.org
sudo systemctl restart ntp
sudo systemctl status ntp
The easiest way without restarting Jenkins:
Open "Manage Jenkins" -> "Script Console"
Run the script:
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'America/New_York')