0
votes

I'm new to writing bash scripts and I would like to write one to start and stop multiple Django applications.

For the stopping one, I've found a command pkill -f runserver which killed all running apps. However, for starting multiple applications, I cant seem to get it working. When I run one manage.py runserver command, it won't proceed onward from the first application unless I press ctrl + c.

Is there a way to run multiple django application within one bash script?

Thanks in advance.

2
you could always add then & at the end of the command (i.e. ``` python manage.py runserver &; and if you're fine with using pkill```, then that could work. - ewong
Hi, thank you :) using and worked for me. Out of curiosity, what are the other ways to kill or stop django applications that are running? THanks - joo hwan kwon
if I know there isn't going to be any other python jobs running, I just killall python; but more or less I just go through the ps list and kill -9 the pids that are it. You could always script that - ewong

2 Answers

0
votes

Maybe the following information will help to improve your workflow in general. I personally use tmux if I need to run multiple projects from one "solution". Just need some time to get into it. Here is the example of alias(that you could probably put into .bash_profile):

alias run_my_solution_dev="
tmux new -s my_solution_session -d
tmux send-keys -t my_solution_session 'cd ~/my_solution_folder' Enter
tmux split-window -v -t my_project_session:0.0
tmux send-keys -t my_solution_session:0.0 'cd my_project1_folder' Enter
tmux send-keys -t my_solution_session:0.0 'source venv/bin/activate' Enter
tmux send-keys -t my_solution_session:0.0 'python manage.py' Enter
tmux send-keys -t my_solution_session:0.1 'cd my_project2_folder' Enter
tmux send-keys -t my_solution_session:0.1 'source venv/bin/activate' Enter
tmux send-keys -t my_solution_session:0.1 'python manage.py' Enter
tmux attach -t my_solution_session
"

Something like that. Also, you can split another window to have ability to run commands there, like your working window.

0
votes

Take a look at tmuxinator. Maybe it can help you.

https://github.com/tmuxinator/tmuxinator