How can I get a Perl script running inside Apache to display a list of all running processes on the Apache server? - apache

Inside the perl script I'm running the below
my #lines = `ps -ef`;
And currently, when I output the array into my browser I can only see the following processes:
UID PID PPID C STIME TTY TIME CMD
root 1928 1 0 Feb18 ? 00:00:00 /usr/sbin/abrtd
apache 9198 9121 1 17:23 ? 00:00:00 /usr/bin/perl /var/www/cgi-bin/tbchecker.pl
apache 9199 9198 0 17:23 ? 00:00:00 ps -ef
I think the issue is that the apache user needs to have access to see all the processes running on the server, but am not sure.
Could anyone help point me in the right direction?
(OS is Linux centos 6.4)

Your assumption that the apache user "needs to have access to see all the processes running on the server" is false (on a well-configured Apache2 server).
It is recommended to run the apache httpd server processes under a special account with restricted priviledges.
If you really want to change this and you know the implications of it, you can configure Apche2 to run under the root account. The Apache documentation on http://httpd.apache.org/docs/2.4/ is your friend.

There is still the possibility to run the perl script as user root with the SUID bit set. Note that I have not tested whether it will give you the desired output; normal shell scripts can't be run in SUID mode (under Linux, at least) and the shell drops the additional priviledges before executing a command.

Related

How to switch between two Apache installations?

