-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescs.sh
177 lines (148 loc) · 5.83 KB
/
escs.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
##############################################################################
# push django-wsbells staging branch.
cd ~/projects/django-wsbells-code
# clean up all .pyc files.
find . -name "*.pyc" -exec rm -f {} \;
rm -fr ~/projects/django-wsbells-code/static/media
git status
git add *
git commit -a
git push -u origin staging
#############################################################################
# push django-wsbells on master.
cd ~/projects/django-wsbells-code
# clean up all .pyc files.
find . -name "*.pyc" -exec rm -f {} \;
git status
git add *
git commit -a
git push -u origin master
##############################################################################
# merge staging into master.
git checkout master
git merge staging
git push -u origin master
git checkout staging
##############################################################################
# merge master into staging.
git checkout staging
git merge master
git push -u origin staging
git checkout staging
##############################################################################
cd ~/projects/django-wsbells-code
git pull
##############################################################################
# erase database.
cd ~/projects/django-wsbells-code
python manage.py blowdb
./create-superusers
./build-data
python manage.py makemigrations
python manage.py migrate
y
##############################################################################
# create staging branch.
git checkout -b staging
git push --set-upstream origin staging
##############################################################################
# run django-wsbells project.
cd ~/projects/django-wsbells-code
stdbuf -o 0 python manage.py runserver 0.0.0.0:8000
#####k#########################################################################
# create django-wsbells virtualenv.
cd ~/.virtualenvs/
ls -la
# by default, python3 has executable named python in arch linux.
virtualenv django-wsbells -p python3.5
#####k#########################################################################
# activate django-wsbells virtualenv.
cd ~/.virtualenvs/
source django-wsbells/bin/activate
cd ~/projects/django-wsbells-code
##############################################################################
# install django-wsbells dependencies virtualenv.
cd ~/.virtualenvs/
source django-wsbells/bin/activate
cd ~/projects/django-wsbells-code
pip install -r requirements.txt
##############################################################################
# create django-wsbells project/demo.
cd ~/projects/
django-admin startproject wschat django-wsbells-code
##############################################################################
# create core_app app.
cd ~/projects/django-wsbells-code
python manage.py startapp core_app
##############################################################################
# delete last commit.
cd ~/projects/django-wsbells-code
git reset HEAD^ --hard
git push -f
##############################################################################
# check whether rabbitmq is running mqtt server on the port
# for paho.
lsof -i tcp:1883
# check whether rabbitmq is running mqtt websocket server on the
# port for paho.
lsof -i tcp:15675
##############################################################################
# install rabbitmq mqqt plugin.
# Exchanges: messages sent to exchange get dispatched to the queues
# that are binded to it.
# rabbitmq-mqtt plugin has a default exchange amq.topic, consumers(ws clients)
# consume from queues binded to this exchange.
# the /ws thing is one default exchange for ws clients.
rabbitmq-plugins enable rabbitmq_web_mqtt
# https://www.rabbitmq.com/mqtt.html
# http://www.steves-internet-guide.com/into-mqtt-python-client/
# it explains the /ws.
# The /ws is an endpoint exposed by the plugin.
# https://www.rabbitmq.com/web-mqtt.html
# setting up rabbitmq to work on server.
tee -i >(stdbuf -o 0 ssh admin@staging.django-wsbells.com 'bash -i')
# first enable the management tool.
rabbitmq-plugins enable rabbitmq_management
# we can access from here:
# http://opus.test.splittask.net:15672/
# we need to create a test user
# then grant permissions to it on vhost /
# because mqtt plugin uses guest for default
# and guest is not allowed to access remotely the broker.
rabbitmqctl add_user test test
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"
# then we create the configuration file for setting up
# the user for the mqtt plugin.
# the web_mqtt plugin relies on mqtt plugin
# it is a dependency.
# we set the user as test/test.
echo '
[{rabbit, [{tcp_listeners, [5672]}]},
{rabbitmq_mqtt, [{default_user, <<"test">>},
{default_pass, <<"test">>},
{allow_anonymous, true},
{vhost, <<"/">>},
{exchange, <<"amq.topic">>},
{subscription_ttl, 1800000},
{prefetch, 10},
{ssl_listeners, []},
%% Default MQTT with TLS port is 8883
%% {ssl_listeners, [8883]}
{tcp_listeners, [1883]},
{tcp_listen_options, [{backlog, 128},
{nodelay, true}]}]}].
' > /etc/rabbitmq/rabbitmq.config
# point the config file in the rabbitmq-env.conf
# it took me a shitload of time to understand
# that setting up the plugins should be done
# in the rabbitmq.config not in the rabbitmq-env.conf.
echo 'RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq
' > /etc/rabbitmq/rabbitmq-env.conf
rabbitmqctl stop
rabbitmqctl start&
# then we are done, it is enough to run the server.
##############################################################################
# stop django-wsbells running, kill the process.
ps aux | grep mana
##############################################################################