Now what I do is:
$ lein ring server &
Then what I see is: [1]+ Stopped lein ring server. Then I'm trying to use:
$ fg 1
And also see that it's stopped. What do I do wrong and how can I run ring as a background process?
As lein simply launches a Java process, this answer of course does not apply to ring/leiningen only.
The simplest way might be to use one of the following Linux/UNIX utilities (and some more as well):
screen
detachtty
nohup
Related
A script that keeps updating the log file. data like system time and date, users currently logged in etc for every interval of time say 5 minutes. THE SCRIPT MUST RUN EVEN AFTER THE TERMINAL HAS BEEN CLOSED.
Actually, no.
First of, you don't need sh:
$ ./newscript.sh &
This is enough. This will start a background process. But your terminal is still controlling it. To achieve the behavior you want, do this:
$ disown %1
This will disown the job with the jobspec 1 (which is like an id), which was the one you started beforehand. Now you can close the terminal.
Hurrah!! I would like to answer my question since i have got the solution.
For example, I'm running a script newscript.sh I want to run this in background and continue someother job in the terminal or i can close the terminal.
[yourname # username ~]$ sh newscript.sh &
and hit enter. You will get a PID and your job will be attached to the background.
To kill the same process, use the PID
For eg.,
kill 1205212
Thank you.
I write a shell script for starting two play framework application.
cd /someDirectory
activator "start -Dhttp.port=9001"
cd /anotherDirectory
activator "start -Dhttp.port=9002"
after running the shell script, running process sleeps after starting first application (because play framework stay in shell after start command until pressing Ctrl + D)
How can I say to activator release shell after starting?
Use any process manager you want :
screen
nohup
upstart
systemd
supervisord
BTW, if this is production, you might consider using the start script created when packaging your application.
Use nohupas follows nohup ./script &. It is also useful when starting applications from remote shell.
I'm trying to background a process in a zsh script:
lein servlet run &
but after the script is done jobs shows:
[4] + 98346 suspended (tty input) lein servlet run
If I run lein servlet run & from my command line, it works fine, and doesn't get suspended.
After researching, I learned that (tty input) means the process is waiting for terminal input, but it doesn't actually take input from me (someone must've wrote something hacky). To solve the problem, I gave it fake input:
lein servlet run </dev/zero &
Now it works. :D
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.
I have a master-workers architecture where the number of workers is growing on a weekly basis. I can no longer be expected to ssh or remote console into each machine to kill the worker, do a source control sync, and restart. I would like to be able to have the master place a message out on the network that tells each machine to sync and restart.
That's where I hit a roadblock. If I were using any sane platform, I could just do:
exec('ruby', __FILE__)
...and be done. However, I did the following test:
p Process.pid
sleep 1
exec('ruby', __FILE__)
...and on Windows, I get one ruby instance for each call to exec. None of them die until I hit ^C on the window in question. On every platform I tried this on, it is executing the new version of the file each time, which I have verified this by making simple edits to the test script while the test marched along.
The reason I'm printing the pid is to double-check the behavior I'm seeing. On windows, I am getting a different pid with each execution - which I would expect, considering that I am seeing a new process in the task manager for each run. The mac is behaving correctly: the pid is the same for every system call and I have verified with dtrace that each run is trigging a call to the execve syscall.
So, in short, is there a way to get a windows ruby script to restart its execution so it will be running any code - including itself - that has changed during its execution? Please note that this is not a rails application, though it does use activerecord.
After trying a number of solutions (including the one submitted by Byron Whitlock, which ultimately put me onto the path to a satisfactory end) I settled upon:
IO.popen("start cmd /C ruby.exe #{$0} #{ARGV.join(' ')}")
sleep 5
I found that if I didn't sleep at all after the popen, and just exited, the spawn would frequently (>50% of the time) fail. This is not cross-platform obviously, so in order to have the same behavior on the mac:
IO.popen("xterm -e \"ruby blah blah blah\"&")
The classic way to restart a program is to write another one that does it for you. so you spawn a process to restart.exe <args>, then die or exit; restart.exe waits until the calling script is no longer running, then starts the script again.