-
Notifications
You must be signed in to change notification settings - Fork 0
/
django-sites
executable file
·94 lines (68 loc) · 1.93 KB
/
django-sites
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/sbin/runscript
### a config in /home/test/conf/django.conf:
# site_user=test
# site_group=nginx
# site_path=/home/test/web/itest
# site_sock=/home/test/web/itest/itest.sock
# site_pid=/home/test/web/itest/itest.pid
# site_python_path=/home/text/lib/python
# site_ext="maxspre=2 minspare=1 maxchildren=10 maxrequests=500"
# FIXME
# outside args not input
opts="${opts} site_start site_stop site_restart"
SITE_CONF_PATH="/home/wwwdev/conf"
DEFAULT_SITE_USER="wwwdev"
DEFAULT_SITE_GROUP="nginx"
start() {
ebegin "Starting Django Sites"
for folder in $SITE_CONF_PATH; do
einfo "search config in $folder"
[ -d $folder ] || continue
for conf in `find $folder -iname "*.conf" -type f`; do
site_start $conf
done
done
}
stop() {
ebegin "Stop Django Sites"
for folder in $SITE_CONF_PATH; do
[ -d $folder ] || continue
einfo "search config in $folder"
for conf in `find $folder -iname "*.conf" -type f`; do
site_stop $conf
done
done
}
# start single site
site_start() {
if [ $# -lt 1 ]; then
echo "usage: django-sites site_start /your/site/config/path/to/setting.conf"
return 1
fi
. $1
# touch pid
[ -f $site_pid ] && ewarn "config $1 already running ($site_pid)" && continue
start-stop-daemon --start \
--user ${site_user:=$DEFAULT_SITE_USER} --group ${site_group:=$DEFAULT_SITE_GROUP} \
--exec /usr/bin/env -- \
PYTHONPATH="$site_python_path" python $site_path/manage.py runfcgi daemonize=true pidfile=$site_pid socket=$site_sock $site_ext
chmod a+rwx $site_sock
einfo "config: $1 started"
return 0
}
site_stop() {
if [ $# -lt 1 ]; then
echo "usage: django-sites site_stop /your/site/config/path/to/setting.conf"
return 1
fi
. $1
start-stop-daemon --stop --pidfile $site_pid
einfo "config: $1 stop"
[ -f $site_pid ] && rm $site_pid
[ -e $site_sock ] && rm $site_sock
return 0
}
site_restart() {
site_stop $@ \
&& site_start $@
}