Partage
  • Partager sur Facebook
  • Partager sur Twitter

Mon service ne fonctionne pas

Sujet résolu
    17 octobre 2019 à 16:06:27

    Bonjour,

    J'ai créé une application en nodejs lié au webhook de github (au push sur la branche master). Ca fonctionne bien, mais lorsque je veux le lancer en mode service rien ne se passe au push.

    L'application en js:

    const express = require('express');
    const app = express();
    const bodyParser = require('body-parser');
    const { execFile } = require('child_process');
    require('dotenv').config();
    
    app.use(bodyParser.json());
    
    
    app.listen(process.env.PORT, () => {
        console.log(`Server started at port ${process.env.PORT}`)
    })
    
    app.post('/webhook', (req, res) => {
        const branch = req.body.ref.split('heads/').pop();
        if (branch === 'master') {
            execFile('sh', ['script.sh'], (error, stdout, stderr) => {
                if (error) {
                    throw error;
                }
                console.log(stdout);
            })
        }
    })

    et le service (/etc/systemd/system/github-webhook.service)

    [Unit]
    Description=Autodeploy when push on master using the Github's webhook
    After=network.target
    
    [Service]
    Environment=PORT=8000
    ExecStart=/usr/bin/node /var/www/github-autodeploy/app.js
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target

    Merci d'avance

    • Partager sur Facebook
    • Partager sur Twitter
      18 octobre 2019 à 9:06:37

      Que donne systemctl status github-webhook.service ?
      • Partager sur Facebook
      • Partager sur Twitter

      git is great because Linus did it, mercurial is better because he didn't.

        18 octobre 2019 à 10:20:37

        Ca me donne ça:

        ● github-webhook.service - Autodeploy when push on master using the Github's webhook
           Loaded: loaded (/etc/systemd/system/github-webhook.service; enabled; vendor preset: enabled)
           Active: active (running) since Fri 2019-10-18 08:18:51 UTC; 38s ago
         Main PID: 1680 (node)
            Tasks: 6 (limit: 1152)
           CGroup: /system.slice/github-webhook.service
                   └─1680 /usr/bin/node /var/www/github-autodeploy/app.js
        
        Oct 18 08:18:51 ip-172-31-26-250 systemd[1]: github-webhook.service: Service hold-off time over, scheduling restart.
        Oct 18 08:18:51 ip-172-31-26-250 systemd[1]: github-webhook.service: Scheduled restart job, restart counter is at 1.
        Oct 18 08:18:51 ip-172-31-26-250 systemd[1]: Stopped Autodeploy when push on master using the Github's webhook.
        Oct 18 08:18:51 ip-172-31-26-250 systemd[1]: Started Autodeploy when push on master using the Github's webhook.
        Oct 18 08:18:52 ip-172-31-26-250 node[1680]: Server started at port 8000

        A chaque fois que je fais un systemctl status il me réaffiche stopped et started, ça vient peut être de la le problème ?

        -
        Edité par AceLine 18 octobre 2019 à 10:22:25

        • Partager sur Facebook
        • Partager sur Twitter
          18 octobre 2019 à 10:53:42

          Ligne 17, tu spécies un fichier relatif. Alors que toi tu lance probablement ton code node dans le répertoire courant contenant script.sh. Met un chemin absolu et ça devrait régler le probléme (en faisant un systemctl restart github-webhook bien sûr).
          • Partager sur Facebook
          • Partager sur Twitter

          git is great because Linus did it, mercurial is better because he didn't.

            18 octobre 2019 à 10:59:55

            markand a écrit:

            Ligne 17, tu spécies un fichier relatif. Alors que toi tu lance probablement ton code node dans le répertoire courant contenant script.sh. Met un chemin absolu et ça devrait régler le probléme (en faisant un systemctl restart github-webhook bien sûr).


            C'était effectivement ça, merci beaucoup ça fonctionne bien :)
            • Partager sur Facebook
            • Partager sur Twitter

            Mon service ne fonctionne pas

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown