0

I've got a problem, which I cannot solve on my own.

I want to start a bash script on bamboo, so I cannot stop it with ^C. This bash script starts a server, which should run after stopping the script.

If I start the script with the command line, it works as it should, but in order to stop the script I either have to enter Enter or ^C to exit the script. But I cannot do this in Bamboo!

This is a short version of my script:

#!/bin/bash
./Server &

I start it with: /bin/bash ./executeServer.sh &

At the end of the script I tried to write:

exit 0 -> no consequence

kill %1 -> the script stops before starting the server

^C -> unknown command

Thank you!!

fedorqui
  • 275,237
  • 103
  • 548
  • 598
tralala
  • 163
  • 2
  • 16

2 Answers2

0

I think it is a little bit overcomplicated. Actually you do not need to start bash as it is started when You start ./executeServer.sh. Add executable rights to ./executeServer.sh and start it as it is. And do not need to start it in the background, as it already starts Server in the background in the script.

TrueY
  • 7,360
  • 1
  • 41
  • 46
  • Thanks for this hint! This works fine, but doesn't solve my problem. – tralala Jun 06 '13 at 08:25
  • @IsaMunich: Sorry, which script you are talking about? I assume it is the `./executeServer.sh`. It stops automatically, after starting `./Server`. You do not need to stop! So if it is not stopping, then the problem is not in this snipplet. – TrueY Jun 06 '13 at 08:35
  • But why doesn't Bamboo stop? I have to quit this task on my own and then there is "Build was not successfull" but it executes my script as it should... If I start it via the command line, I also have to enter `Enter` to be able to enter a new command. – tralala Jun 06 '13 at 08:39
  • @IsaMunich: Ok. What happen if You just start an empty `bash` script (only having the `#!/bin/bash` line from your script)? Is it stopping properly? – TrueY Jun 06 '13 at 08:44
  • No, unfortunately not. But now I got a hint from a friend of mine: If I enter `nohup ./executeServer.sh` it works! Thank you!!! (Also see: http://stackoverflow.com/questions/8122780/exiting-shell-script-with-background-processes) – tralala Jun 06 '13 at 08:58
  • @IsaMunich: `nohup` just redirects `stdin` to `/dev/null`, `stdout` to `nohup.out` and `stderr` to `stdin` (so to the `nohup.out` file). Maybe the `stdin` caused the problem in your case. – TrueY Jun 06 '13 at 09:33
0

If I enter nohup ./executeServer.sh it works!

Also see: exiting shell script with background processes

Community
  • 1
  • 1
tralala
  • 163
  • 2
  • 16