Using Python for Web development, it is now popular to use UWSGI to invoke Python programs, but using UWSGI for a period of time to find that there is a disadvantage is that every time you change the source code must restart Uwsgi to take effect, including change template file is also, I am a lazy person, Again after a period of repeated changes-reboot after I finally can not endure, decided to write a script of the program directory of the file changes, and timely automatic restart Uwsgi, to liberate my hands do not pay attention to these trivial restart work. It took a bit of time to write a script to determine whether or not to change, and then decide whether to reboot the Uwsgi.
Here's what the script says:
#!/bin/bash # author:cold # Filename:checkchange.sh # useage:sh checkchange.sh [dir] Checkisdir () # Have O NE argument # The argument is a directory for I in ' ls $ | Sed-e ' s//\n/g ' do if [D-$1/$i] then if [$i = = "Bin"-o $i = = "Lib"-o $i = = "Inclu
De "] # does not want to detect the directory (here is the environment file generated using VIRTUALENV) then continue fi dir=" $1/$i " Checkisdir $dir Else files= $files ' \ n '/' $i fi done echo-e $files} whil e true do if [-e/tmp/stat.tmp] then to I in ' checkisdir ' do if [-e/tmp/patch. TMP] then stat $i | grep change >/tmp/nstat.tmp rm-f/tmp/patch.tmp continue fi s Tat $i | grep change >>/tmp/nstat.tmp done diff/tmp/stat.tmp/tmp/nstat.tmp >/tmp/patch.tmp if
[$-eq 0] Then sleep else/etc/init.d/uwsgi.py Restart # change here to the action you want to do patch /tmp/stat.tmp/tmp/patch.tmp fi else for I in ' Checkisdir $ ' do stat $i | grep change >>/tmp/stat.tmp do continue fi done
Here the main test changes after the restart Uwsgi, using the method: My bottle program under/code/python:
Copy Code code as follows:
SH Checkchange.sh/code/python &
If you use SVN, you can refer to the following code:
#!/bin/bash
# Author : Cold
# Filename : checkupdate.sh
# describle : To Check update of SVN While
true
does
Cd/code/python
svn up | grep at >/dev/null 2>&1
if [$-eq 0]
th En sleep
fi svn up
| grep Updated >/dev/null 2>&1
if [$?-eq 0]
then
/etc/in it.d/uwsgi.py Restart
fi
done