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를 입력한다.
2. node의 모듈에 오래된 버전의 라이브러리들이 설치된 경우
node_module삭제 후 재설치
pm2 kill
rm -rf node_modules
npm i
pm2 start index.js -xn 'myapp'
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
'문제해결' 카테고리의 다른 글
ubuntu Swap Space 추가하기 (0) | 2024.01.11 |
---|---|
[ERROR] Your password does not satisfy the current policy requirements 해결 (0) | 2024.01.09 |
sh를 통해 로컬에서 Remote Ubuntu 실행하기 / pm2: command not found 해결 (0) | 2024.01.08 |
[ERROR] Client does not support authentication protocol requested by server; consider upgrading MySQL client 해결 (0) | 2024.01.08 |
AWS EC2 인스턴스 ssh연결 실패 - Connection timed out 오류 (0) | 2024.01.08 |