Some time ago I installed Apache 2.2.29 with this manual:
https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew
into this directory:
/usr/local/Cellar/httpd22/2.2.29/bin/httpd
Yesterday I installed Apache 2.4.17 with this manual:
https://www.youtube.com/watch?v=hV52Vs4E1xs
into this directory:
/usr/local/apache2/bin/httpd
Terminal command
which httpd
shows me this:
Server version: Apache/2.2.29 (Unix)
is there any way to switch to 2.4.17?
(I'm on OS X 10.10.5)
Yes of course. Just specify the absolute path.
For example to stop Apache 2.2.9 use the following command:
/usr/local/Cellar/httpd22/2.2.29/bin/apachectl -k stop
Give it a few seconds or use 'ps' to check its finished shutting down and then use the following to start up the 2.4.17 instance:
/usr/local/apache2/bin/apachectl -k start
Note when you machine restarts it my revert to the old version depending what's in its start up scripts.
Also any config will be specific to each installation so you might find they don't point to the same DocumentRoot so don't display the same website.
You cannot run both under port 80 at the same time. However you could run one under port 80 and one under another port of you wanted both running at exactly the same time.

Cygwin Openssh can't see /etc/sshd_config

I can't get the openssh server to work on Windows Server 2008. I have it working on two other servers, but one of them just won't work.
I run ssh-host-config, and choose privilege separation. Two users are created sshd and sshd_server.
Then I run net start sshd, and I see this:
The CYGWIN sshd service is starting.
The CYGWIN sshd service could not be started.
The service did not report an error.
Then I run cat /var/log/sshd.log and I see this output:
/etc/sshd_config: No such file or directory
I then check permissions on /etc/sshd_config:
-rw-r--r-- 1 sshd_server root 3344 Sep 7 09:15 /etc/sshd_config
So now, it seems sshd cannot see a file which is there and has the right permissions. Even on windows, that file is owned by sshd_server.
had this happen too .
a Procmon session revealed to me that the sshd service was trying to locate /etc in the root directory c:\etc instead of c:\cygwin\etc.
further investigation showed that sshd was loading an incorrect cygwin1.dll which was living in my system PATH environment variable.
solution was to either to remove the bad cygwin1.dll or remove the "bad" path from the system variables and assigning that path it to user specific environment variables.
afterwards running the sshd daemon under a dedicated user who did not have this "bad "path worked as it should.
thanks mark

fabric appears to start apache2 but doesn't

I'm using fabric to remotely start a micro aws server, install git and a git repository, adjust apache config and then restart the server.
If at any point, from the fabfile I issue either
sudo('service apache2 restart') or run('sudo service apache2 restart') or a stop and then a start, the command apparently runs, I get the response indicating apache has started, for example
[ec2-184-73-1-113.compute-1.amazonaws.com] sudo: service apache2 start
[ec2-184-73-1-113.compute-1.amazonaws.com] out: * Starting web server apache2
[ec2-184-73-1-113.compute-1.amazonaws.com] out: ...done.
[ec2-184-73-1-113.compute-1.amazonaws.com] out:
However, if I try to connect, the connection is refused and if I ssh into the server and run
sudo service apache2 status it says that "Apache is NOT running"
Whilst sshed in, if run
sudo service apache start, the server is started and I can connect. Has anyone else experienced this? Or does anyone have any tips as to where I could look, in log files etc to work out what has happened. There is nothing in apache2/error.log, syslog or auth.log.
It's not that big a deal, I can work round it. I just don't like such silent failures.
Which version of fabric are you running?
Have you tried to change the pty argument (try to change shell too, but it should not influence things)?
http://docs.fabfile.org/en/1.0.1/api/core/operations.html#fabric.operations.run
You can set the pty argument like this:
sudo('service apache2 restart', pty=False)
Try this:
sudo('service apache2 restart',pty=False)
This worked for me after running into the same problem. I'm not sure why this happens.
This is an instance of this issue and there is an entry in the FAQ that has the pty answer. Unfortunately on CentOS 6 doesn't support pty-less sudo commands and I didn't like the nohup solution since it killed output.
The final entry in the issue mentions using sudo('set -m; service servicename start'). This turns on Job Control and therefore background processes are put in their own process group. As a result they are not terminated when the command ends.
When connecting to your remotes on behalf of a user granted enough privileges (such as root), you can manage system services as shown below:
from fabtools import service
service.restart('apache2')
https://fabtools.readthedocs.org/en/0.13.0/api/service.html
P.S. Its requires the installation of fabtools
pip install fabtools
Couple of more ways to fix the problem.
You could run the fab target with --no-pty option
fab --no-pty <task>
Inside fabfile, set the global environment variable always_use_pty to False, before your target code executes
env.always_use_pty = False
using pty=False still didn't solve it for me. The solution that ended up working for me is doing a double-nohup, like so:
run.sh
#! /usr/bin/env bash
nohup java -jar myapp.jar 2>&1 &
fabfile.py
...
sudo("nohup ./run.sh &> nohup.out", user=env.user, warn_only=True)
...

Selenium: Invalid "already running" error when starting server

I am trying to get the Selenium server up and running. However, when I type:
java -jar selenium-server-standalone-2.0b3.jar
I get an Exception:
Selenium is already running on port 4444. Or some other service is.
I have tried to stop it, just in case it really is running:
http://localhost:4444/selenium-server/driver/?cmd=shutDown
That gets me the message:
ERROR Server Exception: sessionId should not be null; has this session been started yet?
If I just write:
http://localhost:4444/
I get:
HTTP ERROR: 403
Forbidden for Proxy
Ideas?
This worked for me:
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
If selenium server is already running on port 4444 then it will shut down the server and says
OKOK
if selenium is not running on this port 4444 then by hitting above url will give you
"Unable to connect"
try this:
lsof -i -n -P | grep 4444
and kill the process it says is on :4444
One-liner:
kill -9 $(lsof -ti tcp:4444)
The error message Selenium offers up is a little confusing. It really should be telling you you're making a syntax error. I had this problem as well. Make sure the cmd string is PRECISELY like this:
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
That means using the full command shutDownSeleniumServer, and make sure the s in shut is lower-case (That was my mistake).
Hope this helps.
To shut down the server you can use:
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
It will give message OKOK , means it got shutdown. If the server is not running then it will show "This web page not available"
To check the selenium server status , use this
http://localhost:4444/selenium-server/driver/?cmd=getLogMessages
It will give OK if server is running , if not running then it will show webpage not available
If you are using Windows, you can open the task manager and locate the java.exe or javaw.exe process and kill it. This will release port 4444 and you should be able to restart the Selenium server.
I had the same error but no server was running.
Tuned out the java version was in cause. Make sure you are running java 7 or higher:
java -version
lsof returned no results in my case.
On a Ubuntu machine I had to do the following:
sudo netstat -tapen | grep ":4444 "
Reply was like:
tcp6 0 0 XXXXXXXXX:4444 :::* LISTEN 107 31526 **10479**/java
And to kill the Selenium server process identified (in my case) with 10479
sudo kill 10479
In OSX if you follow the command from #HaloWebMaster (lsof -i -n -P | grep 4444) the next step is to take the PID (usually a 4 - 5 digit number indicating the process ID) and run the following command:
kill -9 <PID>
You shouldn't need sudo unless the process was started by another user or root.
If you started Selenium using Java (instead of via whatever testing framework you may or may not be using), you can kill all leftover Selenium instances with:
pkill java
That's guaranteed to kill any java relics (including selenium if started this way) - but be careful here - caveat is that you might be killing other procs too (due to the way pkill works). In my case, I want to kill anything running in the JVM, so this solved it for me.
As per the comment from Goldberg below, note that this will not kill any driver services or browsers running on your system!
I had the same problem , I started my Jboss AP where i have my application deployed and after that tried to run the selenium server and couldn t start. The problem was that Jboss uses the same port that Selenium server uses, so what I did is to start selenium server on a different port
Solution:
java -jar selenium-server-standalone-2.0b3.jar -port 1234 -htmlSuite "*firefox" "http://localhost:8080/" "path to the suite" "path to the results"
For Windows, try this:
taskkill /PID <ProcessID> /F
If you get a 403 error on 127.0.01:4444 and not a 404 one, something is running there. (You're positive it cannot be a previous instance Selenium ? It'd be the most logical.)
Sometimes Selenium continue running in the background after an unexpected exit. I'd suggest checking the running processes, or rebooting the machine if everything else fails.
It happens to me frequently when Hudson asks Selenium-Server to run some tests and it fails in the middle for some reasons. Killing the process solves the problem.
That ERROR Server Exception: sessionId should not be null; has this session been started yet? message comes from Selenium. If you're seeing it, there's a Selenium server running on that port number.
If all the above is not working, please save your work and reboot your system. It will solve the problem
Thanks,
The link of Andre works fine for me.
As 4444 is the default port of Selenium check this as well.

Why does running "apachectl -k start" not work, but "sudo apachectl -k start" does?

I'm working on my OS X with the default installation of Apache. For some reason, when I run the "apachectl" command without the "sudo" I get "no listening sockets available / unable to open logs." I'm guessing this is a permissioning thing, so can someone help me out? I'm using Apache 2.2.
Also, side question, where the the Apache script file that is basically the "exe" that linux executes? I'm trying to intergrate my server with Aptana Studio, and it requires the path to the Apache install. I know in Windows, this would be "C:\path\to\httpd.exe", but I don't know how this works in linux.
Is your server listening on port 80? (Usually) only root is allowed to open ports below 1024. Hence the need for sudo.
As you can see, lots of people wonder how to get around this. One possible solution is to perform port-forwarding on your router. (I'm assuming here that you are behind a router...). Then incoming connections on port 80 can be forwarded to e.g. port 8080. Thus only locally does one need to connect to port 8080. (There may be more elegant solutions... somebody else will post them.)
I think generally (on both OS X and Linux - I'm not sure which one you're referring to) the httpd binary is located at: /usr/sbin/httpd
If you need to be able to restart Apache, and you can't do so as root (for whatever reason..), then you may have to settle for a non 'well known' port.
try this
(with php)
$a = shell_exec('sudo -u root -S /etc/init.d/apache2 restart < /home/$user/passfile');
password should stored in passfile