restart Apache when down centos 6 - apache

I need shell script to restart HTTPD when down. I was search on web found some script but its not working showing syntax error.
#!/bin/bash
RESTART="/sbin/service httpd restart"
PGREP="/usr/bin/pgrep"
HTTPD="httpd"
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
and when i run this script its showing error
[root#vmi194867 pydash]# bash -x /scripts/httpd.sh
: No such file or directory/usr/bin/pgrep // path is correct
/scripts/httpd.sh: line 10: syntax error near unexpected token `fi'
/scripts/httpd.sh: line 10: `fi'

Related

Unable to start apache webserver due to ld.so.1: httpd: libonssys.so: open failed

When I do the below I'm able to start and stop apache instance alright
$ sudo -u wsadm -I -H
$ cd /web/apps/perf/apache/2.4.41/https-harsh/bin
$ ./apachectl -k start
However, when I ssh directly to the destination host using wsadm user and try to start the instance I get the below error:
$ ./apachectl -k start
httpd: Syntax error on line 531 of /web/apps/perf/apache/2.4.41/https-harsh/conf/httpd.conf: Cannot load /web/apps/perf/apache/2.4.41/https-harsh/plugin_lib/lib/mod_wl_24.so into server: ld.so.1: httpd: libonssys.so: open failed: No such file or directory
I was suggested to source the profile so I did the below:
`. /home/wsadm/.profile
source /home/wsadm/.profile
However, I still get the same error starting apache webserver instance.
cat /home/wsadm/.profile
…..
.….
WLS_PLUGIN_HOME=/web/apps/perf/sjsws/webserver7/wlsplugins/wlsplugin-1.1
LD_LIBRARY_PATH_64=${WLS_PLUGIN_HOME}/lib:${LD_LIBRARY_PATH_64}
export WLS_PLUGIN_HOME LD_LIBRARY_PATH LD_LIBRARY_PATH_64
…..
As you can see the .profile does not even have apache folder mentioned for any of the variables or paths. Sorry, if I'm taking the thought process in the wrong direction by mentioning the contents of the .profile
Can you please suggest ?
It says it in the error: Syntax Error
httpd: Syntax error on line 531 of /web/apps/perf/apache/2.4.41/https-harsh/conf/httpd.conf: Cannot load /web/apps/perf/apache/2.4.41/https-harsh/plugin_lib/lib/mod_wl_24.so into server: ld.so.1: httpd: libonssys.so: open failed: No such file or directory
This should answer your question: https://www.experts-exchange.com/questions/29088492/Configuration-problem-with-weblogic-connector-module-mod-wl-24-and-apache-2-4-6.html

How do I check the apache config for validity in Red Hat Linux?

My operating system is Red Hat Enterprise Linux 7. This isn't working...
# httpd -t
bash: httpd: command not found
In case it helps, this is the command I run to restart apache on this box...
# systemctl restart httpd24-httpd
But this doesn't work...
# httpd24-httpd -t
bash: httpd24-httpd: command not found
This doesn't work either...
# apachectl -t
bash: apachetl: command not found
Nor does this work...
# apachectl configtest
bash: apachetl: command not found
I know this is a couple months old but ended up here. I ran into the same issue initially, hence why I am here. I found that the location for the new httpd24-httpd wasn't in my env path to execute. While I could added it there, I found the command location and was able to execute.
How I found the command:
sudo find / -name apachectl
The output of the command:
/opt/rh/httpd24/root/usr/sbin/apachectl
Executed the command:
sudo /opt/rh/httpd24/root/usr/sbin/apachectl
Turns out I have to fix my configuration.
httpd: Syntax error on line 56 of /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf: Syntax error on line 40 of /opt/rh/httpd24/root/etc/httpd/conf.modules.d/00-base.conf: Cannot load modules/mod_http2.so into server: libnghttp2-httpd24.so.14: cannot open shared object file: No such file or directory
Interesting that this came up for me, as I've not done anything with the configuration in this regard.
Here's the version I am running.
sudo /opt/rh/httpd24/root/usr/sbin/apachectl -v
Server version: Apache/2.4.34 (Red Hat)
Server built: Mar 17 2020 09:34:59
All the best!
Found something more for this as well from an old bug submitted to Redhat
Bug 1329639
Comment 10
scl enable httpd24 -- /opt/rh/httpd24/root/usr/sbin/apachectl configtest

httpd -k restart : print some info like " service httpd restart "

restarting apache via service command :
service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
I want to be able to get the same output without using the "service" command.
the following command works but does not print anything.
/usr/sbin/httpd -k restart
The "service" command runs the /etc/init.d/httpd script, this script restarts httpd and prints the info.
With /usr/sbin/httpd -k restart, you are restarting httpd without printing anything.
I want to be able to get the same output without using the "service" command.
Option 1
Run the httpd init script:
/etc/init.d/httpd restart
Option 2
You could create a script like the following:
#!/bin/bash
echo "Restarting httpd..."
/usr/sbin/httpd -k restart
Name it 'restart_httpd.sh', for example, and make it executable:
chmod +x restart_httpd.sh
Run it:
./restart_httpd.sh

Apache Start .sh script

#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="/sbin/service httpd restart"
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"
#path to pgrep command
PGREP="pgrep"
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
# find httpd pid
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
exit
this is my script. when i run it i get
: command not foundin/apache_start.sh: line 12:
: command not foundin/apache_start.sh: line 22: pgrep
/usr/local/apache/bin/apache_start.sh: line 29: syntax error: unexpected end of file
what mistake i made. i would be very happy if anybody answer me.
dude, I ran your script and it works fine except the $PGREP ${HTTPD} part, if you want to get a pid why don't you use "pidof" command, and I think in your if statement you are testing the return value of grep, not httpd command(not sure). anyway did you edit this script in word document or in an editor, cause you know this may add some invisible characters to your code.
to debug it, I suggest that you comment out rest of your code where you get the first error and see figure out the solution to that specific error.

invoking remote java process via ssh command

It works like charm form solaris to linux(RHEL5) but gives error when executing from RHEL5 to RHEL5
apache log error:
tcgetattr: Invalid argument
Connection to server20 closed.
it also gives this error in message log:
Jan 20 02:13:39 sj1glm013 kernel: type=1400 audit(1327054419.954:18549): avc: denied { getattr } for pid=18469 comm="sun.sh" path="/web/cgi-bin/remote"
(sun.sh is local script that cgi invokes)
I am invoking a local shell script from CGI web interface, and that shell script executes another program (script) on remote host.
code of shell script:
### it takes parameters form cgi script.
#!/bin/bash
host="$1"
str3="$2"
ssh -t -t -l user $host $str3
exit 0
any inputs..
When I had a similar problem, I just took out the -tt and that solved it.