forked from wrr/wwwhisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_wwwhisper_for_site.sh
executable file
·72 lines (59 loc) · 1.48 KB
/
run_wwwhisper_for_site.sh
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
#!/bin/bash
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SCRIPT_DIR="$(cd "$( dirname "$0" )" && pwd)"
SITE_DIR=
err_quit() {
echo 1>&2 ${1}
exit 1
}
usage() {
cat 1>&2 << EOF
Starts uWSGI managed wwwhisper instance for a given site.
The script accepts a single argument - a path to a site-specific
directory that was generated with 'add_protected_site.py'.
Example usage:
${0} -d ./sites/https/example.com/
EOF
exit 1
}
assert_dir_exists() {
if [[ ! -d "${1}" ]]; then
err_quit "Directory '${1}' does not exist."
fi
}
while getopts “hd:” OPTION
do
case ${OPTION} in
h)
usage
;;
d)
SITE_DIR=${OPTARG}
;;
esac
done
if [[ -z ${SITE_DIR} ]]; then
usage
exit 1
fi
if [[ -z ${VIRTUALENV_DIR} ]]; then
VIRTUALENV_DIR=${SCRIPT_DIR}/virtualenv
fi
assert_dir_exists ${SITE_DIR}
# Transform site dir to be an absolute path.
SITE_DIR="$(cd "${SITE_DIR}" && pwd)"
# Sanity check.
assert_dir_exists ${SITE_DIR}
source ${VIRTUALENV_DIR}/bin/activate \
|| err_quit "Failed to activate virtualenv in ${VIRTUALENV_DIR}."
exec uwsgi --socket="${SITE_DIR}/uwsgi.sock"\
--chdir="${SCRIPT_DIR}/"\
--module="wwwhisper_service.wsgi:application"\
--master\
--vacuum\
--processes=1\
--chmod-socket=660\
--plugins=python\
--python-path="${SITE_DIR}/django/"\
--virtualenv="${VIRTUALENV_DIR}"\
|| err_quit "Failed to start uwsgi."