I wrote a bash script to start a Django development sever, however, I want to be able to quit the server while it's running with a bash script as well. I'm writing a web app for Koding.com that starts a Django process in an online terminal linked to the user's personal VM by running a bash script with a press of a button, and I want users to be able to end the process with a press of a button as well. I know that control C would end the process, but I haven't been able to find out how to do that in a bash script. How could I go about doing this? Thanks!
UPDATE: I ultimately combined my selected answer for this question and this answer from another question I asked (how to run unix commands in django shell) to solve my problem: https://stackoverflow.com/a/22777849/2181017
You can kill the process listening on 8000/TCP:
fuser -k 8000/tcp
The fuser
command shows which processes are using the named files, sockets, or filesystems and the -k
option kills them as well.
Wait, just to clarify, there's no way to temporarily exit that django shell thing so that I could run a unix command?
When you start the development server it will run in foreground, blocking the prompt. You can pause the task that is running in foreground by hitting CTRL+Z
, and then send the task to background running the bg
command (I assume you are running the bash shell or a lookalike). The jobs
command will list paused tasks or tasks running in background. You can bring a task to foreground using the fg
command.
Please refer to the bash man page (man bash
).
what about GNU screen? http://www.gnu.org/software/screen/
screen
./manage.py runserver 0.0.0.0:8000
ctrl + a then d (this will detach from screen)
exit (from the shell)
when you need to stop, login back in the shell
screen -r
ctrl + c
exit (from screen)
exit (from the shell)
put this in ~/.screenrc
for a nice screen statusline
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With