How does the "Stop build" button work in Bamboo? - bamboo

How does the "Stop build" button work in Bamboo? I have a job that calls a Python3 script to run some tests on a machine. Does Bamboo send a Ctrl+C (SIGINT) to the process when "Stop build" is pressed? SIGKILL?
My script uses multiprocessing and has a graceful shutdown when it receives a SIGINT signal, but when I press "Stop build" it seems to kill the main process and let the rest of the processes keep living...

Based on my Bamboo logs it appears that it sends a SIGQUIT signal followed by a SIGTERM signal five seconds later:
17:24:02 Executing kill -3 66265 # this sends SIGQUIT
17:24:07 Killing: 66265
17:24:07 Executing kill 66265 # this sends SIGTERM
By adding a signal handler like so I was able to catch it and gracefully exit my processes:
def signal_handler(self, signum, frame):
print(f"Received a 'kill -{signum}'! Cleaning up...")
self.cleanup()
# put these inside of the main function
signal.signal(signal.SIGQUIT, self.signal_handler)
signal.signal(signal.SIGTERM, self.signal_handler)
According to this post on the Bamboo forums, Bamboo sends SIGTERM to the process but it doesn't mention the SIGQUIT that is sent first.
The above only seems to be true if you enable "Force stop build" in Plan Configuration -> Other. If "Force stop build" is not enabled then "Stop build" does not seem to do anything.

Related

How to send custom signal to kill running process with Goland?

When I run/debug Ginkgo test from Intellij Idea (with Go plugin installed), it does not shut down gracefully if I press "Stop" button.
JustBeforeEach and AfterEach functions do not get executed and process stops immediately. When I run test from console it gracefully shuts down if I press Ctrl+C. How can I make Intellij Idea/Goland to send custom signal in order to stop running process?
My gotest options are: -ginkgo.v -ginkgo.progress -ginkgo.trace -ginkgo.focus=MyTest
GoLand sends a SIGINT then follows with a SIGKILL to terminate the process. You should make your application handle either of those signals before exiting.
On a Linux/Unix OS, you can use the kill command. For example, if you want to send an interrupt signal, you would use kill -2 pid.

Sending the Valgrind to the background

I'v started a process with valgrind to find the leaks with the option --leak-check=full and redirecting the stdout and stderr outputs to a file. But the program seems to be running too long and now I want to send the process to the background so that I can close the terminal and check on the results at later time.
Here I've found that by using ctrl +z it will suspend the process and with bg and disown commands its possible to remove the process from the terminal and run on the background
But when I try that with valgrind the process doesnot respond to the ctrl + z command
Is there an alternative way to send the valgrind process to background? Or am I doing the whole thing wrong?

failed to kill a returning process

I have an invisible mspaint.exe process (no open window) that runs apparently at startup on WINDOWS XP.
I tried the usual ways to kill it, but none of them worked.
1) Task Manager: the process disappears but returns immediately.
2) Command Prompt: if I do
taskkill -f /im mspaint.exe
I receive the SUCCESS message BUT the process mspaint remains, with the same PID.
If I specify the PID number, then I also get the SUCCESS message but the process mspaint.exe remains with a new PID.
3) Process Explorer: the kill command has no effect.
There is a parent svchost.exe process that I killed but still I could not get rid of child process mspaint.exe
Any advice is welcome.
Try right-clicking on mspaint.exe in the processes tab in task manager and selecting "Kill Process Tree".
It seems like it could be a virus. I suggest downloading Malware Bytes (free) and doing a scan. http://www.malwarebytes.org

How to run a PHP script via SSH and keep it running after I quit

I'm trying to restart a custom IRC bot. I tried various commands :
load.php
daemon load.php
daemon load.php &&
But that makes the script execute inside the console (I see all the output) and when I quit the bot quits as well.
The bot author only taught me the IRC commands so I'm a bit lost.
You can install a package called screen. Then, run screen -dm php load.php and resume with screen -dR
This will allow you to run the script in the background, and still be able to use your current SSH terminal. You can also logout and the process will still be running.
Chances are good the shell is sending the HUP signal to all its running children when you log out to indicate that "the line has been hung up" (a plain old telephone system modem reference to a line being "hung up" when disconnected. You know, because you "hang" the handset on the hook...)
The HUP signal will ask all programs to die conveniently.
Try this:
nohup load.php &
The nohup asks for the next program executed to ignore the HUP signal. See signal(7) and the nohup(1) manpages for details. The & asks the shell to execute the program in the background.
Clay's answer of using screen(1) is pretty awesome, definitely look into screen(1) or tmux(1), but I don't think that they are necessary for this problem.
This line might help you
php load.php &

Fork shell script (not &)

I'm accessing a webserver via PHP. I want to update some info in the Apache configs, so I start a shell script that makes the changes. Then I want to stop and restart Apache.
Problem: as soon as I stop Apache, my process stops and my shell script, being a child process, is killed. Apache never restarts. This also happens with Apache restart.
Is there a way to fork an independent, non-child process for the shell script, so I can restart Apache?
Thx,
Mr B
You can use disown:
disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the `-h' option is given, the job is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If jobspec is not present, and neither the `-a' nor `-r' option is supplied, the current job is used. If no jobspec is supplied, the `-a' option means to remove or mark all jobs; the `-r' option without a jobspec argument restricts operation to running jobs.
./myscript.sh &
disown
./myscript.sh will continue running even if the script that started it dies.
Take a look at nohup, may fit you needs.
let's say you have a script called test.sh
for i in $(seq 100); do
echo $i >> test.temp
sleep 1;
done
if you run nohup ./test.sh & you can kill the shell and the process stay alive.