Projet

Général

Profil

Chiliproject » Historique » Version 26

Mehdi Abaakouk, 16/12/2014 10:39

1 8 Mehdi Abaakouk
{{>toc}}
2 9 Mehdi Abaakouk
3 26 Mehdi Abaakouk
!!! OBSOLETE: Voir: [[Redmine]]
4 26 Mehdi Abaakouk
5 1 Mehdi Abaakouk
h1. Chiliproject
6 1 Mehdi Abaakouk
7 1 Mehdi Abaakouk
La machine chiliproject contient:
8 1 Mehdi Abaakouk
9 5 Mehdi Abaakouk
 - une base données postgres
10 5 Mehdi Abaakouk
 - une application installé dans /srv/http/chiliproject-X.X.X
11 5 Mehdi Abaakouk
 - le git de git.tetaneutral.net dans /srv/http/repositories
12 1 Mehdi Abaakouk
13 1 Mehdi Abaakouk
h2. L'application:
14 1 Mehdi Abaakouk
15 5 Mehdi Abaakouk
Le vhost d'apache est /etc/apache2/sites-enabled/chiliproject.tetaneutral.net, il pointe vers le répertoire /srv/http/chiliproject qui est un lien symbolique vers /srv/http/chiliproject-X.X.X
16 1 Mehdi Abaakouk
17 5 Mehdi Abaakouk
La procédure de mise à jour est la suivante:
18 1 Mehdi Abaakouk
<pre>
19 1 Mehdi Abaakouk
/etc/init.d/apache2 stop
20 5 Mehdi Abaakouk
# su - postgres
21 1 Mehdi Abaakouk
# pgdump chiliproject > chiliproject-3.X.X-20130108.sql
22 1 Mehdi Abaakouk
# exit
23 5 Mehdi Abaakouk
# cd /srv/http/chiliproject
24 4 Mehdi Abaakouk
# git fetch origin
25 5 Mehdi Abaakouk
# git branch ttnn-prod-3.6.0     # Création d'un nouvelle branche qui contient les modifications ttnn
26 4 Mehdi Abaakouk
# git checkout ttnn-prod-3.6.0   # Utilisation de cette branche
27 5 Mehdi Abaakouk
# git rebase v3.6.0              # rebase la branche ttnn avec la dernière version de chiliproject
28 1 Mehdi Abaakouk
</pre>
29 1 Mehdi Abaakouk
30 5 Mehdi Abaakouk
Et continuer les étapes 4 à 10 du howto de chiliproject (cf: https://www.chiliproject.org/projects/chiliproject/wiki/Upgrade#Step-4-Library-installation)
31 3 Mehdi Abaakouk
Version rapide:
32 3 Mehdi Abaakouk
<pre>
33 4 Mehdi Abaakouk
bundle update
34 4 Mehdi Abaakouk
gem cleanup
35 4 Mehdi Abaakouk
bundle update
36 2 Mehdi Abaakouk
bundle exec rake generate_session_store
37 1 Mehdi Abaakouk
bundle exec rake db:migrate RAILS_ENV=production
38 1 Mehdi Abaakouk
bundle exec rake db:migrate:plugins RAILS_ENV=production
39 3 Mehdi Abaakouk
bundle exec rake tmp:cache:clear
40 3 Mehdi Abaakouk
bundle exec rake tmp:sessions:clear
41 3 Mehdi Abaakouk
</pre>
42 3 Mehdi Abaakouk
43 3 Mehdi Abaakouk
44 3 Mehdi Abaakouk
Restart de chili
45 3 Mehdi Abaakouk
<pre>
46 3 Mehdi Abaakouk
/etc/init.d/apache2 start
47 1 Mehdi Abaakouk
</pre>
48 1 Mehdi Abaakouk
49 1 Mehdi Abaakouk
h2. La DB du postgres normal:
50 1 Mehdi Abaakouk
51 1 Mehdi Abaakouk
<pre>
52 5 Mehdi Abaakouk
# su - postgres
53 1 Mehdi Abaakouk
# psql chiliproject
54 1 Mehdi Abaakouk
chiliproject=# \dt
55 1 Mehdi Abaakouk
 public | attachments                         | table | chiliproject
56 1 Mehdi Abaakouk
 public | auth_sources                        | table | chiliproject
57 1 Mehdi Abaakouk
 public | boards                              | table | chiliproject
58 1 Mehdi Abaakouk
 public | changes                             | table | chiliproject
59 1 Mehdi Abaakouk
 public | changesets                          | table | chiliproject
60 1 Mehdi Abaakouk
 public | changesets_issues                   | table | chiliproject
61 1 Mehdi Abaakouk
 public | comments                            | table | chiliproject
62 1 Mehdi Abaakouk
 public | custom_fields                       | table | chiliproject
63 1 Mehdi Abaakouk
 public | custom_fields_projects              | table | chiliproject
64 1 Mehdi Abaakouk
 public | custom_fields_trackers              | table | chiliproject
65 1 Mehdi Abaakouk
 public | custom_values                       | table | chiliproject
66 1 Mehdi Abaakouk
 public | documents                           | table | chiliproject
67 1 Mehdi Abaakouk
 public | enabled_modules                     | table | chiliproject
68 1 Mehdi Abaakouk
 public | enumerations                        | table | chiliproject
69 1 Mehdi Abaakouk
 public | groups_users                        | table | chiliproject
70 1 Mehdi Abaakouk
 public | issue_categories                    | table | chiliproject
71 1 Mehdi Abaakouk
 public | issue_relations                     | table | chiliproject
72 1 Mehdi Abaakouk
 public | issue_statuses                      | table | chiliproject
73 1 Mehdi Abaakouk
 public | issues                              | table | chiliproject
74 1 Mehdi Abaakouk
 public | journal_details                     | table | chiliproject
75 1 Mehdi Abaakouk
 public | journals                            | table | chiliproject
76 1 Mehdi Abaakouk
 public | member_roles                        | table | chiliproject
77 1 Mehdi Abaakouk
 public | members                             | table | chiliproject
78 1 Mehdi Abaakouk
 public | messages                            | table | chiliproject
79 1 Mehdi Abaakouk
 public | news                                | table | chiliproject
80 1 Mehdi Abaakouk
 public | open_id_authentication_associations | table | chiliproject
81 1 Mehdi Abaakouk
 public | open_id_authentication_nonces       | table | chiliproject
82 1 Mehdi Abaakouk
 public | projects                            | table | chiliproject
83 1 Mehdi Abaakouk
 public | projects_trackers                   | table | chiliproject
84 1 Mehdi Abaakouk
 public | queries                             | table | chiliproject
85 1 Mehdi Abaakouk
 public | repositories                        | table | chiliproject
86 1 Mehdi Abaakouk
 public | roles                               | table | chiliproject
87 1 Mehdi Abaakouk
 public | schema_migrations                   | table | chiliproject
88 1 Mehdi Abaakouk
 public | settings                            | table | chiliproject
89 1 Mehdi Abaakouk
 public | taggings                            | table | chiliproject
90 1 Mehdi Abaakouk
 public | tags                                | table | chiliproject
91 1 Mehdi Abaakouk
 public | time_entries                        | table | chiliproject
92 1 Mehdi Abaakouk
 public | tokens                              | table | chiliproject
93 1 Mehdi Abaakouk
 public | trackers                            | table | chiliproject
94 1 Mehdi Abaakouk
 public | user_preferences                    | table | chiliproject
95 1 Mehdi Abaakouk
 public | users                               | table | chiliproject
96 1 Mehdi Abaakouk
 public | versions                            | table | chiliproject
97 1 Mehdi Abaakouk
 public | watchers                            | table | chiliproject
98 1 Mehdi Abaakouk
 public | wiki_content_versions               | table | chiliproject
99 1 Mehdi Abaakouk
 public | wiki_contents                       | table | chiliproject
100 1 Mehdi Abaakouk
 public | wiki_pages                          | table | chiliproject
101 1 Mehdi Abaakouk
 public | wiki_redirects                      | table | chiliproject
102 1 Mehdi Abaakouk
 public | wikis                               | table | chiliproject
103 1 Mehdi Abaakouk
 public | workflows                           | table | chiliproject
104 1 Mehdi Abaakouk
</pre>
105 6 Mehdi Abaakouk
106 22 Mehdi Abaakouk
h2. Howto/Script Migration chiliproject to redmine
107 6 Mehdi Abaakouk
108 6 Mehdi Abaakouk
<pre>
109 6 Mehdi Abaakouk
# -*- coding: utf-8 -*-
110 6 Mehdi Abaakouk
# vim: ts=4: set ft=sh
111 6 Mehdi Abaakouk
#
112 6 Mehdi Abaakouk
# CC-BY Mehdi Abaakouk <sileht@sileht.net>
113 6 Mehdi Abaakouk
# Inpired from this ruby/mysql version: https://gist.github.com/pallan/6663018
114 6 Mehdi Abaakouk
#
115 6 Mehdi Abaakouk
116 6 Mehdi Abaakouk
# On postgres User
117 6 Mehdi Abaakouk
118 6 Mehdi Abaakouk
$ createuser -P redmine
119 6 Mehdi Abaakouk
$ createdb redmine  -O redmine 
120 6 Mehdi Abaakouk
$ pg_dump chiliproject > toredmine.sql
121 6 Mehdi Abaakouk
$ psql redmine < toredmine.sql
122 6 Mehdi Abaakouk
123 6 Mehdi Abaakouk
$ psql redmine <<EOF
124 6 Mehdi Abaakouk
ALTER DATABASE redmine OWNER TO redmine;
125 6 Mehdi Abaakouk
REASSIGN OWNED BY chiliproject TO redmine;
126 6 Mehdi Abaakouk
127 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN created_at TO created_on;
128 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN journaled_id TO journalized_id;
129 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN activity_type TO journalized_type;
130 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type TYPE character varying(30);
131 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type SET NOT NULL;
132 6 Mehdi Abaakouk
ALTER TABLE journals ALTER COLUMN journalized_type SET DEFAULT ''::character varying ;
133 6 Mehdi Abaakouk
EOF
134 6 Mehdi Abaakouk
135 6 Mehdi Abaakouk
136 6 Mehdi Abaakouk
# On root:
137 6 Mehdi Abaakouk
138 6 Mehdi Abaakouk
$ cd /srv/http
139 6 Mehdi Abaakouk
$ tsocks git clone https://github.com/redmine/redmine.git -b 2.5-stable
140 6 Mehdi Abaakouk
$ cd redmine
141 6 Mehdi Abaakouk
142 6 Mehdi Abaakouk
$ cat > config/database.yml <<EOF
143 6 Mehdi Abaakouk
production:
144 6 Mehdi Abaakouk
    adapter: postgresql
145 6 Mehdi Abaakouk
    database: redmine
146 6 Mehdi Abaakouk
    host: localhost
147 6 Mehdi Abaakouk
    username: redmine
148 6 Mehdi Abaakouk
    password: redmine
149 6 Mehdi Abaakouk
EOF
150 6 Mehdi Abaakouk
151 6 Mehdi Abaakouk
$ tsocks bundle install --without development test rmagick
152 7 Mehdi Abaakouk
$ bundle exec rake generate_secret_token
153 6 Mehdi Abaakouk
$ RAILS_ENV=production bundle exec rake db:migrate
154 6 Mehdi Abaakouk
155 6 Mehdi Abaakouk
156 6 Mehdi Abaakouk
# On postgres user:
157 6 Mehdi Abaakouk
158 6 Mehdi Abaakouk
$ psql redmine <<EOF
159 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ADD comments VARCHAR(250) NULL;
160 6 Mehdi Abaakouk
ALTER TABLE wiki_contents RENAME COLUMN lock_version TO version;
161 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ALTER COLUMN version TYPE INTEGER;
162 6 Mehdi Abaakouk
ALTER TABLE wiki_contents ALTER COLUMN version SET NOT NULL;
163 6 Mehdi Abaakouk
164 7 Mehdi Abaakouk
UPDATE journals SET journalized_type='Issue' WHERE journalized_type='issues';
165 6 Mehdi Abaakouk
166 6 Mehdi Abaakouk
ALTER TABLE journals RENAME COLUMN changes TO changes_chili;
167 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN type;
168 6 Mehdi Abaakouk
EOF
169 6 Mehdi Abaakouk
170 6 Mehdi Abaakouk
171 6 Mehdi Abaakouk
$ python <<EOF
172 6 Mehdi Abaakouk
import yaml;
173 6 Mehdi Abaakouk
import psycopg2
174 6 Mehdi Abaakouk
conn = psycopg2.connect("dbname='redmine' user='redmine' host='localhost' password='redmine'")
175 7 Mehdi Abaakouk
commit = 100
176 1 Mehdi Abaakouk
cur = conn.cursor()
177 7 Mehdi Abaakouk
cur.execute("""SELECT id, version, journalized_type, journalized_id, changes_chili,created_on, notes, user_id FROM journals order by version desc""")
178 1 Mehdi Abaakouk
rows = cur.fetchall()
179 7 Mehdi Abaakouk
cur.close()
180 7 Mehdi Abaakouk
dataissue = []
181 7 Mehdi Abaakouk
datawiki = []
182 1 Mehdi Abaakouk
for row in rows:
183 7 Mehdi Abaakouk
    id = row[0]
184 7 Mehdi Abaakouk
    version = int(row[1])
185 7 Mehdi Abaakouk
    type = row[2]
186 7 Mehdi Abaakouk
    jid = row[3]
187 7 Mehdi Abaakouk
    raw_changes = row[4]
188 7 Mehdi Abaakouk
    created_on = row[5]
189 7 Mehdi Abaakouk
    notes = row[6]
190 7 Mehdi Abaakouk
    user_id = row[7]
191 7 Mehdi Abaakouk
    if type in ["time_entries", "documents"]: # only have 1 item each
192 7 Mehdi Abaakouk
        continue
193 7 Mehdi Abaakouk
    elif type == "attachments": # 163
194 7 Mehdi Abaakouk
        continue
195 7 Mehdi Abaakouk
    elif type == "messages": # 3
196 7 Mehdi Abaakouk
        continue
197 7 Mehdi Abaakouk
    elif type == ["Issue", "attachments"] and version > 1:
198 7 Mehdi Abaakouk
        changes = yaml.load(raw_changes)
199 7 Mehdi Abaakouk
        for k, v in changes.iteritems():
200 7 Mehdi Abaakouk
            if k == "attachment":
201 7 Mehdi Abaakouk
                property = 'attachment'
202 7 Mehdi Abaakouk
                prop_key = re.sub("\d+", "", k)
203 7 Mehdi Abaakouk
            elif k == "custom_values":
204 7 Mehdi Abaakouk
                property = 'cf'
205 7 Mehdi Abaakouk
                prop_key = re.sub("\d+", "", k)
206 7 Mehdi Abaakouk
            else:
207 7 Mehdi Abaakouk
                property = 'attr'
208 7 Mehdi Abaakouk
                prop_key = k
209 7 Mehdi Abaakouk
            dataissue.append({'id': id,
210 7 Mehdi Abaakouk
                         'property': property,
211 7 Mehdi Abaakouk
                         'prop_key': prop_key,
212 7 Mehdi Abaakouk
                         'old_value': v[0],
213 7 Mehdi Abaakouk
                         'new_value': v[1],
214 7 Mehdi Abaakouk
                        })
215 7 Mehdi Abaakouk
    elif type == "wiki_edits":
216 7 Mehdi Abaakouk
        changes = yaml.load(raw_changes)
217 7 Mehdi Abaakouk
        datawiki.append({
218 7 Mehdi Abaakouk
            'id': id,
219 7 Mehdi Abaakouk
            'wiki_content_id': jid,
220 7 Mehdi Abaakouk
            'page_id': jid,
221 7 Mehdi Abaakouk
            'author_id': user_id,
222 7 Mehdi Abaakouk
            'data': bytearray(changes.get('data'), encoding="utf-8"),
223 7 Mehdi Abaakouk
            'compression': changes.get('compression', None),
224 7 Mehdi Abaakouk
            'updated_on': created_on,
225 7 Mehdi Abaakouk
            'comments': notes,
226 7 Mehdi Abaakouk
            'version': version,
227 7 Mehdi Abaakouk
        })
228 7 Mehdi Abaakouk
    if len(dataissue) > commit:
229 7 Mehdi Abaakouk
        cur = conn.cursor()
230 7 Mehdi Abaakouk
        cur.executemany("""INSERT INTO journal_details (journal_id, property, prop_key, old_value, value) VALUES (%(id)s,%(property)s,%(prop_key)s,%(old_value)s,%(new_value)s)""", dataissue)
231 7 Mehdi Abaakouk
        cur.close()
232 7 Mehdi Abaakouk
        dataissue = []
233 7 Mehdi Abaakouk
    if len(datawiki) > commit:
234 7 Mehdi Abaakouk
        cur = conn.cursor()
235 7 Mehdi Abaakouk
        cur.executemany("""INSERT INTO wiki_content_versions (id, wiki_content_id, page_id, author_id, data, compression, comments, updated_on, version) VALUES (%(id)s, %(wiki_content_id)s, %(page_id)s, %(author_id)s, %(data)s, %(compression)s, %(comments)s, %(updated_on)s, %(version)s)""", datawiki)
236 7 Mehdi Abaakouk
        cur.close()
237 7 Mehdi Abaakouk
        datawiki = []
238 7 Mehdi Abaakouk
           
239 6 Mehdi Abaakouk
240 7 Mehdi Abaakouk
cur = conn.cursor()
241 7 Mehdi Abaakouk
cur.executemany("""INSERT INTO journal_details (journal_id, property, prop_key, old_value, value) VALUES (%(id)s,%(property)s,%(prop_key)s,%(old_value)s,%(new_value)s)""", dataissue)
242 6 Mehdi Abaakouk
cur.close()
243 7 Mehdi Abaakouk
cur = conn.cursor()
244 7 Mehdi Abaakouk
cur.executemany("""INSERT INTO wiki_content_versions (id, wiki_content_id, page_id, author_id, data, compression, comments, updated_on, version) VALUES (%(id)s, %(wiki_content_id)s, %(page_id)s, %(author_id)s, %(data)s, %(compression)s, %(comments)s, %(updated_on)s, %(version)s)""", datawiki)
245 7 Mehdi Abaakouk
cur.close()
246 7 Mehdi Abaakouk
conn.commit()
247 6 Mehdi Abaakouk
conn.close()
248 6 Mehdi Abaakouk
EOF
249 6 Mehdi Abaakouk
250 6 Mehdi Abaakouk
$ psql redmine <<EOF
251 6 Mehdi Abaakouk
DELETE FROM journals WHERE (notes IS NULL OR notes = '' ) AND changes_chili IS NOT NULL AND NOT EXISTS (SELECT 1 FROM journal_details x where x.journal_id=journals.id);
252 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN changes_chili;
253 6 Mehdi Abaakouk
ALTER TABLE journals DROP COLUMN version;
254 6 Mehdi Abaakouk
EOF
255 6 Mehdi Abaakouk
256 6 Mehdi Abaakouk
# On root in /srv/http/redmine:
257 6 Mehdi Abaakouk
258 6 Mehdi Abaakouk
$ RAILS_ENV=production REDMINE_LANG=fr bundle exec rake redmine:load_default_data
259 10 Mehdi Abaakouk
260 10 Mehdi Abaakouk
$ cat > mailhandler.sh <<EOF
261 10 Mehdi Abaakouk
#!/bin/bash
262 10 Mehdi Abaakouk
exec bundle exec ruby extra/mail_handler/rdm-mailhandler.rb --url http://chiliproject.tetaneutral.net/ --key lVYqSEk1kAUtwsXe3qzf --project tetaneutral.net"
263 10 Mehdi Abaakouk
EOF
264 10 Mehdi Abaakouk
265 10 Mehdi Abaakouk
$ chmod +x mailhandler.sh
266 10 Mehdi Abaakouk
267 10 Mehdi Abaakouk
268 10 Mehdi Abaakouk
# change in /etc/aliases the chiliproject alias to:
269 10 Mehdi Abaakouk
270 1 Mehdi Abaakouk
chiliproject: "|/srv/http/redmine/mailhandler.sh"
271 22 Mehdi Abaakouk
272 22 Mehdi Abaakouk
# Dans /etc/apache2/site-enabled/chiliproject changer les '/srv/http/chiliproject/public' en '/srv/http/redmine/public'
273 22 Mehdi Abaakouk
# Et ajouter en tout en haut du fichier 'PassengerDefaultUser www-data'
274 22 Mehdi Abaakouk
275 22 Mehdi Abaakouk
# Copie des fichiers uploadé:
276 22 Mehdi Abaakouk
277 22 Mehdi Abaakouk
$ cd /srv/http/redmine
278 22 Mehdi Abaakouk
$ rsync -a ../chiliproject/files/ files/
279 22 Mehdi Abaakouk
280 22 Mehdi Abaakouk
# Remise à plat des permissions:
281 22 Mehdi Abaakouk
282 23 Mehdi Abaakouk
$ chown -R www-data:www-data files log tmp public/plugin_assets
283 22 Mehdi Abaakouk
$ chmod 755 files log tmp public/plugin_assets
284 22 Mehdi Abaakouk
$ find files -type d -exec chmod 755 {} \;
285 22 Mehdi Abaakouk
$ find public/plugin_assets -type d -exec chmod 755 {} \;
286 22 Mehdi Abaakouk
$ find log -type d -exec chmod 755 {} \;
287 22 Mehdi Abaakouk
$ find tmp -type d -exec chmod 755 {} \;
288 22 Mehdi Abaakouk
$ find files -type f -exec chmod 644 {} \;
289 22 Mehdi Abaakouk
$ find public/plugin_assets -type f -exec chmod 644 {} \;
290 22 Mehdi Abaakouk
$ find log -type f -exec chmod 644 {} \;
291 22 Mehdi Abaakouk
$ find tmp -type f -exec chmod 644 {} \;
292 22 Mehdi Abaakouk
293 10 Mehdi Abaakouk
294 10 Mehdi Abaakouk
295 1 Mehdi Abaakouk
</pre>
296 11 Laurent GUERBY
297 11 Laurent GUERBY
h2. Problemes
298 11 Laurent GUERBY
299 11 Laurent GUERBY
Lors de la migration
300 11 Laurent GUERBY
301 25 Mehdi Abaakouk
# TODO ? 
302 25 Mehdi Abaakouk
# * TEST ENVOIE EMAIL
303 25 Mehdi Abaakouk
# * TEST MAIL TO: