Redirect ouput to /dev/null when restarting apache13

Hello.

I use apache13 port. When I need to restart it, I use /usr/local/etc/rc.d/apache.sh restart.

I have some scripts to create websites (install apache vhosts in a directory, for example). And I need to restart Apache automatically in this script, without print outputs (except errors).

However, I always have outputs:

Code:
/usr/local/etc/rc.d/apache.sh restart 2> /dev/null
Processing config directory: /usr/local/etc/apache/apps/
 Processing config file: /usr/local/etc/apache/apps/mysql
 Processing config file: /usr/local/etc/apache/apps/stat
Processing config directory: /usr/local/etc/apache/sites/
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/wwww.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
Processing config directory: /usr/local/etc/apache/ssl/
 Processing config file: /usr/local/etc/apache/ssl//www.site.net
Processing config directory: /usr/local/etc/apache/domains_save/
Processing config directory: /usr/local/etc/apache/domains_temp/
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net

(I remplaced site names by http://www.site.net)

As you can see, I have many vhosts files. And I want to mask these ouputs (only show errors). I made a apachectl configtest before for don't restart Apache if errors where found.

When I append a > /dev/null at /usr/local/etc/rc.d/apache.sh restart, these outpurs appears. If I append a 2> /dev/null, too.

I do not have this 'problem' with /etc/rc.d/named restart > /dev/null. Only with apache13 port rc script.

Do you have any ideas?

Thanks a lot.

Regards,
 
If you want to see errors only, you should use

Code:
/usr/local/etc/rc.d/apache.sh restart > /dev/null

This will not redirect the error channel (#2) to /dev/null, only the standard output (#1).

You are sending the errors to /dev/null, so you only see standard output. The other way around ..

You can test which channel contains what like this:

Code:
/usr/local/etc/rc.d/apache.sh restart 1>channel1 2>channel2
 
No. I said in my post :
When I append a > /dev/null at /usr/local/etc/rc.d/apache.sh restart, these outpurs appears

That's the problem. I tried 2> /dev/null for testing...

In my case, /usr/local/etc/rc.d/apache.sh restart > /dev/null prints this output.
 
Usually, /usr/local/etc/rc.d/mydaemon > /dev/null works and prints no ouputs (except errors).

So, I do not understand why with apache13 (and only it), outputs are already printed... I have this at the end of my httpd.conf:

Code:
Include /usr/local/etc/apache/apps/
Include /usr/local/etc/apache/sites/
Include /usr/local/etc/apache/ssl/
Include /usr/local/etc/apache/domains_save/
Include /usr/local/etc/apache/domains_temp/

The result of these includes is already printed when I restart the rc script.

Thanks for your advices.

Regards,
 
Does

Code:
/usr/local/etc/rc.d/apache.sh restart 1>channel1 2>channel2
still produce on-screen output? Notice that apache.sh contains a lot of extra and external system calls, which should conform to how you redirect your output, but maybe they don't.
 
Hummm... Other informations:

A rc script always print:
Code:
Stopping daemon_name.
Waiting for PIDS: pid_number, pid_number, pid_number.
Starting daemon_name.

And other informations. In my case, informations about my vhosts included.

When I append a > /dev/null, informations about 'stopping' and 'starting' are not printed. So, my redirect to /dev/null works. But other informations are already printed.

That's why I don't understand. rc informations are on the standard output...
 
On tcsh 2> won't work. IIRC it's >& but this will route stderr and stdout to the same thing.
 
DutchDaemon said:
Does

Code:
/usr/local/etc/rc.d/apache22 restart 1>channel1 2>channel2
still produce on-screen output? Notice that apache.sh contains a lot of extra and external system calls, which should conform to how you redirect your output, but maybe they don't.
Yes, I think apache13 rc script could countains external system calls. In this case, when I call apache.sh, is a solution exist for not print ouput?
 
Well, there are a lot of these lines in apache.sh already (these are from apache22, though):

Code:
/sbin/kldstat -v | grep accf_http [B]>/dev/null 2>&1[/B]
/sbin/kldload accf_http [B]2> /dev/null[/B]

Looks like you have to /dev/null everything yourself, because apache.sh executes these commands in a new shell by the looks of it.
 
The problem is the same when I use 'apachectl startssl > /dev/null': outputs are printed.
 
Both apache.sh and apachectl (which is a shell script) call httpd -k, so they perform the same tasks which result in the same output.
 
Erf. And is there a solution to mask (or redirect to /dev/null) httpd -k outputs? (when it is called by apachectl or apache rc script)
 
clinty said:
Erf. And is there a solution to mask (or redirect to /dev/null) httpd -k outputs? (when it is called by apachectl or apache rc script)

IMO, only by adding > /dev/null to every line in those scripts where commands are executed (there's more than just httpd -k in there), which will become rather pointless, because a port upgrade will simply replace them with new versions.
 
DutchDaemon said:
IMO, only by adding > /dev/null to every line in those scripts where commands are executed (there's more than just httpd -k in there), which will become rather pointless, because a port upgrade will simply replace them with new versions.
apachectl and apache.sh rc script call /usr/local/sbin/httpd.
However, a /dev/null appened to httpd -DSSL does not solve the problem.
A VAR=`/usr/local/sbin/httpd -DSSL` prints output messages :\

Really, I do not understand. httpd is a binary. All scripts call it. The problem come with httpd binary.
 
If you're in tcsh, try this (or replace apachectl with the offending script in question) :

Code:
% apachectl restart >&output.log

That should redirect everything to the output.log file
 
Wa, this command works! I didn't know it!
Thanks a lot. Now, I can make a apachectl >&/dev/null
 
So separating/redirecting channels isn't even possible in tcsh? Tsk.
 
Back
Top