SetupTasks » History » Version 35

Chris Cannam, 2010-12-14 02:53 PM

1 1 Chris Cannam
h1. Setup on new server tasks
2 1 Chris Cannam
3 2 Chris Cannam
# -Install Apache, Postgres, Varnish, etc-
4 2 Chris Cannam
# -Install "Ruby EE":http://www.rubyenterpriseedition.com/ and "Phusion Passenger":http://modrails.org/-
5 2 Chris Cannam
# -Install (via gem) rake, rails version 2.3.5, pg, rmagick, ruby-openid-
6 2 Chris Cannam
# -Clone current soundsoftware code-
7 2 Chris Cannam
# -Set up postgresql user and initialise database-
8 2 Chris Cannam
# -Redmine initialisation-
9 2 Chris Cannam
# -Redmine permissions and ownership-
10 2 Chris Cannam
# -Basic Apache config for site on :81-
11 2 Chris Cannam
# -Varnish config for :80->:81-
12 4 Chris Cannam
# -PHP5 via fcgi-
13 4 Chris Cannam
# -Basic Drupal install-
14 35 Chris Cannam
# -Initial database load for Redmine-
15 35 Chris Cannam
# -Initial database load for Drupal-
16 35 Chris Cannam
# -Pull across initial hg repos-
17 35 Chris Cannam
# -Configure SSL server-
18 35 Chris Cannam
# -Pull across remaining bits of redmine server that are not in hg (fonts, files, etc)-
19 35 Chris Cannam
# Install -hgwebdir-, -reposman-, -soundsoftware Apache auth- (depend on SSL, db, web service key in db etc)
20 35 Chris Cannam
# -Configure- and test the above (cannot test auth until LDAP is working)
21 35 Chris Cannam
# -Cron jobs-
22 35 Chris Cannam
# -Pull across Drupal theme etc-
23 35 Chris Cannam
# -Make sure we can connect to LDAP!-
24 35 Chris Cannam
# Backup regime
25 35 Chris Cannam
# -Ensure machine can be routed to!-
26 1 Chris Cannam
27 1 Chris Cannam
in the future: put old host in admin mode, re-point dns, final hg / database / redmine files update
28 1 Chris Cannam
29 35 Chris Cannam
further in the future: transplant across test servers, Survey service
30 35 Chris Cannam
31 35 Chris Cannam
even further in the future: switch off kakapo's https service, remove old sites from there
32 35 Chris Cannam
33 35 Chris Cannam
h2. Passenger compatibility
34 35 Chris Cannam
35 35 Chris Cannam
The site doesn't work properly with Passenger 3 -- every page is rendered without stylesheet, and the logs fill up with 
36 35 Chris Cannam
37 35 Chris Cannam
<pre>
38 35 Chris Cannam
ActionController::RoutingError (No route matches "/dispatch.cgi" with {:method=>:get}):
39 35 Chris Cannam
  passenger (3.0.0) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
40 35 Chris Cannam
  passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
