forked from open-city/councilmatic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
postinstall
executable file
·161 lines (141 loc) · 4.34 KB
/
postinstall
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
#!/bin/bash
# A post-install hook script for the dotcould infrastructure. This hook should
# do a few things:
#
# * Load the history of legislative files from ScraperWiki
# * Load the history of meetings and agendas from ScraperWiki
# * Build the search indexes
# * Set up daily cron jobs
echo 'Injecting the appropriate settings into local_settings.py'
cat >> councilmatic/local_settings.py <<EOF
import json
with open("/home/dotcloud/environment.json") as env_json:
env = json.load(env_json)
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'councilmatic',
'USER': env['DOTCLOUD_DB_SQL_LOGIN'],
'PASSWORD': env['DOTCLOUD_DB_SQL_PASSWORD'],
'HOST': env['DOTCLOUD_DB_SQL_HOST'],
'PORT': env['DOTCLOUD_DB_SQL_PORT'],
}
}
DEBUG = (env.get('DEBUG', 'False') in ('True', 'true'))
COMPRESS_ENABLED = True
TEMPLATE_DEBUG = DEBUG
STATIC_ROOT = '/home/dotcloud/static/'
###############################################################################
#
# Source Data
#
LEGISLATION = {
'SYSTEM': 'Daystar Insite',
'ROOT': env['COUNCILMATIC_SOURCE_ROOT'],
'STARTING_KEY': 0,
'ADDRESS_BOUNDS': [float(c) for c in env['COUNCILMATIC_ADDRESS_BOUNDS'].split(',')],
'ADDRESS_SUFFIX': env['COUNCILMATIC_ADDRESS_SUFFIX']
}
###############################################################################
#
# Site search configuration
#
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': env['DOTCLOUD_SEARCH_HTTP_URL'],
}
}
################################################################################
#
# Testing and administration
#
DEFAULT_FROM_EMAIL = env.get('DEFAULT_FROM_EMAIL')
EMAIL_HOST = env.get('EMAIL_HOST')
EMAIL_PORT = env.get('EMAIL_PORT')
EMAIL_HOST_USER = env.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = env.get('EMAIL_HOST_PASSWORD')
if isinstance(EMAIL_PORT, basestring):
EMAIL_PORT = int(EMAIL_PORT)
if isinstance(EMAIL_HOST_PASSWORD, unicode):
EMAIL_HOST_PASSWORD = str(EMAIL_HOST_PASSWORD)
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'log_file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': '/var/log/supervisor/councilmatic.log',
'maxBytes': 1024*1024*25, # 25 MB
'backupCount': 5,
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django': {
'handlers': ['console', 'log_file', 'mail_admins'],
'level': 'INFO',
'propagate': True,
},
'django.request': {
'handlers': ['console', 'log_file', 'mail_admins'],
'level': 'ERROR',
'propagate': False,
},
'django.db.backends': {
'handlers': ['console', 'log_file', 'mail_admins'],
'level': 'INFO',
'propagate': False,
},
# Catch All Logger -- Captures any other logging
'': {
'handlers': ['console', 'log_file', 'mail_admins'],
'level': 'INFO',
'propagate': True,
}
}
}
EOF
echo 'Setting up nginx to serve static files'
cat >> nginx.conf <<EOF
location /static/ { root /home/dotcloud ; }
EOF
echo 'Doing the management commands'
cd councilmatic
python manage.py syncdb --noinput
python manage.py migrate --noinput
python manage.py collectstatic --noinput
echo 'Getting ready for the search index'
mkdir ~/whoosh_index
#python manage.py rebuild_index --noinput & disown # run this in the bg
echo 'Getting ready for logs'
mkdir ~/logs
echo 'Scheduling the cron jobs'
cd ../
crontab - <<EOF
MAILTO=""
0 5 * * * "/home/dotcloud/current/crons/daily_jobs"
EOF