본문 바로가기
문제해결

[Error] exited with code [1] via signal [SIGINT] / Too many unstable restarts 에러 해결

by limew 2024. 1. 8.

 

pm2 를 이용하여 node.js를 백그라운드로 실행하여 서버를 운영하던 중

서버가 갑자기 errored  를 띄우며 작동하지 않아 pm2의 log를 확인했다

 

 

had too many unstable restarts

pm2로 구동한 프로세스가 계속해서 재시작하여 pm2에서 errored로 처리해버린 것이다

 

exited with code [1] via signal [SIGINT]

 

프로세스가 시그널 SIGINT를 받아 코드 1로 종료되었다는 것을 나타낸다. SIGINT는 사용자가 키보드에서 Ctrl+C를 눌러 프로세스에 종료 신호를 보냈을 때 보통 발생하는 시그널이다

 

코드 1은 일반적으로 프로그램에서 오류가 발생하여 비정상적으로 종료되었음을 나타내는데, 이 종류의 오류는 프로그램의 특정 부분에서 예외가 발생하거나 요구 사항을 충족하지 못했을 때 발생할 수 있다

 


해결법

찾아보니 많은 사람들이 1,2번째 방법으로 해결한 것 같다. 하지만 나는 해결이 안 되서 3번으로 해결했다.

1. Entry Point가 불명확한 경우

pm2 start app.js에서 app.js는 정확한 entry point가 아니다.

pm2 start ./bin/www 과 같이 정확한 entry point를 입력한다.

 

 

pm2 start app.js is exiting after 15 restarts

npm start will start my app just fine but when I do: pm2 start app.js I get: [PM2] Spawning PM2 daemon [PM2] PM2 Successfully daemonized [PM2] Process app.js launched ┌──────────┬────┬──────┬───...

stackoverflow.com

 

2. node의 모듈에 오래된 버전의 라이브러리들이 설치된 경우

node_module삭제 후 재설치

pm2 kill
rm -rf node_modules
npm i
pm2 start index.js -xn 'myapp'

 

 

Too Many Unstable Restarts · Issue #659 · Unitech/pm2

Hi all - I have a node server which runs fine under forever, and will 'start' under PM2, however, as soon as the first request hits the server - the PM2 errors out with the message... Script index....

github.com

 

 

3. ssh 로그인이 안 된 경우

ssh로 접속한 경우 non-interactive모드이기 때문에 환경변수가 달라서 node와 pm2를 못 찾는다.

이때 bash login을 통해 Interactive모드로 변환하고 환경변수를 불러오면 pm2를 사용할 수 있다.

bash --login -i run.sh

 

  • 인터랙티브(Interactive) 커맨드는 사용자와 시스템 간의 상호작용이 필요한 커맨드이다. 예를 들어, 사용자가 선택을 하거나 입력하는 프롬프트를 포함하는 명령어 등이 여기에 해당한다.
  • 비인터랙티브(Non-interactive) 커맨드는 사용자의 입력 없이 실행되는 커맨드이다

 

참고

https://superuser.com/questions/564926/profile-is-not-loaded-when-using-ssh-ubuntu

 

~/.profile is not loaded when using SSH (Ubuntu)

Edited to reflect the problem I really wanted to solve: I need to set up my ruby environment so I can deploy via Capistrano. export PATH=$HOME/.rbenv/bin:$PATH eval "$(rbenv init -)" I put these...

superuser.com