Reputation: 29
So i have a NextJs project. In my /admin route, i have a button, where i call some /same_server/api/update_frontend
This calls a user of a server to go to the folder, where my NextJs project is and works with terminal:
$ssh = new SSH2(config('app-update.ssh-host'), config('app-update.ssh-port')); if ($ssh->login(config('app-update.ssh-user'), config('app-update.ssh-password'))) { return $ssh->exec('cd ' . config('app-update.ssh-front-directory') . " && pm2 stop all; pm2 delete all; git restore .; git pull origin main; yarn build; pm2 start yarn --name 'website' -- start"); }
I use pm2 to keep NextJs running. I want to run these commands:
pm2 stop all; pm2 delete all; git restore .; git pull origin main; yarn build; pm2 start yarn --name 'website' -- start
But i failed and figured out, that if i, for example just run yarn dev, it starts nextjs in dev mode, thinks the task is finished, closes terminal and everything stops.
If i run pm2 start yarn --name 'website' -- dev
it works fine then.
So how do i correctly initiate all those commands 1 by one, so at the end, ill have completed build and started project kept by pm2?
Upvotes: 1
Views: 402
Reputation: 29
What helped: connect to a user of a server throught root. Somehow, you can not run pm2 commands directly from root, need to connect to your user
Upvotes: 0