I wrote apllication for embedded device and I use Qt creator. This is app is some server that open port and wait connections. I want start locally another apllication (for examle the "nc 1.5.1.105 10000") after deploy and start my application on remote device.
How to start another app locally, after deploy my app?
You can add some arguments in
project->run section.
Just add "&" and command you want to execute after launching your app.
If you run gui app you can add something like & xterm -hold -e nc...
Solved by adding Deploy step -> Custom process step:
Command=xterm,
Arguments=-display ":0" -si -sk +bc -mesg -rightbar -sl 1000 -hold -e 'E=1; while [ $E -ne 0 ]; do nc 1.5.1.105 10000;let E=$?; done' &
Related
How can I run a shell script and immediately background it, however keep the ability to inspect its output any time by tailing /tmp/output.txt.
It would be nice if I can foreground the process too later.
P.S.
It would be really cool if you can also show me how to "send" the backgrounded process in to a GNU screen that may or may not have been initialized.
To 'background' a process when you start it
Simply add an ampersand (&) after the command.
If the program writes to standard out, it will still write to your console / terminal.
To foreground the process
Simply use the fg command. You can see a list of jobs in the background with jobs.
For example:
sh -c 'sleep 3 && echo I just woke up' & jobs
To background a currently running process
If you have already started the process in the foreground, but you want to move it to the background, you can do the following:
Press Ctrl+z to put the current process to sleep and return to your shell. This process will be paused until you send it another signal.
Run the bg command to resume the process, but have it run in the background instead of the foreground.
Another way is using the nohup command with & at the end of the line.
Something like this
nohup whatevercommandyouwant whateverparameters &
This will run it in the background and send its output to a nohup.log file.
One easy to use approach that allows managing multiple processes and has a nice terminal UI is hapless utility.
Install with pip install hapless (or python3 -m pip install hapless) and just run
$ hap run my-command # e.g. hap run python my_long_running_script.py
$ hap status # check all the launched processes
$ hap logs 4 # output logs for you 4th background process
$ hap logs -f 2 # continuously stream logs for the 2nd process
See docs for more info.
I need to run the command line dotnet run, after starting the url localhost, I need to run another command like curl.
I could do like it:
dotnet run & sleep 12; curl http://localhost:59406
but if dotnet run delay more then 12 seconds, it will be stopped.
It may be possible to solve with linux commands, but I am not experienced in this.
If that helps, I will use this when building the Azure DevOps pipeline, to run newman tests on localhost
You can extend the sleep time if dotnet run takes longer to start up your application, to make sure your application is started when curl the url localhost
If you use this in azure devops pipeline, you can use two bash tasks to run above command. The first bash task run dotnet run & to start your application in the background. The second bash task run curl to curl url localhost. See below yaml pipeline example.
- bash: |
#cd ConnectionWeb/ConnectionWeb
#dotnet restore
dotnet run &
- bash: |
curl http://localhost:8881
I tried adding a Meteor build for Sublime Text as follow :
{
"cmd": "meteor",
"working_dir": "${project_path}",
"shell": true
}
This build requires to save a file (.sublime-project) in the project's root folder. And it works... sort of. It just won't stop. Even closing Sublime, meteor will not stop and I have to ps and kill the process manually. I have tried the "Cancel Build" menu, and it does write (Cancelled), but meteor is still running.
It is even possible to stop the build command from Sublime? Can someone share their .sublime-build file for meteor?
Thank you.
I don't totally agree with you on the comment section, but I think it gonna be easy to solve your problem. I have a start script to start my meteor on the server and local like this
# start.sh
if [ "$1" = "local" ]; then
echo "Local mode is running"
nohup meteor --settings config/settings.json >> log.txt 2>&1 &
else
echo "Server mode is running"
nohup meteor --settings config/settings.server.json >> log.txt 2>&1 &
fi
echo $! > save_pid.txt
and this is the stop script
#stop.sh
kill -9 `cat save_pid.txt`
Now what you need to do is making the build start on Sublime to call the start script and cancel to call the stop script
Can I use node-inspector with meteor?
I tried "--debug" option, and succeed to connect debug port.
But, cannot to access my codes.
exec "$DEV_BUNDLE/bin/node" "--debug" "$METEOR" "$#"
You might have countered the same problem like I have:
On Linux machine, Meteor script will spawn two processes:
Process1: node "meteor files"
Process2: node "your meteor files"
When you run exec "$DEV_BUNDLE/bin/node" "--debug" "$METEOR" "$#", it spawn process1 in debug mode but process2 still run in normal mode. This is why you can not see your files.
I just run the regular meteor script and send kill -s USR1 to process2 then you can see your file in node-inspector
I am trying to create a Jenkins job that restarts a program that runs all the time on one of our servers.
I specify the following as the command to run:
cd /usr/local/tool && ./tool stop && ./tool start
The script 'tool' contains a line like:
nohup java NameOfClass &
The output of that ends up in my build console instead of in nohup.out, so the job never terminates unless I terminate it manually, which terminates the program.
How can I cause nohup to behave the same way it does from a terminal?
If I understood the question correctly, Jenkins is killing all processes at the end of the build and you would like some process to be left running after the build has finished.
You should read https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller
Essentially, Jenkins searches for processes with some secret value in BUILD_ID environment variable. Just override it for the processes you want to be left alone.
In the new Pipeline jobs, setting BUILD_ID no longer prevents Jenkins from killing your processes once the job finishes. Instead, you need to set JENKINS_NODE_COOKIE:
sh 'JENKINS_NODE_COOKIE=dontKillMe nohup java NameOfClass &'
See the wiki on ProcessTreeKiller and this comment in the Jenkins Jira for more information.
Try adding the & in the Jenkins build step and redirecting the output using > nohup.out.
I had a similar problem with runnning a shell script from jenkins as a background process. I fixed it by using the below command:
BUILD_ID=dontKillMe nohup ./start-fitnesse.sh &
In your case,
BUILD_ID=dontKillMe nohup java NameOfClass &