Makefile
6.52 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
PROJECT_NAME = pybossa
PROJECT_DIR = $(CURDIR)
SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)"
SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)"
ifndef LOCALHOST
ifndef NETWORK_INTERFACE
NETWORK_INTERFACE := $(shell ip route | awk '{print $$5; exit}')
endif
ifdef NETWORK_INTERFACE
LOCALHOST := $(shell ip addr list ${NETWORK_INTERFACE} | grep "inet " | cut -d ' ' -f6 | cut -d/ -f1)
endif
endif
ifndef LOCALHOST
LOCALHOST := localhost
endif
install: uninstall install-dep config
@( \
virtualenv ./env/; \
. ./env/bin/activate; \
pip install -U pip; \
pip install -U uwsgi; \
pip install -U ndg-httpsclient; \
pip install -r requirements.txt; \
)
config:
@ rm -f ./pybossa/translations
@ ln -sf ./pybossa/themes/default/translations/ ./pybossa/translations
@ cp alembic.ini.template alembic.ini
@ sudo service postgresql restart > /dev/null
-@ $(MAKE) -s drop-db > /dev/null
@ $(MAKE) -s create-db
@ $(info Using interface: ${NETWORK_INTERFACE})
@ $(info Using local IP: ${LOCALHOST})
@ cp settings_local.py.tmpl settings_local.py
@ cp ./contrib/${PROJECT_NAME}.wsgi.tmpl ./contrib/${PROJECT_NAME}.wsgi
@ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/${PROJECT_NAME}.wsgi)
@ cp ./contrib/apache/${PROJECT_NAME}.conf.tmpl ./contrib/apache/${PROJECT_NAME}.conf
@ $(call SED_REPLACE_ALL,ServerName localhost,ServerName ${LOCALHOST},./contrib/apache/${PROJECT_NAME}.conf)
@ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/${PROJECT_NAME}.conf)
@ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/${PROJECT_NAME}.conf)
@ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/apache/${PROJECT_NAME}.conf)
@ sudo install -m 755 -p ./contrib/apache/${PROJECT_NAME}.conf /etc/apache2/sites-available/${PROJECT_NAME}.conf
@ sudo a2ensite ${PROJECT_NAME}.conf
@ sudo rm -f /etc/apache2/sites-available/vlibras-wiki.conf /etc/apache2/sites-enabled/vlibras-wiki.conf
@ sudo service redis-server stop
@ sudo update-rc.d -f redis-server remove
-@ sudo killall redis-server
@ cp ./contrib/pybossa.ini.template ./contrib/pybossa.ini
@ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,${PROJECT_DIR},./contrib/pybossa.ini)
@ cp ./contrib/supervisor/rq-scheduler.conf.template ./contrib/supervisor/rq-scheduler.conf
@ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,${PROJECT_DIR},./contrib/supervisor/rq-scheduler.conf)
@ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-scheduler.conf)
@ cp ./contrib/supervisor/rq-worker.conf.template ./contrib/supervisor/rq-worker.conf
@ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,${PROJECT_DIR},./contrib/supervisor/rq-worker.conf)
@ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/rq-worker.conf)
@ cp ./contrib/supervisor/pybossa.conf.template ./contrib/supervisor/pybossa.conf
@ $(call SED_REPLACE_ALL_PATH,/home/pybossa/pybossa,${PROJECT_DIR},./contrib/supervisor/pybossa.conf)
@ $(call SED_REPLACE_ALL_PATH,pybossa.ini,contrib/pybossa.ini,./contrib/supervisor/pybossa.conf)
@ $(call SED_REPLACE_ALL,user=pybossa,user=$$USER,./contrib/supervisor/pybossa.conf)
@ sudo cp ./contrib/supervisor/pybossa.conf /etc/supervisor/conf.d/pybossa.conf
@ sudo cp ./contrib/supervisor/redis-sentinel.conf /etc/supervisor/conf.d/redis-sentinel.conf
@ sudo cp ./contrib/supervisor/redis-server.conf /etc/supervisor/conf.d/redis-server.conf
@ sudo cp ./contrib/supervisor/rq-scheduler.conf /etc/supervisor/conf.d/rq-scheduler.conf
@ sudo cp ./contrib/supervisor/rq-worker.conf /etc/supervisor/conf.d/rq-worker.conf
@ sudo cp ./contrib/redis-supervisor/redis.conf /etc/redis/redis.conf
@ sudo cp ./contrib/redis-supervisor/sentinel.conf /etc/redis/sentinel.conf
@ sudo chown redis:redis /etc/redis/redis.conf
@ sudo chown redis:redis /etc/redis/sentinel.conf
@ while ! sudo service supervisor restart; do echo "fail, retrying ..."; done
@ sudo supervisorctl restart rq-scheduler
@ sudo supervisorctl restart rq-worker
@ sudo supervisorctl restart pybossa
@ sudo service apache2 restart
@ sudo service apache2 reload
@ echo "\33[32;1mYou must create an account to administer the site then copy your API key\\33[0m"
@ $(MAKE) -s api-key
api-key:
@( \
echo -n "\33[34;1mInput your API key from pybossa account: \33[0m"; \
unset APIKEY; \
read APIKEY; \
sed -i "/^export PYBOSSA_API_KEY=/d" ~/.bashrc ; \
sed -i "\$$aexport PYBOSSA_API_KEY=\"$$APIKEY\"" ~/.bashrc; \
echo "\33[33;1mtype: \33[32;1mexport PYBOSSA_API_KEY=\"$$APIKEY\"\\33[0m"; \
echo "\33[33;1mtype: \33[32;1msource ~/.bashrc\\33[0m"; \
echo "\33[33;1mor open a new terminal\\33[0m"; \
)
clean:
@ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete
uninstall: clean
@ rm -rf ./env/
@ rm -f ./settings_local.py
@ rm -f ./contrib/${PROJECT_NAME}.wsgi
@ rm -f ./contrib/apache/${PROJECT_NAME}.conf
@ sudo rm -f /etc/apache2/sites-available/${PROJECT_NAME}.conf
@ sudo rm -f /etc/apache2/sites-enabled/${PROJECT_NAME}.conf
run:
@ ( \
. ./env/bin/activate; \
python main.py; \
)
uninstall-dep:
@ sudo apt-get -y purge --auto-remove apache2 apache2-bin apache2-data apache2-utils supervisor redis-server && sudo apt-get -y autoremove
@ sudo rm -rf "/etc/apache2" "/var/log/apache2" "/var/log/redis" "/var/log/supervisor"
install-dep:
@ sudo apt-get update && \
sudo apt-get install -y git-core \
postgresql postgresql-server-dev-all libpq-dev python-psycopg2 \
python-virtualenv \
python-dev build-essential libjpeg-dev libssl-dev swig libffi-dev \
redis-server \
supervisor \
apache2 apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-wsgi
@ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf
@ sudo a2enconf servername
@ sudo a2enmod headers
-@ sudo a2dissite 000-default.conf
PYBOSSA_DB_USERNAME = pybossa
PYBOSSA_DB_PASSWORD = tester
PYBOSSA_DB_PSQL = psql -c
PYBOSSA_DB_CREATE = ${PYBOSSA_DB_PSQL} \"CREATE USER pybossa WITH PASSWORD '${PYBOSSA_DB_PASSWORD}'\";
PYBOSSA_DB_CREATE += ${PYBOSSA_DB_PSQL} \"CREATE DATABASE pybossa OWNER ${PYBOSSA_DB_USERNAME}\";
PYBOSSA_DB_DROP = ${PYBOSSA_DB_PSQL} \"DROP DATABASE ${PYBOSSA_DB_USERNAME}\";
PYBOSSA_DB_DROP += ${PYBOSSA_DB_PSQL} \"DROP USER ${PYBOSSA_DB_USERNAME}\";
create-db:
@ sudo su postgres -c "${PYBOSSA_DB_CREATE}"
@( \
. ./env/bin/activate; \
python cli.py db_create; \
)
drop-db:
@ sudo su postgres -c "${PYBOSSA_DB_DROP}"