PDA

View Full Version : apachectl graceful / cron under root on osX server



Nevets_Anderson
3rd August 2006, 12:07 PM
Ok I have got 2 servers

I've useed a bash script to do this for a number of years on an older mac os X server

its saved as a chmod +x file, and the system crontab runs this file once a day to archive my weblogs



_________________
#!/bin/bash
# Moves and re names current web log (biglog) to archived logs
# Gracefull Restart of apache

mv /weblogs/biglog.log /weblogs/archived_logs/`date '+%d%m%Y'`.log

apachectl graceful
__________________


Cron is running this as root
works fine on the older machine

on the new mac the apachectl graceful dosen't seem to be working
I have to manually run this each day as root

Anyone have any ideas on what may be going on?

Thanks in advance

Nevets

purana
3rd August 2006, 12:20 PM
To have apache recreate the log file, you could simply do a;

kill -1 pid

pid = current process id for an apache process.

The -1 tells the process to reread any config files and reopen any log files. Thus creating new log files since you just moved the old ones while the process was up.

purana
3rd August 2006, 12:30 PM
<div class='quotetop'>QUOTE(Nevets_Anderson &#064; Aug 3 2006, 12&#58;07 PM) 200908</div>

Cron is running this as root
works fine on the older machine

on the new mac the apachectl graceful dosen&#39;t seem to be working
I have to manually run this each day as root

Anyone have any ideas on what may be going on?
[/b]

On the machine it dont work on, it might be possible that the cron process spawned to run it, dont have the path to the apachectl binary... in which case, create a path environment variable in your script pointing to it, or merely add the full path to the command on the command line for the command being ran, to see if it works or not still.

As noted above, you can also use kill -1 on the pid..

mac_man_luke
3rd August 2006, 01:00 PM
I believe cron is not running by default on 10.4

MacDave
3rd August 2006, 01:30 PM
The reason is that Tiger&#39;s crontab doesn&#39;t have a path set at the top. You&#39;ll need to either put the full path to "apachectl" or put a path at the top of your crontab (as it was in Panther&#39;s.)

[Isis:~] dave% which apachectl
/usr/sbin/apachectl

<div class='quotetop'>QUOTE(mac_man_luke &#064; Aug 2 2006, 08&#58;00 PM) 200928</div>

I believe cron is not running by default on 10.4
[/b]


Btw, you believe wrong. Crontab is "deprecated" but still works on both Tiger Client and Server.

Here&#39;s a peek at my Xserve&#39;s: http://www.zarabeth.com/temp/crontab.txt

mac_man_luke
3rd August 2006, 03:20 PM
ok, i knew something like that had happened - could not remember exactly

Nevets_Anderson
3rd August 2006, 04:36 PM
Thanks for your advice all&#33;

spectre I think your&#39;ve hit the nail on the head I&#39;ll let you all know tommrow when my script runs how things go (it&#39;s sitting on a live machine so it&#39;s a bit like keyhole surgery)



Nevets

Nevets_Anderson
4th August 2006, 09:23 AM
Just got in and checked
Now works beaudifully&#33;

Thanks to every one&#33;

purana
4th August 2006, 09:35 AM
Now onto the next challenge :)

Nevets_Anderson
4th August 2006, 12:47 PM
For what it&#39;s worth I thought I&#39;d document what i did

The original top of the tiger crontab looked something like this




# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
#
# minute hour mday month wday who command



New version of crntab looks like this and works a treat



# /etc/crontab
SHELL = /bin/sh
PATH = /etc&#58;/bin&#58;/sbin&#58;/usr/bin&#58;/usr/sbin
HOME = /var/log
#
#minute hour mday month wday who command


Thanks again esp spectre