Projet

Général

Profil

Chiliproject » Historique » Version 23

« Précédent - Version 23/26 (diff) - Suivant » - Version actuelle
Mehdi Abaakouk, 18/04/2014 15:04


Chiliproject

La machine chiliproject contient:

- une base données postgres
- une application installé dans /srv/http/chiliproject-X.X.X
- le git de git.tetaneutral.net dans /srv/http/repositories

L'application:

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

La procédure de mise à jour est la suivante:

/etc/init.d/apache2 stop
# su - postgres
# pgdump chiliproject > chiliproject-3.X.X-20130108.sql
# exit
# cd /srv/http/chiliproject
# git fetch origin
# git branch ttnn-prod-3.6.0     # Création d'un nouvelle branche qui contient les modifications ttnn
# git checkout ttnn-prod-3.6.0   # Utilisation de cette branche
# git rebase v3.6.0              # rebase la branche ttnn avec la dernière version de chiliproject

Et continuer les étapes 4 à 10 du howto de chiliproject (cf: https://www.chiliproject.org/projects/chiliproject/wiki/Upgrade#Step-4-Library-installation)
Version rapide:

bundle update
gem cleanup
bundle update
bundle exec rake generate_session_store
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake db:migrate:plugins RAILS_ENV=production
bundle exec rake tmp:cache:clear
bundle exec rake tmp:sessions:clear

Restart de chili

/etc/init.d/apache2 start

La DB du postgres normal:

# su - postgres
# psql chiliproject
chiliproject=# \dt
 public | attachments                         | table | chiliproject
 public | auth_sources                        | table | chiliproject
 public | boards                              | table | chiliproject
 public | changes                             | table | chiliproject
 public | changesets                          | table | chiliproject
 public | changesets_issues                   | table | chiliproject
 public | comments                            | table | chiliproject
 public | custom_fields                       | table | chiliproject
 public | custom_fields_projects              | table | chiliproject
 public | custom_fields_trackers              | table | chiliproject
 public | custom_values                       | table | chiliproject
 public | documents                           | table | chiliproject
 public | enabled_modules                     | table | chiliproject
 public | enumerations                        | table | chiliproject
 public | groups_users                        | table | chiliproject
 public | issue_categories                    | table | chiliproject
 public | issue_relations                     | table | chiliproject
 public | issue_statuses                      | table | chiliproject
 public | issues                              | table | chiliproject
 public | journal_details                     | table | chiliproject
 public | journals                            | table | chiliproject
 public | member_roles                        | table | chiliproject
 public | members                             | table | chiliproject
 public | messages                            | table | chiliproject
 public | news                                | table | chiliproject
 public | open_id_authentication_associations | table | chiliproject
 public | open_id_authentication_nonces       | table | chiliproject
 public | projects                            | table | chiliproject
 public | projects_trackers                   | table | chiliproject
 public | queries                             | table | chiliproject
 public | repositories                        | table | chiliproject
 public | roles                               | table | chiliproject
 public | schema_migrations                   | table | chiliproject
 public | settings                            | table | chiliproject
 public | taggings                            | table | chiliproject
 public | tags                                | table | chiliproject
 public | time_entries                        | table | chiliproject
 public | tokens                              | table | chiliproject
 public | trackers                            | table | chiliproject
 public | user_preferences                    | table | chiliproject
 public | users                               | table | chiliproject
 public | versions                            | table | chiliproject
 public | watchers                            | table | chiliproject
 public | wiki_content_versions               | table | chiliproject
 public | wiki_contents                       | table | chiliproject
 public | wiki_pages                          | table | chiliproject
 public | wiki_redirects                      | table | chiliproject
 public | wikis                               | table | chiliproject
 public | workflows                           | table | chiliproject

Howto/Script Migration chiliproject to redmine

# -*- coding: utf-8 -*-
# vim: ts=4: set ft=sh
#
# CC-BY Mehdi Abaakouk <sileht@sileht.net>
# Inpired from this ruby/mysql version: https://gist.github.com/pallan/6663018
#

# On postgres User

$ createuser -P redmine
$ createdb redmine  -O redmine 
$ pg_dump chiliproject > toredmine.sql
$ psql redmine < toredmine.sql

$ psql redmine <<EOF
ALTER DATABASE redmine OWNER TO redmine;
REASSIGN OWNED BY chiliproject TO redmine;

ALTER TABLE journals RENAME COLUMN created_at TO created_on;
ALTER TABLE journals RENAME COLUMN journaled_id TO journalized_id;
ALTER TABLE journals RENAME COLUMN activity_type TO journalized_type;
ALTER TABLE journals ALTER COLUMN journalized_type TYPE character varying(30);
ALTER TABLE journals ALTER COLUMN journalized_type SET NOT NULL;
ALTER TABLE journals ALTER COLUMN journalized_type SET DEFAULT ''::character varying ;
EOF

# On root:

$ cd /srv/http
$ tsocks git clone https://github.com/redmine/redmine.git -b 2.5-stable
$ cd redmine

$ cat > config/database.yml <<EOF
production:
    adapter: postgresql
    database: redmine
    host: localhost
    username: redmine
    password: redmine
EOF

$ tsocks bundle install --without development test rmagick
$ bundle exec rake generate_secret_token
$ RAILS_ENV=production bundle exec rake db:migrate

# On postgres user:

$ psql redmine <<EOF
ALTER TABLE wiki_contents ADD comments VARCHAR(250) NULL;
ALTER TABLE wiki_contents RENAME COLUMN lock_version TO version;
ALTER TABLE wiki_contents ALTER COLUMN version TYPE INTEGER;
ALTER TABLE wiki_contents ALTER COLUMN version SET NOT NULL;

UPDATE journals SET journalized_type='Issue' WHERE journalized_type='issues';

ALTER TABLE journals RENAME COLUMN changes TO changes_chili;
ALTER TABLE journals DROP COLUMN type;
EOF

$ python <<EOF
import yaml;
import psycopg2
conn = psycopg2.connect("dbname='redmine' user='redmine' host='localhost' password='redmine'")
commit = 100
cur = conn.cursor()
cur.execute("""SELECT id, version, journalized_type, journalized_id, changes_chili,created_on, notes, user_id FROM journals order by version desc""")
rows = cur.fetchall()
cur.close()
dataissue = []
datawiki = []
for row in rows:
    id = row[0]
    version = int(row[1])
    type = row[2]
    jid = row[3]
    raw_changes = row[4]
    created_on = row[5]
    notes = row[6]
    user_id = row[7]
    if type in ["time_entries", "documents"]: # only have 1 item each
        continue
    elif type == "attachments": # 163
        continue
    elif type == "messages": # 3
        continue
    elif type == ["Issue", "attachments"] and version > 1:
        changes = yaml.load(raw_changes)
        for k, v in changes.iteritems():
            if k == "attachment":
                property = 'attachment'
                prop_key = re.sub("\d+", "", k)
            elif k == "custom_values":
                property = 'cf'
                prop_key = re.sub("\d+", "", k)
            else:
                property = 'attr'
                prop_key = k
            dataissue.append({'id': id,
                         'property': property,
                         'prop_key': prop_key,
                         'old_value': v[0],
                         'new_value': v[1],
                        })
    elif type == "wiki_edits":
        changes = yaml.load(raw_changes)
        datawiki.append({
            'id': id,
            'wiki_content_id': jid,
            'page_id': jid,
            'author_id': user_id,
            'data': bytearray(changes.get('data'), encoding="utf-8"),
            'compression': changes.get('compression', None),
            'updated_on': created_on,
            'comments': notes,
            'version': version,
        })
    if len(dataissue) > commit:
        cur = conn.cursor()
        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)
        cur.close()
        dataissue = []
    if len(datawiki) > commit:
        cur = conn.cursor()
        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)
        cur.close()
        datawiki = []

