리눅스 재시작시 forever도 같이 시작하기

자고 일어나서 보니 모든 서버가 다 꺼져있다 ㅠ

uptime을 보니 얼마전에 재시작을 한 듯 한데 (아니면 무슨 일이 있었던것이거나..)

어찌됐던, 서버가 갑자기 재시작하는 일이 생길 수 있으니 설정을 해 두는것이 맞다고 본다.

스택오버플로우에 해당 문제 해결방법을 찾을 수 있었다.

아래는 best answer 본문이다.

  1. To start editing run the following replacing the “testuser” with your desired runtime user for the node process. If you choose a different user other than yourself, you will have to run this with sudo.
    $ crontab -u testuser -e
  2. If you have never done this before, it will ask you which editor you wish to edit with. I like vim, but will recommend nano for ease of use.
  3. Once in the editor add the following line:
    @reboot /usr/local/bin/forever start /your/path/to/your/app.js
  4. Save the file. You should get some feedback that the cron has been installed.
  5. For further confirmation of the installation of the cron, execute the following (again replacing “testuser” with your target username) to list the currently installed crons:
    $ crontab -u testuser -l 

Note that in my opinion, you should always use full paths when executing binaries in cron. Also, if the path to your forever script is not correct, run which forever to get the full path.

Given that forever calls node, you may also want to provide the full path to node:

@reboot /usr/local/bin/forever start -c /usr/local/bin/node /your/path/to/your/app.js

 

forever의 위치는 다를 수 있으니 which forever를 써서 확인 해 볼 것!