Only use systemd timer oncalendar events - timer

I'm trying to get a service to run at :0/5:00 (every 5min) every time. This process may take more or less than 5min. If it passes the 5min mark, do nothing, and start the next one on the next 5min block.
This all works properly when the process takes less than 5min, but if the process takes more than 5min, it re-starts the service immediately.
From what I've read, the default behavior is to skip the next execution if the service time overflows (see https://unix.stackexchange.com/questions/203254/does-systemd-timer-unit-skip-the-next-run-if-the-process-hasnt-finished-yet). However, I also see a question which seems to indicate that the service will start as soon as the previous execution completes (see https://unix.stackexchange.com/questions/487562/how-to-make-systemd-timer-run-exactly-every-10-minutes-with-a-task-that-lasts-s) which fits with my expreiences.
(For testing purposes, I'm using :0/1:0 so that I don't have to wait 5min every time)
My timer:
[Unit]
Description=Start service on timed schedule.
After=network-online.target
Wants=network-online.target
[Timer]
OnCalendar=*:0/1:0
AccuracySec=1us
[Install]
WantedBy=timers.target
My service:
[Unit]
Description=Do a thing
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/bin/bash /usr/local/bin/my-script.sh
My script:
#!/bin/bash
PROG="/usr/local/bin/fake-third-party.sh"
exec $PROG &>> /tmp/timer_testing.out
Fake third-party script:
#!/bin/bash
echo "`date` I sleep now"
sleep 76
echo "`date` No more sleep"
So right now, when the 76s ends, it immediately starts the next one.
Thu Jun 25 13:01:00 UTC 2020 I sleep now
Thu Jun 25 13:02:16 UTC 2020 No more sleep
Thu Jun 25 13:02:16 UTC 2020 I sleep now
Thu Jun 25 13:03:32 UTC 2020 No more sleep
Thu Jun 25 13:03:32 UTC 2020 I sleep now
When what I'd be looking for is:
13:01:00 -> sleep
13:02:16 -> wake
13:03:00 -> sleep
13:04:16 -> wake
13:05:00 -> sleep

One possible (aka hacky) solution that is working right now is the following:
Change the my-script.sh to have this at the front:
minutes=$(date +"%-M" | tail -c 2)
seconds=$(date +"%S")
if [[ "$seconds" != "00" || ! ( "$minutes" == "0" || "$minutes" == "5" ) ]]; then
then
exit 0
fi
This does trigger the my-script.sh, but the script never calls exec third-party-script so, it accomplishes the requirement.
However I would like to do this the 'proper' way, if there is one.

Related

Nagios Tool, total running time for the tool

