pdksh time built-in function does not work - pdksh

$ time -p sleep 5
real 8.33
user 0.00
sys 0.00
$ /usr/bin/time -p sleep 5
real 5.00
user 0.00
sys 0.00
$ echo $KSH_VERSION
#(#)PD KSH v5.2.14 99/07/13.2
I have noticed this issue:
on Red Hat Enterprise Linux Server release 6.8 (Santiago).
and on Red Hat Enterprise Linux Client release 5.8 (Tikanga).
Any help is welcome.

At least I have found the maintainer of a fork of pdksh that had the same problem. He has fixed the bug:github.com/Orc/pdksh/commit/5d...
The symbol CLK_TCK has been removed from a C header by an evil standardisation commitee. As a result pdksh was using a default value (60) instead of the correct value that can be displayed using the following command:
$ getconf CLK_TCK
100
If you need a quick and dirty patch, you can either download the source of the rpm and fix the value in ksh_time.h or you can install the fork.

Related

Debian: Cannot fork (Memory Issue)

Recently my processes started to randomly die with an out of memory exception. Furthermore the restart script for those processes printed:
./start.sh: 4: ./start.sh: Cannot fork
The script looks like this:
#!/bin/sh
#EU1
while :
do
if ! screen -list | grep -q "eu1"; then
echo EU1 ist down, Patch eingeleitet!
cd MysticRunes/EU1
./patch.sh
echo EU1 Patch ausgeführt!
screen -dmS eu1 java -Xms6000M -Xmx6000M -jar spigot.jar nogui
echo EU1 neugstartet!
cd ../..
fi
#MRDev
if ! screen -list | grep -q "mrdev"; then
echo MRDev ist down, restart eingeleitet!
cd MysticRunes/Developer
screen -dmS mrdev java -Xms4000M -Xmx4000M -jar spigot.jar nogui
echo MRDev neugstartet.
cd ../..
fi
sleep 1
done
free -m shows this:
total used free shared buffers cached
Mem: 32125 29902 2222 0 1386 17873
-/+ buffers/cache: 10642 21483
Swap: 16375 0 16375
And htop shows this:
I can't really tell whats the issue here. I have looked up the memory being used issue and afaik my memory is used that much at all because it is only caching stuff and memory allocated to the cache is supposed to be free when the server is in need of more memory. HTOP showing the same process over and over again is probably only the amount of threads the server is running right? So basicly all the entries with 8.7% memory usages of the process can be combined to a total of 8.7% too?
Maybe I am just getting this wrong so please correct and/or help me.
Sincerely,
Jalau
The solution was that there was a thread pool that kept creating threads and thus causing the max amount of threads to be reached at some point. Thanks for helping.

How do I schedule the Let's Encrypt certbot to automatically renew my certificate in cron?