41 35 Chris Cannam
...
42 35 Chris Cannam
</pre>
43 35 Chris Cannam
44 35 Chris Cannam
(what's it doing in rack/ anyway? This isn't a Rack app)
45 35 Chris Cannam
46 35 Chris Cannam
Reverting to Passenger 2.2 fixes it.  Just noting this here as a reminder to report / investigate...
47 35 Chris Cannam
48 35 Chris Cannam
h2. After import
49 35 Chris Cannam
50 35 Chris Cannam
We have to clear the repositories cache (if we have imported these tables).
51 35 Chris Cannam
52 35 Chris Cannam
<pre>
53 35 Chris Cannam
delete from changesets;
54 35 Chris Cannam
delete from changes;
55 35 Chris Cannam
</pre>
56 35 Chris Cannam
57 35 Chris Cannam
(Do we have to rebuild indexes?  With MySQL it was necessary to run @optimize table@ on these afterwards, followed by @flush tables@.  Probably no harm in at least running @REINDEX TABLE@ on each table)
58 35 Chris Cannam
59 6 Chris Cannam
h2. MySQL to Postgres migration notes
60 6 Chris Cannam
61 9 Chris Cannam
Just to make things more fun, we're migrating the existing databases from MySQL to pgsql.
62 6 Chris Cannam
63 9 Chris Cannam
For Redmine, we don't attempt to dump and reload the schema -- more sensible to use Redmine to set up the schema (in case it has any database-specific set up) and then massage the data as we load it.  We just dump and reload the row data.  That way we only have to fix problems once.
64 6 Chris Cannam
65 7 Chris Cannam
"mysql2pgsql":http://pgfoundry.org/projects/mysql2pgsql/ does a reasonable job of converting the data, as far as it goes.  Some problems remain:
66 6 Chris Cannam
67 6 Chris Cannam
<pre>$ grep ERROR log/dbload.log |sort|uniq
68 6 Chris Cannam
ERROR:  column "admin" is of type boolean but expression is of type integer
69 6 Chris Cannam
ERROR:  column "assignable" is of type boolean but expression is of type integer
70 6 Chris Cannam
ERROR:  column "hide_mail" is of type boolean but expression is of type integer
71 6 Chris Cannam
ERROR:  column "is_closed" is of type boolean but expression is of type integer
72 6 Chris Cannam
ERROR:  column "is_default" is of type boolean but expression is of type integer
73 6 Chris Cannam
ERROR:  column "is_in_chlog" is of type boolean but expression is of type integer
74 6 Chris Cannam
ERROR:  column "is_public" is of type boolean but expression is of type integer
75 1 Chris Cannam
ERROR:  column "mail_notification" is of type boolean but expression is of type integer
76 1 Chris Cannam
ERROR:  column "onthefly_register" is of type boolean but expression is of type integer
77 6 Chris Cannam
ERROR:  column "protected" is of type boolean but expression is of type integer
78 6 Chris Cannam
ERROR:  duplicate key value violates unique constraint "unique_schema_migrations"
79 1 Chris Cannam
ERROR:  INSERT has more expressions than target columns
80 1 Chris Cannam
ERROR:  invalid input syntax for type bytea
81 1 Chris Cannam
$
82 1 Chris Cannam
</pre>
83 1 Chris Cannam
84 35 Chris Cannam
The boolean ones are understandable -- mysqldump writes them out as ones and zeros and you can't tell they were intended to be boolean without the schema.  We can fix them readily enough in a script once we identify which table they come from.
85 1 Chris Cannam
86 35 Chris Cannam
The duplicate key values we don't care about -- in fact we're glad they're rejected, because they come from the Redmine db:migrate which we've already run anyway.
87 1 Chris Cannam
88 1 Chris Cannam
"INSERT has more expressions"... that's a strange one.  Is our schema out of date?
89 35 Chris Cannam
90 35 Chris Cannam
This is from the repositories table.  Columns:
91 35 Chris Cannam
92 35 Chris Cannam
<pre>
93 35 Chris Cannam
 id | project_id | url | login | password | root_url | type 
94 35 Chris Cannam
</pre>
95 35 Chris Cannam
96 35 Chris Cannam
Values being inserted (example):
97 35 Chris Cannam
98 35 Chris Cannam
<pre>
99 35 Chris Cannam
INSERT INTO "repositories" VALUES (1,2,E'/var/hg/svcore',E'',E'',E'/var/hg/svcore',E'Mercurial',E'--- {}\n\n');
100 35 Chris Cannam
</pre>
101 35 Chris Cannam
102 35 Chris Cannam
So we are indeed missing something -- the @checkout_settings@ column.  We forgot to run the plugins migration (@rake db:migrate:plugins@).
103 35 Chris Cannam
104 35 Chris Cannam
Fixing that, we have a new one instead:
105 35 Chris Cannam
106 35 Chris Cannam
<pre>
107 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "settings_pkey"
108 35 Chris Cannam
</pre>
109 35 Chris Cannam
110 35 Chris Cannam
The problem is that the blimmin' redmine-checkout plugin has inserted its own settings row, which appears only later in the imported dump.  We need to @delete from settings@ before we can load.
111 35 Chris Cannam
112 35 Chris Cannam
Later,
113 35 Chris Cannam
114 35 Chris Cannam
<pre>
115 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "roles_pkey"
116 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "users_pkey"
117 35 Chris Cannam
</pre>
118 35 Chris Cannam
119 35 Chris Cannam
The roles one doesn't really matter (we're inserting the same stuff anyway) but the users one does, as it has all of admin's details.  So we have to do this after the migrate steps but before the data load:
120 35 Chris Cannam
121 35 Chris Cannam
<pre>
122 35 Chris Cannam
delete from settings
123 35 Chris Cannam
delete from roles
124 35 Chris Cannam
delete from users
125 35 Chris Cannam
</pre>
126 35 Chris Cannam
127 35 Chris Cannam
h2. Problematic Boolean columns
128 35 Chris Cannam
129 35 Chris Cannam
We'll just script a quick hack to convert these based on counting the commas for column numbers.  Hence we need to know which table each belongs to, which column it is (counting from the left), and whether any of the fields to the left can contain commas themselves.
130 35 Chris Cannam
131 35 Chris Cannam
* @admin@: table @users@ col 8 (counting from 1); no
132 35 Chris Cannam
* @assignable@: table @roles@ col 4; no
133 35 Chris Cannam
* @hide_mail@: table @user_preferences@ col 4; no
134 35 Chris Cannam
* @is_closed@: table @issue_statuses@ col 3; no
135 35 Chris Cannam
* @is_default@: table @issue_statuses@ col 4; table @enumerations@ col 4; both no
136 35 Chris Cannam
* @is_in_chlog@: table @trackers@ col 3; no
137 35 Chris Cannam
* @is_in_roadmap@: table @trackers@ col 5; no
138 35 Chris Cannam
* @is_public@: table @projects@ col 5; yes. This is likely to be first occurrence of @,1,@ or @,0,@ however
139 35 Chris Cannam
* @mail_notification@: table @members@ col 5; no (there is also a column of this name in @users@ but it is not boolean)
140 35 Chris Cannam
* @onthefly_register@: table @auth_sources@ col 13; yes. This is likely to be first occurrence of @,1,@ or @,0,@ however and we only have one row in @auth_sources@ at the moment anyway
141 35 Chris Cannam
* @tls@: table @auth_sources@ col 14; yes. Last column, so look for @,0)@ or @,1)@ I guess.  Yummy
142 35 Chris Cannam
* @protected@: table @wiki_pages@ col 5; no
143 35 Chris Cannam
144 35 Chris Cannam
h2. Errors from Drupal database import
145 35 Chris Cannam
146 35 Chris Cannam
All of the foregoing is to do with the Redmine database.  Here's what we get for Drupal.
147 35 Chris Cannam
148 35 Chris Cannam
Our first load failed because of something to do with the @cache@ table -- but we don't want to load the cache anyway (do we?).  After eliminating the cache from the dump and trying again,
149 35 Chris Cannam
150 35 Chris Cannam
<pre>ERROR:  duplicate key value violates unique constraint "actions_pkey"
151 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "authmap_pkey"
152 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "blocks_pkey"
153 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "blocks_roles_pkey"
154 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "boxes_pkey"
155 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "cache_menu_pkey"
156 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "filter_formats_pkey"
157 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "filters_pkey"
158 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "menu_custom_pkey"
159 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "menu_links_pkey"
160 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "menu_router_pkey"
161 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "node_access_pkey"
162 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "node_type_pkey"
163 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "role_pkey"
164 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "sessions_pkey"
165 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "system_pkey"
166 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "users_pkey"
167 35 Chris Cannam
ERROR:  duplicate key value violates unique constraint "variable_pkey"
168 35 Chris Cannam
ERROR:  relation "cache_views" does not exist
169 35 Chris Cannam
ERROR:  relation "image_attach" does not exist
170 35 Chris Cannam
ERROR:  relation "image" does not exist
171 35 Chris Cannam
ERROR:  relation "upload" does not exist
172 35 Chris Cannam
ERROR:  relation "views_display" does not exist
173 35 Chris Cannam
ERROR:  relation "views_view" does not exist
174 35 Chris Cannam
</pre>
175 35 Chris Cannam
176 35 Chris Cannam
The first few were probably caused by the previous partial load with cache (I didn't clear out in between).
177 35 Chris Cannam
178 35 Chris Cannam
The rest by missing modules?