forked from os2display/vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
916 lines (757 loc) · 23.3 KB
/
bootstrap.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
#!/usr/bin/env bash
set -eo pipefail
if [[ $MODE == 'dev' ]]; then
echo "Provisioning in DEVELOPMENT mode - git-cloned bundles will be used"
fi
if [[ $MODE == 'demo' ]]; then
echo "Provisioning in DEMO mode"
fi
# size of swapfile in megabytes
swapsize=8000
echo 'swapfile not found. Adding swapfile.'
fallocate -l 10000M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
# APT
echo "Updating APT"
apt-get update > /dev/null 2>&1
# Set timezone.
echo "Setting up timezone..."
echo "Europe/Copenhagen" > /etc/timezone
/usr/sbin/dpkg-reconfigure --frontend noninteractive tzdata > /dev/null 2>&1
# Set locale
echo "Setting up locale..."
echo en_GB.UTF-8 UTF-8 > /etc/locale.gen
echo en_DK.UTF-8 UTF-8 >> /etc/locale.gen
echo da_DK.UTF-8 UTF-8 >> /etc/locale.gen
/usr/sbin/locale-gen > /dev/null 2>&1
export LANGUAGE=en_DK.UTF-8 > /dev/null 2>&1
export LC_ALL=en_DK.UTF-8 > /dev/null 2>&1
/usr/sbin/dpkg-reconfigure --frontend noninteractive locales > /dev/null 2>&1
# Add dotdeb
cat > /etc/apt/sources.list.d/dotdeb.list <<DELIM
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
deb http://packages.dotdeb.org wheezy-php56 all
deb-src http://packages.dotdeb.org wheezy-php56 all
DELIM
wget http://www.dotdeb.org/dotdeb.gpg > /dev/null 2>&1
apt-key add dotdeb.gpg > /dev/null 2>&1
rm dotdeb.gpg
apt-get update > /dev/null 2>&1
# Mysql
echo "Configuring mysql"
debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password password vagrant' > /dev/null 2>&1
debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password_again password vagrant' > /dev/null 2>&1
apt-get install -y mysql-server > /dev/null 2>&1
# PHP5
echo "Installing php"
apt-get install -y php5-fpm php5-cli php5-xdebug php5-mysql php5-curl php5-gd git > /dev/null 2>&1
# Used by os2display bundle tests
apt-get install -y php5-sqlite > /dev/null 2>&1
sed -i '/;date.timezone =/c date.timezone = Europe/Copenhagen' /etc/php5/cli/php.ini
sed -i '/;date.timezone =/c date.timezone = Europe/Copenhagen' /etc/php5/fpm/php.ini
sed -i '/upload_max_filesize = 2M/cupload_max_filesize = 256M' /etc/php5/fpm/php.ini
sed -i '/post_max_size = 8M/cpost_max_size = 300M' /etc/php5/fpm/php.ini
sed -i '/;listen.owner = www-data/c listen.owner = vagrant' /etc/php5/fpm/pool.d/www.conf
sed -i '/;listen.group = www-data/c listen.group = vagrant' /etc/php5/fpm/pool.d/www.conf
sed -i '/;listen.mode = 0660/c listen.mode = 0660' /etc/php5/fpm/pool.d/www.conf
# Set php memory limit to 256mb
sed -i '/memory_limit = 128M/c memory_limit = 256M' /etc/php5/fpm/php.ini
# Redis
echo "Installing redis"
apt-get install -y redis-server > /dev/null 2>&1
# Memcache
echo "Installing memcache"
apt-get install -y memcached php5-memcached > /dev/null 2>&1
# APC
# APC is disabled until we find a way to get it installed, the version of
# ubuntu we currently use is not able to resolve a package.
# echo "Configuring APC"
# apt-get install -y php-apc > /dev/null 2>&1
#
# cat > /etc/php5/fpm/conf.d/apc.ini <<DELIM
# apc.enabled=1
# apc.shm_segments=1
# apc.optimization=0
# apc.shm_size=64M
# apc.ttl=7200
# apc.user_ttl=7200
# apc.num_files_hint=1024
# apc.mmap_file_mask=/tmp/apc.XXXXXX
# apc.enable_cli=1
# apc.cache_by_default=1
# DELIM
# x-debug
echo "Configure x-debug"
cat << DELIM >> /etc/php5/fpm/conf.d/20-xdebug.ini
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=192.168.50.1
xdebug.remote_port=9000
xdebug.remote_autostart=0
DELIM
# Nginx
echo "Installing nginx"
apt-get install -y nginx > /dev/null 2>&1
unlink /etc/nginx/sites-enabled/default
# Setup web root
ln -s /vagrant/htdocs /var/www
# Config files into nginx
cat > /etc/nginx/sites-available/admin.os2display.vm.conf <<DELIM
server {
listen 80;
server_name admin.os2display.vm;
root /vagrant/htdocs/admin/web;
rewrite ^ https://\$server_name\$request_uri? permanent;
access_log /var/log/nginx/admin_access.log;
error_log /var/log/nginx/admin_error.log;
}
# HTTPS server
#
server {
listen 443;
server_name admin.os2display.vm;
root /vagrant/htdocs/admin/web;
client_max_body_size 300m;
access_log /var/log/nginx/admin_access.log;
error_log /var/log/nginx/admin_error.log;
location / {
# try to serve file directly, fallback to rewrite
try_files \$uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)\$ /app_dev.php/\$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|\$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)\$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param HTTPS off;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
location /bundles/ {
add_header 'Access-Control-Allow-Origin' "*";
}
location /proxy/ {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_buffering off;
proxy_pass http://nodejs_search/;
proxy_redirect off;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://nodejs_search;
}
ssl on;
ssl_certificate /etc/ssl/nginx/server.cert;
ssl_certificate_key /etc/ssl/nginx/server.key;
ssl_session_timeout 5m;
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl_prefer_server_ciphers On;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
}
DELIM
cat > /etc/nginx/sites-available/screen.os2display.vm.conf <<DELIM
server {
listen 80;
server_name screen.os2display.vm;
root /vagrant/htdocs/screen;
rewrite ^ https://\$server_name\$request_uri? permanent;
access_log /var/log/nginx/screen_access.log;
error_log /var/log/nginx/screen_error.log;
}
# HTTPS server
#
server {
listen 443;
server_name screen.os2display.vm;
root /vagrant/htdocs/screen;
client_max_body_size 300m;
access_log /var/log/nginx/screen_access.log;
error_log /var/log/nginx/screen_error.log;
location / {
try_files \$uri \$uri/ /index.html;
}
location /proxy/ {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_buffering off;
proxy_pass http://nodejs_middleware/;
proxy_redirect off;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://nodejs_middleware;
}
ssl on;
ssl_certificate /etc/ssl/nginx/server.cert;
ssl_certificate_key /etc/ssl/nginx/server.key;
ssl_session_timeout 5m;
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl_prefer_server_ciphers On;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
}
DELIM
cat > /etc/nginx/sites-available/search.os2display.vm.conf <<DELIM
upstream nodejs_search {
server 127.0.0.1:3010;
}
server {
listen 80;
server_name search.os2display.vm;
rewrite ^ https://\$server_name\$request_uri? permanent;
access_log /var/log/nginx/search_access.log;
error_log /var/log/nginx/search_error.log;
}
# HTTPS server
#
server {
listen 443;
server_name search.os2display.vm;
access_log /var/log/nginx/search_access.log;
error_log /var/log/nginx/search_error.log;
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_buffering off;
proxy_pass http://nodejs_search/;
proxy_redirect off;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://nodejs_search;
}
ssl on;
ssl_certificate /etc/ssl/nginx/server.cert;
ssl_certificate_key /etc/ssl/nginx/server.key;
ssl_session_timeout 5m;
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl_prefer_server_ciphers On;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
}
DELIM
cat > /etc/nginx/sites-available/middleware.os2display.vm.conf <<DELIM
upstream nodejs_middleware {
server 127.0.0.1:3020;
}
server {
listen 80;
server_name middleware.os2display.vm;
rewrite ^ https://\$server_name\$request_uri? permanent;
access_log /var/log/nginx/search_access.log;
error_log /var/log/nginx/search_error.log;
}
# HTTPS server
#
server {
listen 443;
server_name middleware.os2display.vm;
access_log /var/log/nginx/search_access.log;
error_log /var/log/nginx/search_error.log;
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_buffering off;
proxy_pass http://nodejs_middleware/;
proxy_redirect off;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://nodejs_middleware;
}
ssl on;
ssl_certificate /etc/ssl/nginx/server.cert;
ssl_certificate_key /etc/ssl/nginx/server.key;
ssl_session_timeout 5m;
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl_prefer_server_ciphers On;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
}
DELIM
# Symlink
ln -s /etc/nginx/sites-available/search.os2display.vm.conf /etc/nginx/sites-enabled/search.os2display.vm.conf
ln -s /etc/nginx/sites-available/middleware.os2display.vm.conf /etc/nginx/sites-enabled/middleware.os2display.vm.conf
ln -s /etc/nginx/sites-available/admin.os2display.vm.conf /etc/nginx/sites-enabled/admin.os2display.vm.conf
ln -s /etc/nginx/sites-available/screen.os2display.vm.conf /etc/nginx/sites-enabled/screen.os2display.vm.conf
# SSL
mkdir /etc/ssl/nginx
openssl req -x509 -sha256 -nodes -days 1460 -newkey rsa:2048 -keyout /etc/ssl/nginx/server.key -out /etc/ssl/nginx/server.cert -subj "/C=DK/L=Aarhus/O=OS2Display/CN=admin.os2display.vm/[email protected]"
# Config file for middleware
cat > /vagrant/htdocs/middleware/config.json <<DELIM
{
"port": 3020,
"secret": "MySuperSecret",
"logs": {
"all": "logs/messages.log",
"info": "logs/info.log",
"error": "logs/error.log",
"debug": "logs/debug.log",
"exception": "logs/exceptions.log",
"socket": "logs/socket.log"
},
"admin": {
"username": "admin",
"password": "admin"
},
"cache": {
"port": "6379",
"host": "localhost",
"auth": null,
"db": 0
},
"apikeys": "apikeys.json"
}
DELIM
# Config file for apikeys
cat > /vagrant/htdocs/middleware/apikeys.json <<DELIM
{
"059d9d9c50e0c45b529407b183b6a02f": {
"name": "IK3",
"backend": "https://admin.os2display.vm",
"expire": 300
}
}
DELIM
# Config file for screen
cat > /vagrant/htdocs/screen/app/config.js <<DELIM
window.config = {
"resource": {
"server": "//screen.os2display.vm/",
"uri": 'proxy'
},
"ws": {
"server": "https://screen.os2display.vm/"
},
"apikey": "059d9d9c50e0c45b529407b183b6a02f",
"cookie": {
"secure": false
},
"debug": true,
"version": "dev",
"itkLog": {
"version": "1",
"errorCallback": null,
"logToConsole": true,
"logLevel": "all"
}
};
DELIM
# NodeJS
echo "Installing nodejs"
wget https://deb.nodesource.com/setup_4.x -O /tmp/node_install.sh
chmod 700 /tmp/node_install.sh
/tmp/node_install.sh
apt-get update > /dev/null 2>&1
apt-get install -y nodejs > /dev/null 2>&1
# Search node requirements
echo "Installing search_node requirements"
su vagrant -c "cd /vagrant/htdocs/search_node && ./install.sh" > /dev/null 2>&1
# Search node requirements
echo "Installing middleware requirements"
# @TODO: remove this when logger plugin can handle a non-existing directory
test -d /vagrant/htdocs/middleware/logs || mkdir /vagrant/htdocs/middleware/logs
su vagrant -c "cd /vagrant/htdocs/middleware && ./install.sh" > /dev/null 2>&1
# Search node config
cd /vagrant/htdocs/search_node/
cp example.config.json config.json
cat > /vagrant/htdocs/search_node/mappings.json <<DELIM
{
"e7df7cd2ca07f4f1ab415d457a6e1c13": {
"name": "os2display",
"tag": "private",
"fields": [
{
"field": "title",
"type": "string",
"language": "da",
"country": "DK",
"default_analyzer": "string_index",
"default_indexer": "analyzed",
"sort": true,
"indexable": true,
"raw": false
},
{
"type": "string",
"country": "DK",
"language": "da",
"default_analyzer": "string_index",
"default_indexer": "analyzed",
"sort": true,
"indexable": true,
"raw": false,
"geopoint": false,
"field": "name"
}
],
"dates": [ "created_at", "updated_at" ]
},
"itkdevshare": {
"name": "ITK Dev Share",
"tag": "shared",
"fields": [
{
"field": "title",
"type": "string",
"language": "da",
"country": "DK",
"default_analyzer": "string_index",
"default_indexer": "analyzed",
"sort": true,
"indexable": true,
"raw": false
},
{
"field": "slides",
"indexable": false,
"type": "object",
"raw": false
}
],
"dates": [ "created_at", "updated_at" ]
},
"bibshare": {
"name": "Biblioteks Share",
"tag": "shared",
"fields": [
{
"field": "title",
"type": "string",
"language": "da",
"country": "DK",
"default_analyzer": "string_index",
"default_indexer": "analyzed",
"sort": true,
"indexable": true,
"raw": false
},
{
"field": "slides",
"indexable": false,
"type": "object",
"raw": false
}
],
"dates": [ "created_at", "updated_at" ]
}
}
DELIM
# Config file for apikeys
cat > /vagrant/htdocs/search_node/apikeys.json <<DELIM
{
"795359dd2c81fa41af67faa2f9adbd32": {
"name": "IK3",
"expire": 300,
"indexes": [
"e7df7cd2ca07f4f1ab415d457a6e1c13",
"de831b7bf75d90f6641b4918dde0ddba"
],
"access": "rw"
},
"88cfd4b277f3f8b6c7c15d7a84784067": {
"name": "Share",
"expire": 300,
"indexes": [
"itkdevshare",
"bibshare"
],
"access": "rw"
}
}
DELIM
# Search Node service script
echo "Setting up search_node service"
cat > /etc/init.d/search_node <<DELIM
#!/bin/sh
NODE_APP='app.js'
APP_DIR='/vagrant/htdocs/search_node';
PID_FILE=\$APP_DIR/app.pid
LOG_FILE=\$APP_DIR/app.log
NODE_EXEC=\`which node\`
###############
# chkconfig: - 58 74
# description: node-app is the script for starting a node app on boot.
### BEGIN INIT INFO
# Provides: search_node
# Required-Start: \$network \$remote_fs \$local_fs
# Required-Stop: \$network \$remote_fs \$local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop node
# Description: Node process for app
### END INIT INFO
start_app (){
if [ -f \$PID_FILE ]
then
PID=\`cat $PID_FILE\`
if ps -p \$PID > /dev/null; then
echo "\$PID_FILE exists, process is already running"
exit 1
else
rm \$PID_FILE
start_app
fi
else
echo "Starting node app..."
if [ ! -d \$APP_DIR ]
then
sleep 30
fi
cd \$APP_DIR
\$NODE_EXEC \$APP_DIR/\$NODE_APP 1>\$LOG_FILE 2>&1 &
echo \$! > \$PID_FILE;
fi
}
stop_app (){
if [ ! -f \$PID_FILE ]
then
echo "\$PID_FILE does not exist, process is not running"
exit 1
else
echo "Stopping \$APP_DIR/\$NODE_APP ..."
echo "Killing \`cat \$PID_FILE\`"
kill \`cat \$PID_FILE\`;
rm -f \$PID_FILE;
echo "Node stopped"
fi
}
case "\$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
stop_app
start_app
;;
status)
if [ -f \$PID_FILE ]
then
PID=\`cat \$PID_FILE\`
if [ -z "\`ps ef | awk '{print \$1}' | grep "^\$PID\$"\`" ]
then
echo "Node app stopped but pid file exists"
else
echo "Node app running with pid \$PID"
fi
else
echo "Node app stopped"
fi
;;
*)
echo "Usage: \$0 {start|stop|restart|status}"
exit 1
;;
esac
DELIM
chmod +x /etc/init.d/search_node
# Make middleware service
echo "Making middleware service"
cp /etc/init.d/search_node /etc/init.d/middleware
sed -i 's/search_node/middleware/g' /etc/init.d/middleware
# Update rc
update-rc.d middleware defaults > /dev/null 2>&1
update-rc.d search_node defaults > /dev/null 2>&1
# Create database
echo "Setting up database os2display"
echo "create database os2display" | mysql -uroot -pvagrant > /dev/null 2>&1
# Get composer
echo "Setting up composer"
cd /vagrant/htdocs/admin
curl -sS http://getcomposer.org/installer | php > /dev/null 2>&1
mv /vagrant/htdocs/admin/composer.phar /usr/local/bin/composer
composer global require hirak/prestissimo
# Config file for admin_os2display
cat > /vagrant/htdocs/admin/app/config/parameters.yml <<DELIM
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: os2display
database_user: root
database_password: vagrant
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: da
secret: ThisTokenIsNotSoSecretChangeIt
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true
absolute_path_to_server: 'https://admin.os2display.vm'
zencoder_api: 1234567890
mailer_from_email: [email protected]
mailer_from_name: Webmaster os2display
templates_directory: ik-templates/
sharing_host: https://search.os2display.vm
sharing_path: /api
sharing_apikey: 88cfd4b277f3f8b6c7c15d7a84784067
search_host: https://search.os2display.vm
search_path: /api
search_apikey: 795359dd2c81fa41af67faa2f9adbd32
search_index: e7df7cd2ca07f4f1ab415d457a6e1c13
middleware_host: https://middleware.os2display.vm
middleware_path: /api
middleware_apikey: 059d9d9c50e0c45b529407b183b6a02f
templates_slides_directory: templates/slides/
templates_slides_enabled:
- manual-calendar
- only-image
- only-video
- portrait-text-top
- text-bottom
- text-left
- text-right
- text-top
- ik-iframe
- header-top
- event-calendar
- wayfinding
templates_screens_directory: templates/screens/
templates_screens_enabled:
- full-screen
- five-sections
- full-screen-portrait
site_title: os2display
koba_apikey: b70a6d8511e05aa737ee68126d801558
koba_path: http://192.168.50.21
version: dev
itk_log_version: 1
itk_log_error_callback: /api/error
itk_log_log_to_console: true
itk_log_log_level: all
DELIM
# If we're in dev mode, clone bundles and patch composer.json prior to
# installing.
if [[ $MODE == 'dev' ]]; then
su --login vagrant -c "/vagrant/scripts/install_bundles.sh"
fi
echo "Composer installing admin, this will take a while..."
# We disable xdebug while composer is running to give us a bit more speed.
php5dismod -s cli xdebug
# Use the dev override composer if available.
if [[ -f composer-dev.json ]]; then
su --login vagrant -c "cd /vagrant/htdocs/admin && COMPOSER=composer-dev.json composer install"
else
su --login vagrant -c "cd /vagrant/htdocs/admin && composer install" > /dev/null 2>&1
fi
php5enmod -s cli xdebug
app/console doctrine:migrations:migrate --no-interaction > /dev/null 2>&1
# Setup super-user
echo "Setting up super-user: admin/admin"
app/console fos:user:create --super-admin admin [email protected] admin > /dev/null 2>&1
# Fix /etc/hosts
echo "Add *.os2display.vm to hosts"
echo "127.0.1.1 screen.os2display.vm" >> /etc/hosts
echo "127.0.1.1 admin.os2display.vm" >> /etc/hosts
echo "127.0.1.1 search.os2display.vm" >> /etc/hosts
echo "127.0.1.1 middleware.os2display.vm" >> /etc/hosts
# Elastic search
echo "Installing elasticsearch"
apt-get install openjdk-7-jre -y > /dev/null 2>&1
cd /root
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.deb > /dev/null 2>&1
dpkg -i elasticsearch-1.7.1.deb > /dev/null 2>&1
rm elasticsearch-1.7.1.deb
update-rc.d elasticsearch defaults 95 10 > /dev/null 2>&1
# Elasticsearch plugins
/usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-icu/2.5.0 > /dev/null 2>&1
/usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head > /dev/null 2>&1
# Install gulp
npm install --global gulp > /dev/null 2>&1
su --login vagrant -c "cd /vagrant/htdocs/screen && npm install" > /dev/null 2>&1
# Add symlink.
ln -s /vagrant/htdocs/ /home/vagrant
echo "Starting php5-fpm"
service php5-fpm restart > /dev/null 2>&1
echo "Starting nginx"
service nginx restart > /dev/null 2>&1
echo "Starting mysql"
service mysql start > /dev/null 2>&1
echo "Starting ElasticSearch"
service elasticsearch restart > /dev/null 2>&1
echo "Starting redis"
service redis-server restart > /dev/null 2>&1
echo "Starting search_node"
service search_node start > /dev/null 2>&1
echo "Starting middleware"
service middleware start > /dev/null 2>&1
echo "Adding crontab"
# Pipe any existing crontab to current_crontab
(crontab -l > /dev/null && crontab -l > current_crontab) || true
echo "*/1 * * * * /usr/bin/php /vagrant/htdocs/admin/app/console os2display:core:cron" >> current_crontab
crontab current_crontab
rm current_crontab
# Set up MailHog
mkdir -p /opt/mailhog/bin
chmod -Rv a+x /opt/mailhog
curl --location https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64 > /opt/mailhog/bin/MailHog
chmod a+x /opt/mailhog/bin/MailHog
cat > /etc/init.d/mailhog <<'EOF'
#! /bin/sh
# /etc/init.d/mailhog
#
# MailHog init script.
#
# @author Mikkel Ricky <[email protected]>
### BEGIN INIT INFO
# Provides: mailhog
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MailHog
# Description: MailHog
### END INIT INFO
NAME=mailhog
DAEMON=/opt/mailhog/bin/MailHog
PIDFILE=/var/run/mailhog.pid
SCRIPTNAME=/etc/init.d/$NAME
test -f $DAEMON || exit 5
. /lib/lsb/init-functions
case $1 in
start) start-stop-daemon --start --exec $DAEMON --pidfile $PIDFILE --make-pidfile --background
;;
stop) start-stop-daemon --stop --pidfile $PIDFILE
;;
*) echo "Usage: $SCRIPTNAME {start|stop}"
exit 2
;;
esac
EOF
chmod a+x /etc/init.d/mailhog
update-rc.d mailhog defaults
service mailhog start
cat > /etc/php5/mods-available/mailhog.ini <<'EOF'
sendmail_path = /opt/mailhog/bin/MailHog sendmail
EOF
echo "Done"