Is there any way to check for how long the NAGIOS TOOL runs? I mean when the tool started running and the time up till now.
Nagios is running in a remote machine, in which I have access (through ssh). I have both credentials for accessing the machine and credentials just to see the Stats from Nagios on this machine
I tried System->Process Info, but I do not have privileges to view such information.
Is there any other way, through terminal?
You can use nagiostats to check the uptime of a Nagios instance. See: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/nagiostats.html
[nagios#lanman ~]# /usr/local/nagios/bin/nagiostats -c /usr/local/nagios/etc/nagios.cfg
Nagios Stats 3.0prealpha-05202006
Copyright (c) 2003-2007 Ethan Galstad (www.nagios.org)
Last Modified: 05-20-2006
License: GPL
CURRENT STATUS DATA
------------------------------------------------------
Status File: /usr/local/nagios/var/status.dat
Status File Age: 0d 0h 0m 9s
Status File Version: 3.0prealpha-05202006
Program Running Time: 0d 5h 20m 39s <------------
Nagios PID: 10119
Used/High/Total Command Buffers: 0 / 0 / 64
Used/High/Total Check Result Buffers: 0 / 7 / 512
...
Find the nagios.log file, it's likely in the var directory under the Nagios installation. Then..
grep "Nagios.*starting" nagios.log | tail -1
Grab the epoch time (first field), and convert it to local.
date -d #1580045430
Sun Jan 26 07:30:30 CST 2020
All in one, assuming the nagios.log is in the current directory.
date -d #$(grep "Nagios.*starting" nagios.log | tail -1 | awk '{print $1}' | sed 's/\[//;' | sed 's/\]//;')
Sun Jan 26 07:30:30 CST 2020

In Splunk, How to use parsed time to determine duration between events?

I have a log file that records the start and finish times for processing files. The entries contain strings that look like this:
=============== STARTED PROCESSING FILE filename at Thu Jul 19 00:03:55 2018 EDT===============
=============== FINISHED PROCESSING FILE filename at Thu Jul 19 00:04:05 2018 EDT===============
Initially I came up with a query using _time:
processing.log "FINISHED PROCESSING FILE" OR "STARTED PROCESSING FILE" | rex field=_raw "(?<filename>\S*)" | stats count first(_time) as start last(_time) as finished by filename | eval duration = abs( finished - start)
That seemed to work just fine until I realized that _time of finished and start could be hours apart even though actual processing to 10 seconds (as in the above example. So now I am trying this query:
processing.log "FINISHED PROCESSING FILE" OR "STARTED PROCESSING FILE" | rex field=_raw "(?<filename>\S*) at (?<ptime>.*) EDT" | eval stime=strptime(ptime,'%a %B %d %Y %H:%M:%S')| stats count first(stime) as start last(stime) as finished by filename | eval duration = abs( finished - start)
However it is not providing the desired results of showing the processing duration of each filename. What am I doing wrong/how can I fix this?
Instead of ...| stats count first(stime) as start last(stime) as finished by filename |eval duration = abs( finished - start) try ... | stats count range(stime) as duration by filename

How to ignore timeouts in ab (apache bench)?

I run benchmarks with apache bench on a web service. I know that 1-2 requests from the test will be timeouted during measurement (it's a web framework issue). And when timeout occurs ab quits with the message apr_pollset_poll: The timeout specified has expired (70007) and does not show results. I want to get measurement results ignoring these timeouted tests (or count them too, but just use timeout value as response time). Is it possible with ab?
EDIT: The command I use is
ab -n 1000 -c 10 http://localhost:80
I looked into ab source and from what I saw it's impossible to ignore these errors. Maybe there is a fork which implements such feature?
The default timeout is 30 seconds. You can change this with -s:
ab -s 9999 -n 1000 -c 10 http://localhost:80

Increasing Solr5 time out from 30 seconds while starting solr

Many time while starting solr I see the below message and then the solr is not reachable.
debraj#boutique3:~/solr5$ sudo bin/solr start -p 8789
Waiting to see Solr listening on port 8789 [-] Still not seeing Solr listening on 8789 after 30 seconds!
I am having two cores in my local set-up. I am guessing this is happening because one of the core is a little big. So solr is timing out while loading the core. If I take one of the core out of solr then everything works fine.
Can some one let me know how can I increase this timeout value from default 30 seconds?
I am using Solr 5.2.1 on Debian 7.
Usually this could be related to startup problems, but if you are running solr on a slow machine, 30 seconds may not be enough for it to start.
In that case you may try this (I'm using Solr 5.5.0)
Windows (tested, working): in bin/solr.cmd file, look for the parameter
-maxWaitSecs 30
few lines below "REM now wait to see Solr come online ..." and replace 30 with a number that meets your needs (e.g. 300 seconds = 5 minutes)
Others (not tested): in bin/solr file, search the following code
if [ $loops -lt 6 ]; then
sleep 5
loops=$[$loops+1]
else
echo -e "Still not seeing Solr listening on $SOLR_PORT after 30 seconds!"
tail -30 "$SOLR_LOGS_DIR/solr.log"
exit # subshell!
fi
Increase waiting loop cycles from 6 to whatever meets your needs (e.g. 60 cycles * 5 sleep seconds = 300 seconds = 5 minutes). You should change the number of seconds in the message below too, just to be congruent.

How is it possible to get real file's change time after updating from SVN?

I have changed a CSS file, then committed it. Then updated it on another server. But the time of the updated file is time of the SVN update.
Is it possible to get the "Real" time - the one when the file change was saved on the first server?
Output of stat:
stat myfile.css
File: `myfile.css'
Size: 29731 Blocks: 64 IO Block: 4096 regular file
Device: fe11h/65041d Inode: 4411064 Links: 1
Access: (0660/-rw-rw----) Uid: ( 1118/ valk) Gid: ( 1010/developers)
Access: 2012-02-19 18:04:50.000000000 +0200
Modify: 2012-02-19 18:04:50.000000000 +0200
Change: 2012-02-19 18:04:50.000000000 +0200
Thanks
You can also configure Subversion to use commit-times by editing the
Subversions config file located at ~/.subversion/config (UNIX, Linux) respectively
%APPDATA%\subversion(Windows)
There are these lines (around line 100 in unmodified file):
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
Just remove the "#" from the last displayed line.
Note this setting is active for all your workingcopies on this machine
Use svn info. It will give you something like:
Path: /XXXXX/myfile.css
Name: myfile.css
URL: svn+ssh://XXXXX/current/myfile.css
Repository Root: svn+ssh://XXXXX
Repository UUID: ed4dba2c-4d18-0410-83c2-a4e2ddc248c7
Revision: 3697
Node Kind: file
Schedule: normal
Last Changed Author: ocharlesworth
Last Changed Rev: 3654
Last Changed Date: 2011-11-22 00:08:53 +0000 (Tue, 22 Nov 2011)
Text Last Updated: 2011-12-15 11:39:55 +0000 (Thu, 15 Dec 2011)
Checksum: 395d2b79f528cccb58017a87a76f2e50

Resources