I've seen conflicting recommendations. From the eff.org docs:
if you're setting up a cron or systemd job, we recommend running it twice per day... Please select a random minute within the hour for your renewal tasks.
I've also seen recommendations for weekly jobs.
I'm not a cron expert, so I'd prefer an answer with detailed steps for setting up the cron job.
So I settled on scheduling it to run once a day. First I tested auto-renew as the docs recommend:
sudo letsencrypt renew --dry-run --agree-tos
Then I updated the crontab:
sudo crontab -e
This is the line I added:
12 3 * * * letsencrypt renew >> /var/log/letsencrypt/renew.log
This runs the renew everday at 3:12 am. I presume the docs recommend "a random minute within the hour" to distribute the load on the renew servers. So I suppose anything other than 0, 15, 30, or 45 is preferred.
I looked into randomizing the minute in the cron setting, like Jenkins allows you to do, but that seemed overly complicated.
Finally, I tested the cron command using sudo bash:
sudo bash -c "letsencrypt renew >> /var/log/letsencrypt/renew.log"
I recently (April 2018) installed and ran certbot (version 0.22.2) on an Ubuntu 16.04 server, and a renewal cron job was created automatically in /etc/cron.d/certbot.
Here's the cron job that was created:
# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew
Please check this before putting a new Cron job.
In Debian Jessie and up (incl. Ubuntu) cron is not executed for Certbot renewal.
Instead the systemd timer is used. See timer: /lib/systemd/system/certbot.timer
This timer runs the following service: /lib/systemd/system/certbot.service
Which contains:
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew
PrivateTmp=true
In order to list all the timers, execute the following command in the terminal:
systemctl list-timers
Hopefully Certbot is part of this:
Mon 2019-02-04 08:38:45 CET 9h left Sun 2019-02-03 15:25:41 CET
8h ago certbot.timer certbot.service
UPDATE:
Due to the down votes. I'll add how to install Certbot on a Debian based distro (it may vary depending on your Linux distribution).
But within Debian Stretch for example you can install the back-port package of certbot via:
sudo apt-get install certbot -t stretch-backports
This will install the files I showed above for you automatically! And thus automatically schedule a certbot timer for you, which runs the service, which runs again the renew.
Manually running a renew is always possible via:
sudo /usr/bin/certbot renew
Can be forced via --force-renewal flag. For more info see the help text of renew:
/usr/bin/certbot --help renew
Files part of the certbot package (incl. but not limited by):
dpkg-query -L certbot
...
/lib/systemd/system/certbot.service
/lib/systemd/system/certbot.timer
...
Normally while you run a certbot for any webserver in an Ubuntu 16.04 server it automatically creates a cron
#cat /etc/cron.d/certbot
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew
I added the following line to /etc/crontab to run renewal attempt daily on a random minute between 00:00 and approximately 16:40:
1 1 * * * root sleep ${RANDOM:0:3}m && /home/admin/certbot-auto renew --quiet --no-self-upgrade --authenticator webroot --installer apache -w /var/www/mywebroot
Works great for more than a year now.
The renew command itself may vary for you - I used webroot as it seemed most robust at that time.

solr / tomcat7 doesn't come back up after a crash

I keep getting issues with Solr crashing on my server. Its hardly a busy site, so I'm baffled as to why it keeps doing it.
Anyway, as an intermediary - I'm written a shell script that runs on a cron as root:
#!/bin/bash
declare -a arr=(tomcat7 nginx mysql);
for i in "${arr[#]}"
do
echo "Checking $i"
if (( $(ps -ef | grep -v grep | grep $i | wc -l) > 0 ))
then
echo "$i is running!!!"
else
echo "service $i start\n"
service $i start
fi
done
# re-run, but this time do a restart if its still not going!
for i in "${arr[#]}"
do
echo "Checking $i"
if (( $(ps -ef | grep -v grep | grep $i | wc -l) > 0 ))
then
echo "$i is running!!!"
else
service $i restart
fi
done
..then this cron (as root)
*/5 * * * * bash /root/script-checks.sh
The cron itself seems to run just fine:
Checking tomcat7
service tomcat7 start\n
Checking nginx
nginx is running!!!
Checking mysql
mysql is running!!!
Checking tomcat7
Checking nginx
nginx is running!!!
Checking mysql
mysql is running!!!
...and Tomcats status seems ok:
root#domain:~# service tomcat7 status
â tomcat7.service - LSB: Start Tomcat.
Loaded: loaded (/etc/init.d/tomcat7)
Active: active (exited) since Mon 2016-03-21 06:33:28 GMT; 4 days ago
Process: 2695 ExecStart=/etc/init.d/tomcat7 start (code=exited, status=0/SUCCESS)
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
...yet my script, can't connect to Solr:
Could not parse JSON response: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "Can't connect to loc...") at /srv/www/domain.net/www/cgi-bin/admin/WebService/Solr/Response.pm line 42. Can't connect to localhost:8080 Connection refused at /usr/share/perl5/LWP/Protocol/http.pm line 49.
If I manually run a "restart":
service tomcat7 restart
...it then starts working again. Its almost like the 2nd part in my shell script isn't working.
Any suggestions?
My Solr versions are as follows:
Solr Specification Version: 3.6.2.2014.10.31.18.33.47
Solr Implementation Version: 3.6.2 debian - pbuilder - 2014-10-31 18:33:47
Lucene Specification Version: 3.6.2
UPDATE: I've read that sometimes updating the maxThreads can help with crashes, so I've changed it to 10,000:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="10000" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
I guess time will tell, to see if this fixes the issue.
Ok, well I never got to the bottom of why it wouldn't restart... but I have worked out why it was crashing. Before, we had it on 2048mb RAM Linode server, but when we moved over to Apache2, I setup a 1024Mb server, and was going to upgrade it to 2048mb one we had it all working. However, we put it live - but I forgot to update it to the 2048mb server, so Nginx/Apache2/Tomcat/MySQL etc, were all trying to run on a pretty slow server.
We found that Solr was dying with an OOM (out of memory) error, which is what gave us the clue.
Hopefully this helps someone else, who may come across this.

Calabash no colors in output

I have a Android device connected to my PC.
Running a calabash test I use the following command:
calabash-android run <NAME>.apk features/<NAME>.feature
Doing so I always get the following error even so I have ANSICON installed.
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
There are also no colors (using MINGW32 on a 64bit-win having ANSICON installed running it with -p and -i).
$ ansicon.exe --help ANSICON by Jason Hood .
Version 1.66 (21 September, 2013). Freeware.
http://ansicon.adoxa.vze.com/
How can I make this work?
Any help would be appreciated!
Thank you!
I have not tried this, but I found this blog post that writes about the same problem http://qastuffs.blogspot.dk/2011/02/how-to-install-ansicon-for-cucumber-to.html
So it could be worth a try.
Copied from the blog
Anyway, here are the steps on how to install ansicon.exe:
Download and unzip the file from https://github.com/adoxa/ansicon/downloads
open cmd and navigate to the unzipped folder
Navigate to x64 (if you have a 64 bit machine) otherwise navigate to x86
Type ansicon.exe -h and you will get the following: D:\Data\ansicon\x86>ansicon.exe -h ANSICON by Jason Hood . Version
1.32 (22 December, 2010). Freeware. http://ansicon.adoxa.cjb.net/
Process ANSI escape sequences in Win32 console programs.
ansicon -i|I | -u|U ansicon [-m[]] [-p | -e|E string | -t|T [file(s)]
| program [args]]
-i install - add ANSICON to the AutoRun entry (implies
-p) -u uninstall - remove ANSICON from the AutoRun entry -I -U use local machine instead of current user -m use grey on black ("monochrome") or as default color -p
hook into the parent process -e echo string -E
echo string, don't append newline -t display files ("-"
for stdin), combined as a single stream -T display files,
name first, blank line before and after program run the
specified program nothing run a new command processor, or
display stdin if redirected
is one or two hexadecimal digits; please use "COLOR /?" for details.
5. Execute 'ansicon.exe -i' to install and add ansicon to your Windows
6. Run your cucumber 0.10.0 test and you should get the coloured output result on Windows

Unable to run “gearman” command line tool with gearman 1.1.6

I am trying to run the example on "http://gearman.org/getting_started" on Ubuntu in VirtualBox environment.
At first I tried to download an old version 0.16 by using apt-get install gearman-job-server, apt-get install gearman-tools and everything worked well. The server ran in the background, I was able to create 2 workers and verify that I can call them by creating a client.
I decided to download and compile the latest version, 1.1.6. Now, I am trying to do the same thing with the new version and I am having errors.
I run the server as admin:
sudo gearmand
The statement
gearadmin --getpid
seems to work - it returns me the process ID of the server. Thus, the server is running, and this answer is not relevant.
Now, I am adding a worker:
gearman -w -f wc -- wc -l
It seems to run.
Nevertheless,
gearadmin --workers
results in something that probably represents and empty list :
33 127.0.0.1 - :
.
(In version 0.16, I was able to see 2 lines, the second showing the registered function name.)
Attempting to run the client
gearman -f wc < /etc/passwd
results in
gearman: gearman_client_run_tasks : flush(GEARMAN_COULD_NOT_CONNECT) localhost:0 -> libgearman/connection.cc:671"
This might be the very same problem described in here - the port not specified, but I have no idea how to do it through the command line tool.
Any idea?
Ok, It looks like the answer in here was the key to success. Probably, the "getting started" section was not updated for a while. Indeed, one must specify a port explicitly for gearmand and gearman .
Server:
sudo gearmand -p 5000
Worker:
gearman -p 5000 -w -f wc -- wc -l
Client:
gearman -p 5000 -f wc < /etc/passwd

Resources