Stop derby server hanging onto the terminal window - terminal

Im running derby server from the command line on ubuntu. Problem is when i start it, it stays running in the terminal window, so it print all its logs straight to terminal. When i close the terminal window, the server shuts down. Is there anyway i can start derby from the command line, and then be able to close the terminal without shutting down the server?

You can suspend it with CTRL-z and run it in the background with bg and then disown %1 (or substitute 1 with the job number shown between the brackets in the suspend message).
Example...
$ bundle exec script/rails s
[1] + 14192 suspended bundle exec script/rails s
$ bg
[1] + 14192 continued bundle exec script/rails s
$ disown %1
$ exit

Another technique is to use your window manager. Set up an application menu item that starts the network server for you, with the various output redirected to files. Then start your server by choosing that menu item.

Related

Command prompt started from batch file closes when operation is stopped

I am using a batch file to open a number of command prompts while I do some development work, however, I often need to restart 1 or more of the programs, while I'm debugging.
Is it possible to change the code to keep the window open to allow me to restart the application?
C:\
cd /d "C:\Users\me\mydir"
start redis-server
start celery worker -A celery_worker.celery --loglevel=info
start python manage.py runserver
I'd like to be able to kill and restart the celery worker / webserver whenever I make a change to the code.
START attempts to start the program directly; if the program uses stdin and stdout, this will invoke the console host to handle it. If you want a window that will remain open, instead of using START, try CMD /K - for the celery command line specifically, change start celery ... to CMD /K celery .... This starts a command prompt and runs the specified command; if the command terminates, the command prompt will remain, waiting for input (and will remain open until you exit it). Look at the output of CMD /?, or the page on cmd at SS64 for more information.

How to tell Bash to not stop the simulations when ssh disconnects?

I am running some simulations on another machine via ssh. Here is what I do
ssh username#ipp.ip.ip.ip
Go to the right directory
cd path/to/folder
And then I just call my executable
.\myexecutable.exe
The issue is that every time the ssh disconnect, the simulations stops. How can I make sure the simulations doesn't stop on the other machine? Will I somehow receive potential error messages (assuming the code will crash) once I reconnect (ssh)?
You should launch a screen or tmux to create a terminal from which you can detach, leave running in the background and later reattach.
Further reading:
http://ss64.com/osx/screen.html
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screen.1.html
You may also want to try out Byobu:
http://byobu.co
run your command as follows : nohup ./myexecutable.exe >nohup.out 2>&1 &
The & is to run the command in the background
The >nohup.out 2>&1 sends your stdout and stderr to nohup.out)
Note the '/' as opposed to '\' - which won't work on osx

executing a script which runs even if i log off

So, I have a long running script (of order few days) say execute.sh which I am planning to execute on a server on which I have a user account...
Now, I want to execute this script so that it runs forever even if I logoff or disconnect from the server??
How do i do that?
THanks
You have a couple of choices. The most basic would be to use nohup:
nohup ./execute.sh
nohup executes the command as a child process and detaches from terminal and continues running if it receives SIGHUP. This signal means sig hangup and will getting triggered if you close a terminal and a process is still attached to it.
The output of the process will getting redirected to a file, per default nohup.out located in the current directory.
You may also use bash's disown functionality. You can start a script in bash:
./execute.sh
Then press Ctrl+z and then enter:
disown
The process will now run in background, detached from the terminal. If you care about the scripts output you may redirect output to a logfile:
./execute.sh > execute.log 2>&1
Another option would be to install screen on the remote machine, run the command in a screen session and detach from it. You'll find a lot of tutorials about this.
nohup (no hangup) it and run it in the background:
nohup execute.sh &
Output that normally would have gone to the screen (STDOUT) will go to a file called nohup.out.

Get bg jobs to fg after closing terminal window/session

TL;DR How can I get a bg (background) job into fg (foreground) after I close the terminal window?
FULL I'm using terminal to start Spotify and put it into background with CTRL+Z and bg. Everything works as expected within this window: fg puts the process again in forground and jobs shows me Spotify as a running process. The problem occurs if I close the terminal window.
After I close the terminal window and open a new terminal window, the jobs command can't find Spotify running in the background. Therefore I can't access the process for stopping or closing anymore.
What is the advantage of this behaviour CTRL+Z, fg, bg & jobs ? And how can I get back my process?
You can search your old process via ps -A. Or ps -A | grep <application name>.
If you found it, then use reptyr <pid> to get the application on your new console.
But if you closed the old terminal, all the terminal applications will probably be closed also, so it's too late.
Use screen, before you start your app. This will help you to reconnect to your session from another terminal.
The job numbers only refer to background processes running under your current shell. The shell couldn't know the job numbers associated with the old shell.

How to close a Terminal window while executing a file with node.js without stopping the process?

When I execute a file with node.js (by typing "node example.js", maybe a http server), then, when I close the Terminal window (Mac OS X Lion), the process is stopped and doesn't answers on requests anymore. The same happens if I type "ctrl c" or "ctrl z". How can I close the Terminal without stopping the process, so my server continues answering on requests.
Use a combination of the nohup prefix command (to keep the process from being killed when the terminal closes) and the & suffix (to run the process in the background so it doesn't tie up the terminal):
nohup node example.js &
You should also look into forever or similar tools that will also automatically restart the server if it crashes, and nodemon which will automatically restart it when you change the code.

Resources