-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
151 lines (122 loc) · 6.11 KB
/
install.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
#!/usr/bin/env bash
set -e
if [ "$EUID" -ne 0 ]
then echo "Please run as the root user."
exit
fi
EXCHANGE_DIR=/opt/boundless/exchange
FILE_SERVICE_STORE=$EXCHANGE_DIR/.storage/media/fileservice
FULCRUM_STORE=/opt/geonode/geoserver_data/fulcrum_data
EXCHANGE_SETTINGS=/etc/profile.d/exchange-settings.sh
BEX_SETTINGS=$EXCHANGE_DIR/bex/settings.py
EXCHANGE_URLS=$EXCHANGE_DIR/.venv/lib/python2.7/site-packages/exchange/urls.py
EXCHANGE_CELERY_APP=$EXCHANGE_DIR/.venv/lib/python2.7/site-packages/exchange/celery_app.py
PIP=$EXCHANGE_DIR/.venv/bin/pip
PYTHON=$EXCHANGE_DIR/.venv/bin/python
GEONODE_LAYERS_MODELS=$EXCHANGE_DIR/.venv/lib/python2.7/site-packages/geonode/layers/models.py
MANAGE=$EXCHANGE_DIR/manage.py
CELERY_BEAT_SCRIPT=$EXCHANGE_DIR/celery-beat.sh
grep FILE_SERVICE_STORE $EXCHANGE_SETTINGS && \
sed -i -e "s|export FILE_SERVICE_STORE=.*$|export FILE_SERVICE_STORE=\$\{FILE_SERVICE_STORE\:\-'$FILE_SERVICE_STORE'\}|" $EXCHANGE_SETTINGS || \
sed -i -e "s|set +e|export FILE_SERVICE_STORE=\$\{FILE_SERVICE_STORE\:\-'$FILE_SERVICE_STORE'\}\nset +e|" $EXCHANGE_SETTINGS
grep FULCRUM_UPLOAD $EXCHANGE_SETTINGS && \
sed -i -e "s|export FULCRUM_UPLOAD=.*$|export FULCRUM_UPLOAD=\$\{FULCRUM_STORE\:\-'$FULCRUM_STORE'\}|" $EXCHANGE_SETTINGS || \
sed -i -e "s|set +e|export FULCRUM_UPLOAD=\$\{FULCRUM_UPLOAD\:\-'$FULCRUM_STORE'\}\nset +e|" $EXCHANGE_SETTINGS
grep 'DJANGO_SETTINGS_MODULE' $EXCHANGE_SETTINGS && \
sed -i -e "s|export DJANGO_SETTINGS_MODULE=.*$|export DJANGO_SETTINGS_MODULE=\$\{DJANGO_SETTINGS_MODULE\:\-'bex.settings'\}|" $EXCHANGE_SETTINGS || \
sed -i -e "s|set +e|export DJANGO_SETTINGS_MODULE=\$\{DJANGO_SETTINGS_MODULE\:\-'bex.settings'\}\nset +e|" $EXCHANGE_SETTINGS
$PIP uninstall -y django_fulcrum && \
echo 'Previous version of the application has been uninstalled.' || \
echo 'The application has not been installed previously, starting new install.'
$PIP install -e ./
mkdir -p $FULCRUM_STORE
chown exchange:geoservice $FULCRUM_STORE
chmod 775 $FULCRUM_STORE
# change permissions to file_service folder so that django_fulcrum can add data to the folder.
mkdir -p $FILE_SERVICE_STORE
chown exchange:geoservice $FILE_SERVICE_STORE
chmod 775 $FILE_SERVICE_STORE
#add to ${EXCHANGE_URLS}:
grep -qF 'from django_fulcrum.urls import urlpatterns as django_fulcrum_urls' $EXCHANGE_URLS ||
printf "\nfrom django_fulcrum.urls import urlpatterns as django_fulcrum_urls\nurlpatterns += django_fulcrum_urls\n" >> $EXCHANGE_URLS
#add to ${EXCHANGE_CELERY_APP}:
grep -qF 'from django.conf import settings' $EXCHANGE_CELERY_APP || echo "from django.conf import settings" >> $EXCHANGE_CELERY_APP
grep -qF 'app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)' ${EXCHANGE_CELERY_APP} || echo "app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)" >> ${EXCHANGE_CELERY_APP}
#add django_fulrum to bex.settings
grep -qF 'from django_fulcrum.settings import *' ${BEX_SETTINGS} ||
printf "\nfrom django_fulcrum.settings import *" >> ${BEX_SETTINGS}
if [ ! -f $CELERY_BEAT_SCRIPT ]; then
cat << END > $CELERY_BEAT_SCRIPT
#!/bin/bash
source /etc/profile.d/exchange-settings.sh
source /etc/profile.d/vendor-libs.sh
cd ${EXCHANGE_DIR}
source .venv/bin/activate
${EXCHANGE_DIR}/.venv/bin/celery beat --app=exchange.celery_app --uid=exchange --loglevel=info --workdir=${EXCHANGE_DIR}
END
chown exchange:geoservice $CELERY_BEAT_SCRIPT
chmod 775 $CELERY_BEAT_SCRIPT
fi
source $EXCHANGE_SETTINGS
export EXCHANGE_DIR=$EXCHANGE_DIR
# add to /etc/supervisord.conf and fix duplicate layer bug in geonode
cd $EXCHANGE_DIR
$PYTHON - << END
import ConfigParser
import os
import django
import os
from string import Template
os.environ['DJANGO_SETTINGS_MODULE'] = 'bex.settings'
django.setup()
from django.db import connection
from django.db.utils import ProgrammingError, IntegrityError
EXCHANGE_DIR = os.getenv('EXCHANGE_DIR')
# Add celerybeat to supervisor.d
config_file = '/etc/supervisord.conf'
config = ConfigParser.SafeConfigParser()
config.read(config_file)
program = 'celery-beat'
program_configuration = {"command": os.path.join(EXCHANGE_DIR, "celery-beat.sh"),
"stdout_logfile": "/var/log/celery/celery-beat-stdout.log",
"stderr_logfile": "/var/log/celery/celery-beat-stderr.log",
"autostart": "true",
"autorestart": "true",
"startsecs": "10",
"stopwaitsecs": "600"}
if program not in config.get('group:exchange', 'programs'):
config.set('group:exchange', 'programs', '{0},{1}'.format(config.get('group:exchange', 'programs'), program))
program_section = 'program:{0}'.format(program)
if not config.has_section(program_section):
config.add_section(program_section)
for key,value in program_configuration.iteritems():
config.set(program_section, key, value)
with open(config_file, 'wb') as configfile:
config.write(configfile)
print("Added celerybeat to config")
# Add constraint to tables
geonode_layers_table = 'layers_layer'
command_template = Template("ALTER TABLE \$table_name ADD CONSTRAINT store_name_key UNIQUE (store, name);")
with connection.cursor() as cursor:
try:
command = command_template.safe_substitute({'table_name': geonode_layers_table})
cursor.execute(command)
print("Added unique constaint to layers_layer for store and name.")
except (ProgrammingError, IntegrityError) as error:
print("Database unique constaint was already added to layers_layer for store and name.")
print(error)
from geonode.base.models import TopicCategory
topic = TopicCategory.objects.get_or_create(gn_description='Fulcrum',
description='Data loaded features pictures, videos, and audio.',
is_choice=True,
fa_class='fa-user-circle-o',
identifier='fulcrum')
print("Added Fulcrum Category")
END
# select * from information_schema.table_constraints where table_name='layers_layer';
cd -
$PYTHON $MANAGE collectstatic --noinput
$PYTHON $MANAGE loaddata django_fulcrum/fixtures/topic.json
$PYTHON $MANAGE migrate
service exchange restart
set +e