Next.js Discord

Discord Forum

Restarting nextjs server on webhook

Answered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Australian Freshwater CrocodileOP
Can anyone help me with this? I created an api /api/handle-webhook
It does this
import { exec } from "child_process"
import path from 'path';

exec(`sh ${path.join(process.cwd(), "deploy.sh")}`, function (error, stdout, stderr) {
        console.log('stdout', stdout);
        console.error('stderr', stderr);
        if (error !== null) {
            console.log('exec error: ', error);
        }
})

Like the deploy.sh file restarts the nextjs server. All this is triggered by the github webhook.
But the server is not restarting. The process is being killed but it isn't restarting. When I exec() does deploy.sh kill the process that is running deploy.sh or not? This is what deploy.sh looks like:
#!/bin/bash
cd "$(dirname "$0")"
git pull
npm i
npm run build
kill $(ps aux | grep node | grep website-frontend | awk '{print $2}')
npm run start
Answered by Australian Freshwater Crocodile
the script worked only with screen
by executing
exec(`screen ${path.join(process.cwd(), "deploy.sh")}

Note: nohup instead of screen didn't work for some reason
View full answer

1 Reply

Australian Freshwater CrocodileOP
the script worked only with screen
by executing
exec(`screen ${path.join(process.cwd(), "deploy.sh")}

Note: nohup instead of screen didn't work for some reason
Answer