Apache httpd terminates on interrupt/breakpoint - linux

I try to use "valgrind --vgdb=yes httpd -X" to debug a service running via httpd, and monitor memory leaks using "monitor leak_check full reachable increased" after each request. The problem is that I cannot interrupt httpd reliably in order to run the "monitor" command in gdb - when I press Ctrl-C in valgrind/httpd terminal, it usually terminates, same when I send kill -INT. I tried different "handle SIGINT/SIGTERM nopass/pass" but with no luck.
Also often, when I just add breakpoints and pause httpd in Eclipse CDT/gdb debugger, httpd terminates, too.
So is it possible to interrupt httpd without making it exit in 90% cases?

Related

Is there a way to safely kill all apache processes running in background?

In a server that I'm working on, There are many apache processes running in background. Is it safe to kill all the processes? If so, please guide me the steps involved in it. I have seen 12 httpd commands running as per result of top command, hope it helps in debugging the problem.
You can kill httpd process using this command
sudo kill `pgrep httpd`
Source: https://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/
OR
Stop the Apache service with:
sudo systemctl stop httpd.service
Prevent Apache from loading when the system boots:
sudo systemctl disable httpd.service
Source: https://phoenixnap.com/kb/how-to-restart-apache-centos-linux

Monit config param - group?

I cannot locate information on the purpose of the group parameter below.
It appears in the documentation as a way to control access to a block, but I can't locate what it does in the following block.
# nginx check:
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start" with timeout 60 seconds
stop program = "/etc/init.d/nginx stop"
if cpu > 50% for 2 cycles then alert
group www-data
Also, in some examples for monit, you'll see an explicit fail condition w/a then restart command. My understanding is the above block handles this for us automatically in the event of a failure. Do I understand this correctly?
Groups are useful for the html GUI interface for Monit and M/Monit. You can use them on the commandline, for example:
monit -g stop
Will stop all processes with that groupname.
The "depends on" command might do what you are thinking of, for example:
check process postfix with pidfile /var/spool/postfix/pid/master.pid
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
depends on postfix_bin
check file postfix_bin with path /usr/sbin/postfix
if failed permission 0755 then unmonitor
If postfix has wrong permissions (or isn't installed) it will not try to start it
Your example above will raise an alert. You need to replace the "alert" with "restart" in order to activate the response of running the stop then start programs automatically on process failure. If you remove the if statement entirely monit will default to doing a restart on failure.

Daemon vs process

I am very new to linux, so I can't quite understand the difference between daemon, foreground process and background process.
As I understand that:
Daemon is simply a background process that runs in the background and has init as its parent process.
Foreground process is a process that we simply invoke from the console.
Then if I run for example nginx inside a docker container with "daemon off" flag that means that nginx will be the foreground process running in the container's console?
What is the problem exactly?
Read this.
To start a container in detached mode, you use -d=true or just -d option.
In foreground mode (the default when -d is not specified), docker run can start the process in the container and attach the console to the process’s standard input, output, and standard error.

Cassandra process killed on exit

When I run dsc cassandra on CoreOS(tarball) using telnet everything comes up fine. But when i close the telnet session, it kills the process. How do i keep the cassandra server running?
I tried sudo bin/cassandra and sudo bin/cassandra -f
both didnt help.
I have no issues in other OS.
Option Description
-f Start the cassandra process in foreground. The default is to start as background process.
-h Help.
-p filename Log the process ID in the named file. Useful for stopping Cassandra by killing its PID.
-v Print the version and exit.
When you are starting cassandra using -f it runs in foreground, hence it will stop as soon as terminal is closed. Same is true for background process.
This will happen with any application you run in telnet session.
You can try
sudo service cassandra start OR nohup bin/cassandra this will keep your application running even when terminal is closed
You need to run Cassandra as a systemd service, as described here: https://coreos.com/os/docs/latest/getting-started-with-systemd.html
Running in the foreground with cassandra -f as your ExecStart= command will allow systemd to manage the state of the process (ideally inside a container).
While this is a bit different than what you're used to, it will lead to an overall more stable mechanism since you'll be using an init system that understands dependency chains, restart and reboot behavior, logging, etc.
Run the process in a screen or tmux session. Detaching from the screen session should allow the process to keep running.

When we exit command prompt when npm start is still running (Node.js), will the process end and the server stop?

I'm new to node and don't really know how things will turn out.
The short answer is: yes, the process will end.
When you run a process in a command prompt (or terminal), then the command processor basically pauses while your process is running. When you shut down the command prompt, you kill whatever process is running in that prompt.
On Linux systems, there's a couple ways of keeping the program around when killing the terminal:
node server.js &
The & tells the terminal to run the job in the background. You'll notice that it returns you immediately to a prompt.
However, when you actually log out, your process will get killed. In order to prevent that, you can use the nohup command (as indicated in the comments by #YTowOnt9):
nohup node server.js &
This tells the process to ignore the HUP (hangup) signal:
From Wikipedia:
nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout.
On Windows system, you can use the START command, but as far as I know there's no way to keep the program running after logging out short of turning the program into a Windows Service (which is a whole other topic):
start node server.js
If you want to prevent the creation of a new window:
start /b node server.js

Resources