If you have multiple cp to the same file then it is too be expected, the first locks the file and the others will hold up.

As said previously if the original copy is failing then look to disk failures, perhaps space problems or hardware problems.

As for the design issue here it would be better for the page that gets the data to randomise the URL rather than randomising the file. Caching would actually work correctly then.


Ta
Ken

-----Original Message----- From: David
Sent: Wednesday, July 18, 2012 9:05 AM
To: [email protected]
Subject: [SLUG] curious spawning of cron caused server crash

I have a script that has been running for several years. It's purpose is
to change the background image to a website randomly every minute.

This morning apache was not responding and the problem seemed to be that
this cron wasn't exiting, resulting in over 2000 processes running.

the output of ps looked like this:

root       381  0.0  0.0   2548  1028 ?        S    04:50   0:00 CRON
root       382  0.0  0.0   1828   508 ?        Ss   04:50   0:00 /bin/sh
-c run-parts --report /etc/cron.minute
root       383  0.0  0.0   1752   504 ?        S    04:50   0:00
run-parts --report /etc/cron.minute
root       384  0.0  0.0   4196  1304 ?        S    04:50   0:00
/bin/bash /etc/cron.minute/background
root       388  0.0  0.0   3480   764 ?        D    04:50   0:00 cp
/var/www/html/sks.com/images/backgrounds/8.jpg
/var/www/html/sks.com/images/backgroundimage.jpg


this is the script, followed by the directory listing.


root@ns:~ # cat /etc/cron.minute/background
#!/bin/bash
# mv a random background pic for website
# images must be named 1.jpg 2.jpg ..... NUMFILES.jpg

DIR=/var/www/html/sks.com/images
NUMFILES=`ls $DIR/backgrounds/*.jpg | wc -l` # no. of images
let "i=($RANDOM%$NUMFILES)+1"
cp $DIR/backgrounds/$i.jpg $DIR/backgroundimage.jpg # cp to CSS location


root@ns:~ # ls /var/www/html/sks.com/images/backgrounds
10.jpg  11.jpg  12.jpg  13.jpg  1.jpg  2.jpg  3.jpg  4.jpg  5.jpg  6.jpg
 7.jpg  8.jpg  9.jpg

Even kill wouldn't work, so I had to hard reboot. After reboot the cron
script seems to be behaving itself again.

Can anyone suggest a reason for this behaviour?


--
David McQuire
0418 310312

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html




-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.2197 / Virus Database: 2437/5137 - Release Date: 07/17/12
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to