Start Django automatically after restarting development system/server in Linux
Are you tired of writing script manually whenever you restart your systems to start Django?
Don’t worry about it. Today we are going to learn how to start Django automatically after restarting development or local systems/server in Linux.
Please don’t use this script on the live server, this script is for only development or local system.
Start Django automatically after restarting development or local system/server in Linux
- First open gedit in your Linux system.
Run the following command in terminal.$gedit
- Now we create script for start Django server In gedit
#!/bin/bash clear cd /path/to your/virtual environment #path to your virtual environment . bin/activate #Activate your virtual environment cd /path/to your/project directory #After that go to your project directory python manage.py runserver #run django server
After that save this file with .sh extension. I have saved this file as script.sh in the following example.
3. Run following command in terminal for giving execution permission to your script
$ chmod u+x script.sh
4. To test your script works perfectly, add following command in terminal
$ ./ script.sh
5. After that, you have to create cron job on your machine for run script automatically on reboot give following command in terminal
$ crontab -e
Above command will open crontab window, then add the following line in it:
6. After pressing crtl+x, it will ask you for saving changes
Bravo!!! We have done it. Whenever you restart your machine, Django will run automatically. 😀
I hope you like this article. Share your views to to improve content. Happy Learning !!!
Subscribe for more articles !!