Commit af06148c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Fix : PCRU (erreur d'écriture des configurations)

- DOC : Mise à jour détaillée (Debian 11 / PHP 7.4 / Composer / Worker)
parent 0fd55cfe
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
### Version actuelle
- **VERSION 2.12 "Spartan"** ([Note de version](doc/versions/version-2.12.md))

- [Mise à jour technique](doc/upgrade-to-spartan.md) 
  
### Version antérieurs
 - VERSION 2.11 "MacClane" ([Note de version](doc/versions/version-2.11.md))
 - VERSION 2.10 "Creed" ([Note de version](doc/versions/version-2.10.md))
+276 −0
Original line number Diff line number Diff line
# Spartan Release

## Passage à Debian 11 "Bullseye"

### MISE à JOUR DEBIAN 10 > 11

Commencez par mettre à jour le système.

```bash
apt update
apt upgrade
```

### Installation de PHP7.4

Installation des paquets PHP

```bash
apt install php7.4 \
 php7.4-bcmath  \
 php-bz2 \
 php7.4-cli \
 php7.4-curl \
 php7.4-dom \
 php7.4-gd \
 php7.4-gearman \
 php7.4-intl \
 php7.4-ldap \
 php7.4-mbstring \
 php7.4-pdo-pgsql \
 php7.4-xml  \
 php7.4-zip
```

### Passage PHP7.3 > PHP7.3

Il faut ensuite configurer l'utilisation de PHP pour l'utilisation en ligne de commande (**cli**) et *Apache* :

#### Pour PHP-CLI

```bash
update-alternatives --config php
```

Choisir PHP 7.4 :

```
Il existe 2 choix pour l'alternative php (qui fournit /usr/bin/php).

  Sélection   Chemin           Priorité  État
------------------------------------------------------------
  0            /usr/bin/php7.4   74        mode automatique
* 1            /usr/bin/php7.3   73        mode manuel
  2            /usr/bin/php7.4   74        mode manuel

Appuyez sur <Entrée> pour conserver la valeur par défaut[*] ou choisissez le numéro sélectionné :0
update-alternatives: utilisation de « /usr/bin/php7.4 » pour fournir « /usr/bin/php » (php) en mode automatique
```

#### Pour le module PHP Apache

Mettre à jour le module PHP de Apache :

```
a2dismod php7.3
systemctl restart apache2
a2enmod php7.4
systemctl restart apache2
```

#### Vérifier

Vérifier que tout les modules PHP sont bien chargés en 7.4 :

```bash
php bin/oscar.php check:config
```

```
------------- --------- -----------
 Modules PHP   Version   Statut
------------- --------- -----------
 bz2           7.4.21    Installed
 curl          7.4.21    Installed
 fileinfo      7.4.21    Installed
 gd            7.4.21    Installed
 gearman       2.1.0     Installed
 iconv         7.4.21    Installed
 json          7.4.21    Installed
 ldap          7.4.21    Installed
 mbstring      7.4.21    Installed
 openssl       7.4.21    Installed
 pdo_pgsql     7.4.21    Installed
 posix         7.4.21    Installed
 Reflection    7.4.21    Installed
 session       7.4.21    Installed
 xml           7.4.21    Installed
 zip           1.15.6    Installed
------------- --------- -----------
```

## Passage à composer 2.x

```
wget https://getcomposer.org/download/latest-stable/composer.phar
```

## Passage sur la branche "Spartan"

```bash
git fetch
git checkout spartan

# Installation des dépendances
php composer.phar install

# Mise à jour du modèle
php vendor/bin/doctrine-module orm:schema-tool:update --force
```

### Mise à jour de la configuration LDAP

Configuration de l'authentification

```php
<?php
// config/autoload/local.php
$settings = array(
    // Authentification via LDAP/BDD
    'local' => [
        'order' => 2,
        'enabled' => true,
        'db' => [
            'enabled' => true,
        ],
        'ldap' => [
            'enabled' => false,
        ],
    ],
    
    // CAS
    'cas' => [
        'order' => 1,
        'enabled' => false,
        'connection' => [
            'default' => [
                'params' => [
                    'hostname' => 'host.domain.fr',
                    'port'     => 443,
                    'version'  => "2.0",
                    'uri'      => "",
                    'debug'    => false,
                ],
            ],
        ]
    ]
);

/**
 * You do not need to edit below this line
 */
return array(
    'unicaen-auth' => $settings,
);
```

### Relancer le OscarWorker

Oscar *"Spartan"* propose un refonte du système de recalcule des Notifications et de la réindexation. A ce titre, le Worker a été modifié, il faudra donc le relancer : 

```bash
service oscarworker stop
service oscarworker start
```

Vérifier son fonctionnement

```bash
# On affiche les logs du Worker
journalctl -u oscarworker -f
```

Puis dans lancez le check:config

```
php bin/oscar.php check:config
```

Vous devriez voir dans le journal du Worker ce type de sortie : 

```
oct. 11 10:41:10 woscar-pp systemd[1]: Stopped OSCAR Worker.
oct. 11 10:41:14 woscar-pp systemd[1]: Started OSCAR Worker.
oct. 11 10:41:14 woscar-pp php[378252]: ###################################################################
oct. 11 10:41:14 woscar-pp php[378252]: # OSCAR WORKER STARTED v2.12.0-spartan#0fd55cfe "Spartan" (2021-10-06 14:10:01) SPARTAN
oct. 11 10:41:14 woscar-pp php[378252]: # working directory : '/var/OscarApp/oscar/bin'
oct. 11 10:41:14 woscar-pp php[378252]: ###################################################################
oct. 11 10:43:46 woscar-pp php[378252]: stdClass Object
oct. 11 10:43:46 woscar-pp php[378252]: (
oct. 11 10:43:46 woscar-pp php[378252]:     [message] => Check Config Oscar
oct. 11 10:43:46 woscar-pp php[378252]: )
oct. 11 10:43:46 woscar-pp php[378252]: [worker] Hello with 1
```

Les logs Oscar ont également été enrichies, les interactions entre Oscar et Gearman y sont visibles : 

```bash
tail -f logs.oscar.log
```

```
[2021-10-11T10:43:46.641506+02:00] oscar.INFO: [COMMAND] check:config [] []
[2021-10-11T10:43:46.765458+02:00] oscar.INFO:  > [gearman:call] TEST OK] [] []
```

Vous pouvez vérifier le processus d'actualisation de l'index en allant dans une activité de recherche et y ajouter un responsable scientifique, les logs Oscar détailleront les opérations effectuées : 

```
[2021-10-11T11:41:24.014487+02:00] oscar.INFO: a supprimé [Person:5063:Stephane Bouvry](Responsable scientifique) dans l'activité [Activity:11842:Présentation OSCAR Nanterre - subvention - comete]  [] []
[2021-10-11T11:41:24.292731+02:00] oscar.NOTICE: CMD success : Notifications mises à jour '[2021DRI00012] Présentation OSCAR Nanterre - subvention - comete' [] []
[2021-10-11T11:41:24.514452+02:00] oscar.NOTICE: CMD success : Index de recherche mis à jour pour '[2021DRI00012] Présentation OSCAR Nanterre - subvention - comete' mis à jour [] []
[2021-10-11T11:41:24.735195+02:00] oscar.NOTICE: CMD success : Index de recherche mis à jour pour 'Stephane Bouvry' mis à jour [] []
```

Et dans les logs du *worker* : 

```
oct. 11 11:41:24 woscar-pp php[378252]: [worker] exec /usr/bin/php bin/oscar.php console  notificationsactivity '{"activityid":11842}'
oct. 11 11:41:24 woscar-pp php[378252]: [worker] exec /usr/bin/php bin/oscar.php console  indexactivity '{"activityid":11842}'
oct. 11 11:41:24 woscar-pp php[378252]: [worker] exec /usr/bin/php bin/oscar.php console  indexperson '{"personid":5063}'
```

### Réindexation de la recherche

Il est chaudement recommandé de recalculer les index de recherche : 

```
# Index des activités
php bin/oscar.php activity:search-rebuild -f

# Index des Organisations
php bin/oscar.php organization:search-rebuild

# Index des personnes
php bin/oscar.php person:search-rebuild
```


### Elastic : cluster_block_exception

Si vous voyez l'erreur : 

```
[2021-10-11T10:51:43.473403+02:00] oscar.ERROR: CMD error : {"error":{"root_cause":[{"type":"cluster_block_exception","reason":"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"}],"type":"cluster_block_exception","reason":"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"},"status":403} [] []
```

C'est que **Elastic Search** est passé en mode *readonly**. Ce problème est généralement consécutif à une saturation de l'espace disque.

Pour régler le problème, faites un peu de place sur la machine, puis faites sauter le verrou placé par Elastic via la commande CURL : 

```
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
```

### Installation des référentiels

Depuis l'interface d'administration : `Administration > Configuration et maintenance` :

 - Dans la section **Nomenclatures > Pays (ISO 3166)**, cliquez sur le bouton **Actualiser les pays**

 - Dans la section **Modules > PCRU**, cliquez sur le bouton **Mettre à jour les référentiels**.

### Activer PCRU

Depuis l'interface d'administration : `Administration > Configuration et maintenance` :
+146 −156
Original line number Diff line number Diff line
<template>
  <section style="position: relative; min-height: 100px">
        <ajax-oscar :oscar-remote-data="remoterState" />

    <div v-if="configuration" class="container">
      <form action="" method="post">
        <div class="row">
@@ -88,7 +86,7 @@
            </div>

            <div class="row">
                        <button type="submit" class="btn btn-primary">
              <button type="button" class="btn btn-primary" @click="performEdit">
                <i class="icon-floppy"></i>
                Enregistrer
              </button>
@@ -114,20 +112,14 @@

 */

    import AjaxOscar from "./remote/AjaxOscar";
    import OscarRemoteData from "./remote/OscarRemoteData";
import PasswordField from "./components/PasswordField";

    // test
    let oscarRemoteData = new OscarRemoteData();

function flashMessage() {
}

export default {

  components: {
            "ajax-oscar": AjaxOscar,
    "password-field": PasswordField
  },

@@ -138,7 +130,6 @@
  data() {
    return {
      formData: null,
                remoterState: oscarRemoteData.state,
      configuration: null
    }
  },
@@ -146,33 +137,32 @@
  methods: {


            // performEdit(){
            //     let documentId = this.editData.document.id;
            //     let newType = this.editData.documentype_id;
            //     this.editData = null;
            //     let formData = new FormData();
            //     formData.append('documentId', documentId);
            //     formData.append('type', newType);
            //     oscarRemoteData
            //         .setPendingMessage("Modification du type de document")
            //         .setErrorMessage("Impossible de modifier le type de document")
            //         .performPost(this.urlDocumentType, formData, (response) => {
            //             this.fetch();
            //         });
            // },
    performEdit() {

      let formData = new FormData();
      formData.append('pcru_enabled', this.configuration.pcru_enabled);
      formData.append('host', this.configuration.pcru_host);
      formData.append('port', this.configuration.pcru_port);
      formData.append('user', this.configuration.pcru_user);
      formData.append('pass', this.configuration.pcru_pass);
      formData.append('ssh', this.configuration.pcru_ssh);

      this.$http.post(this.url, formData).then(ok=>{
        this.fetch();
      })
    },

    handlerSuccess(success) {
      let data = success.data;
                console.log("SUCCESS", success);
      this.configuration = data.configuration_pcru;
    },

    fetch() {
                oscarRemoteData
                    .setDebug(true)
                    .setPendingMessage("Chargement de la configuration PCRU")
                    .setErrorMessage("Impossible de charger la configuration")
                    .performGet(this.url, this.handlerSuccess);
      this.$http.get(this.url).then(
          ok => {
            this.handlerSuccess(ok)
          }
      )
    }
  },

+28 −23
Original line number Diff line number Diff line
@@ -1319,6 +1319,7 @@ class AdministrationController extends AbstractOscarController implements UsePro
        $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_PARAMETERS_MANAGE);

        if ($this->isAjax()) {
            if( $this->getRequest()->isGet() ){
                $response = $this->baseJsonResponse();
                $response['configuration_pcru'] = [
                    'pcru_enabled' => $this->getOscarConfigurationService()->getPcruEnabled(),
@@ -1332,8 +1333,9 @@ class AdministrationController extends AbstractOscarController implements UsePro
            }

            if ($this->getRequest()->isPost()) {
                $this->getLoggerService()->info("Modification de la configuration PCRU");
                $data = [
                'pcru_enabled' => $this->params()->fromPost('pcru_enabled') == 'on' ? true : false,
                    'pcru_enabled' => $this->params()->fromPost('pcru_enabled') == 'true' ? true : false,
                    'pcru_host' => $this->params()->fromPost('host'),
                    'pcru_port' => $this->params()->fromPost('port'),
                    'pcru_user' => $this->params()->fromPost('user'),
@@ -1344,8 +1346,11 @@ class AdministrationController extends AbstractOscarController implements UsePro
                foreach ($data as $key => $value) {
                    $this->getOscarConfigurationService()->saveEditableConfKey($key, $value);
                }
            return $this->redirect()->toRoute('administration/pcru');
                $this->getResponseOk("Informations PCRU modifiées");
            }
        }



        return [];
    }
+2 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
            $parser = new Parser();
            $parsed = $parser->parse(file_get_contents($path));
            if( $parsed ){
                $parser->parse(file_get_contents($path));
                return $parsed;
            } else {
                return [];
            }
@@ -184,6 +184,7 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
    public function saveEditableConfKey($key, $value)
    {
        $conf = $this->getEditableConfRoot();
        error_log("Save edit : " . print_r($conf, true));
        $conf[$key] = $value;
        $writer = new Dumper();
        file_put_contents($this->getYamlConfigPath(), $writer->dump($conf));
Loading