cur = conn.cursor()
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)
cur.close()
cur = conn.cursor()
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)
cur.close()
conn.commit()
conn.close()
EOF

$ psql redmine <<EOF
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);
ALTER TABLE journals DROP COLUMN changes_chili;
ALTER TABLE journals DROP COLUMN version;
EOF

# On root in /srv/http/redmine:

$ RAILS_ENV=production REDMINE_LANG=fr bundle exec rake redmine:load_default_data

$ cat > mailhandler.sh <<EOF
#!/bin/bash
exec bundle exec ruby extra/mail_handler/rdm-mailhandler.rb --url http://chiliproject.tetaneutral.net/ --key lVYqSEk1kAUtwsXe3qzf --project tetaneutral.net" 
EOF

$ chmod +x mailhandler.sh

# change in /etc/aliases the chiliproject alias to:

chiliproject: "|/srv/http/redmine/mailhandler.sh" 

# Dans /etc/apache2/site-enabled/chiliproject changer les '/srv/http/chiliproject/public' en '/srv/http/redmine/public'
# Et ajouter en tout en haut du fichier 'PassengerDefaultUser www-data'

# Copie des fichiers uploadé:

$ cd /srv/http/redmine
$ rsync -a ../chiliproject/files/ files/

# Remise à plat des permissions:

$ chown -R www-data:www-data files log tmp public/plugin_assets
$ chmod 755 files log tmp public/plugin_assets
$ find files -type d -exec chmod 755 {} \;
$ find public/plugin_assets -type d -exec chmod 755 {} \;
$ find log -type d -exec chmod 755 {} \;
$ find tmp -type d -exec chmod 755 {} \;
$ find files -type f -exec chmod 644 {} \;
$ find public/plugin_assets -type f -exec chmod 644 {} \;
$ find log -type f -exec chmod 644 {} \;
$ find tmp -type f -exec chmod 644 {} \;

Problemes

Lors de la migration

  1. TODO ?