Multiple httpd processes running in Docker Container - linux

This is the Dockerfile I created for installing httpd on centos:
#Installing HTTPD
FROM centos:latest
MAINTAINER xxx#gmail.com
RUN yum install -y httpd
EXPOSE 80
#ENTRYPOINT ["systemctl"]
ENTRYPOINT ["/usr/sbin/httpd"]
After building, when I run the container I can see too many httpd process running inside this container:
docker run -d -p 80:80 httpd:4.0 -DFOREGROUND
Output of Docker top command:
UID PID PPID C STIME TTY TIME CMD
root 2457 2443 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2474 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2475 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2476 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2477 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2478 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2491 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2492 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2493 2457 0 04:26 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 2512 2500 0 04:27 pts/0 00:00:00 /bin/bash
apache 2532 2457 0 04:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
Please let me know why so many httpd processes running and how to have only one process with PID 1 ?

Apache runs multiple processes to be ready catch up a client request fast, because spawning a server process is slow, so it is better to have one ready when request comes in.
You can configure their number in httpd.conf through StartServers, MinSpareServers, MaxSpareServers and ServerLimit directives.

Related

Can you take a thread dump of a non-java process?

I have done quite a bit of research, and cant find any documentation on this. I may be using the wrong terminology with the term "thread dump", so I apologize for any lack of knowledge on this topic.
I am looking for a way to take a thread dump of an Apache webserver running on an RHEL AWS instance. The Apache webserver is running on the httpd process. From my understanding, tools like jstack and jmap are specific to taking thread dumps of JVM processes only, and httpd is not compatible.
When I use ps -aux | grep apache I receive the following output of processes.
ps -aux | grep apache
ssm-user 1539 0.0 0.0 112812 960 pts/1 S+ 17:26 0:00 grep apache
apache 1554 0.0 0.2 272752 15488 ? S 16:12 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1713 0.0 0.1 270376 13452 ? S 16:13 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1715 0.0 0.1 270376 13452 ? S 16:13 0:00 /usr/sbin/httpd -DFOREGROUND
apache 1956 0.0 0.1 270556 14080 ? S 13:16 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5700 0.0 0.2 272752 15704 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5701 0.0 0.2 272996 16064 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5703 0.0 0.1 270676 14368 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 5704 0.0 0.2 272720 15636 ? S May22 0:00 /usr/sbin/httpd -DFOREGROUND
apache 11441 0.0 0.2 272776 15744 ? S 04:55 0:00 /usr/sbin/httpd -DFOREGROUND
apache 11442 0.0 0.2 272800 15832 ? S 04:55 0:00 /usr/sbin/httpd -DFOREGROUND
I am also unsure why there are so many of the same process, but I wanted to figure out if its possible to take a thread dump of one of the processes before I dive into solving the duplicate processes.
Are there any tools or commands I can use to accomplish a thread dump of an httpd process?

`ps` of specific container from host

in the host, is there any way to get ps of specific container?
if a container having cgroup foo has processes bar, baz, bam
then like ps --cgroup-id foo should print the result of ps as if in the container(cgroup) as follows:
PID USER TIME COMMAND
1 root 0:00 bar
60 root 0:00 baz
206 root 0:00 bam
it doesn't have to be ps though, I hope it could be made of just one or two commands.
Thanks!
There's a docker top command, e.g.:
$ docker top 9f2
UID PID PPID C STIME TTY TIME CMD
root 20659 20621 0 Oct08 ? 00:00:00 nginx: master process nginx -g daemon off;
systemd+ 20825 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20826 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20827 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20828 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20829 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20830 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20831 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd+ 20832 20659 0 Oct08 ? 00:00:00 nginx: worker process
Or you can exec into the container if the container ships with ps:
docker exec $container_name ps
And if ps isn't included in the container, you can run a different container in the same pid namespace:
$ docker run --pid container:9f2 busybox ps -ef
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
23 101 0:00 nginx: worker process
24 101 0:00 nginx: worker process
25 101 0:00 nginx: worker process
26 101 0:00 nginx: worker process
27 101 0:00 nginx: worker process
28 101 0:00 nginx: worker process
29 101 0:00 nginx: worker process
30 101 0:00 nginx: worker process
31 root 0:00 ps -ef

Suspicious processes when running ps -Af

Can anyone explain for me what to do if i see this on my PS list?!
apache 23687 2388 5 12:40 ? 00:00:02 /usr/sbin/httpd -DFOREGROUND
postfix 23830 1971 0 12:40 ? 00:00:00 cleanup -z -t unix -u
apache 24167 1 0 Jun13 ? 00:00:17 /tmp/wwrr10/wwrr10
apache 24235 1 0 Jun13 ? 00:00:17 /tmp/wwrr/wwrr
apache 24276 1 0 Jun13 ? 00:00:17 /tmp/wwrr20/wwrr20
apache 25509 1 0 Jun11 ? 00:00:30 /tmp/sdvvrtw/sdvvrtw
apache 25546 1 0 Jun11 ? 00:00:30 /tmp/sdvvrtw10/sdvvrtw10
apache 25576 1 0 Jun11 ? 00:00:31 /tmp/sdvvrtw20/sdvvrtw20
apache 29100 1 0 Jun15 ? 00:00:03 /tmp/bgbh/bgbh
apache 29120 1 0 Jun15 ? 00:00:03 /tmp/bgbh10/bgbh10
apache 29140 1 0 Jun15 ? 00:00:03 /tmp/bgbh20/bgbh20
Your Apache installation may be using prefork. This mpm spawns a process per request. So if you are under a bit of load and nowadays knowing how many concurrent requests some browsers send, that list of process is quite usual. if this is the case it can be a misconfiguration in your php files making them behave incorrectly.
You can also try to reducing the number of of clients in the httpd.conf file.

Multiple apache and finding its ports

The following command
[cuser#vdev-b7-5461-4f3c-9d98-7fc3ec6 kafka]$ ps aux|grep apache
apache 3967 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3968 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3969 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3970 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3971 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3972 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3974 0.0 0.0 175412 3188 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3975 0.0 0.0 175276 2696 ? S 03:40 0:00 /usr/sbin/httpd -k start
clduser 9566 0.0 0.0 103244 844 pts/1 S+ 16:41 0:00 grep apache
There are multiple apache process running in my machine. Is there a way for me to determine the files/directory each of these process uses to run it?
Also, would like to know the ports that they are using?
[user#vdev-37-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ netstat -tulpn|grep 80
(No info could be read for "-p": geteuid()=500 but you should be root.)
tcp 0 0 :::80 :::* LISTEN -
This above command shows port 80 is being used but I want to know what process is using it?
[duser#vpsq-dev-4ac0b737-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ find / -iname apache 2>/dev/null
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.4.0-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache

Linux Runlevel 1: start programm

I'm trying to automatically start a process when I enter runlevel 1 by init 1. It's a watchdog which has to send a life signal all the time therefore in runlevel 1 too! But when runlevel 1 is entered each process is killed and the system switches to runlevel S. I tried to tell linux to start my process by update-rc.d -f watchdog 99 1 S .. The resulting entries in /etc/rc1.d/ and /etc/rcS.d/ are:
/etc/rc1.d/:
.
.
.
S30killprocs -> ../init.d/killprocs
S90single -> ../init.d/single
S99watchdog -> ../init.d/watchdog
.
.
.
/etc/rcS.d/:
.
.
.
S01glibc.sh -> ../init.d/glibc.sh
S02hostname.sh -> ../init.d/hostname.sh
S99watchdog -> ../init.d/watchdog
.
.
.
A ps ax after runlevel 1 was entered sadfully doesn't return my watchdog process. I have to start it manually.
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 init [S]
2 ? S 0:00 [kthreadd]
3 ? S 0:00 [ksoftirqd/0]
4 ? S 0:00 [kworker/0:0]
5 ? S 0:00 [kworker/u:0]
6 ? S 0:00 [rcu_kthread]
7 ? S< 0:00 [khelper]
8 ? S 0:00 [kworker/u:1]
104 ? S 0:00 [sync_supers]
106 ? S 0:00 [bdi-default]
108 ? S< 0:00 [kblockd]
119 ? S 0:00 [khubd]
219 ? S 0:00 [kswapd0]
220 ? S 0:00 [fsnotify_mark]
221 ? S< 0:00 [aio]
314 ? S< 0:00 [scsi_tgtd]
347 ? S< 0:00 [kpsmoused]
349 ? S 0:00 [kworker/0:1]
366 ? S 0:00 [w1_bus_master1]
390 ? S 0:00 [mmcqd/0]
395 ? S 0:00 [jbd2/mmcblk0p2-]
396 ? S< 0:00 [ext4-dio-unwrit]
475 ? S 0:00 [flush-179:0]
4532 ttyS0 Ss 0:00 init [S]
4533 ttyS0 S 0:00 bash
4536 ttyS0 R+ 0:00 ps ax
The system I'm working on is Debian GNU/Linux 5.0 debarm (embedded). Any hints or solution? Thank you.
As said here:
Run Level 1 is known as 'single user' mode. A more apt description
would be 'rescue', or 'trouble-shooting' mode. In run level 1, no
daemons (services) are started.
You have several options to get around this limitation:
Don't use runlevel 1, this is not what it is meant for
Start the watchdog on login (if this is a valid option), e.g. .bashrc.
I solved it by adding following line into /etc/inittab:
~~:S:wait:/etc/init.d/watchdog start
~~:S:wait:/sbin/sulogin
Note: It must be before /sbin/sulogin.

Resources