/
pm2 를 system rebooting 시 자동으로 실행하기
pm2 를 system rebooting 시 자동으로 실행하기
pm2 는 start 명령으로 실행할 app 을 지정하면 자동으로 nodeJS 프로세스를 관리하지만 pm2 프로세스가 떠야 가능합니다.
pm2 start app.js
특히 시스템을 재부팅하면 직접 명령어를 입력할 수 없으므로 재부팅시 자동으로 실행해 합니다.
pm2 는 startup 명령어을 실행하면 systemd 를 통해서 자동으로 실행되도록 unit 파일을 생성합니다.
$ pm2 startup [PM2] Init System found: systemd [PM2] To setup the Startup Script, copy/paste the following command: sudo env PATH=$PATH:/usr/bin /home/lesstif/.node_modules/lib/node_modules/pm2/bin/pm2 startup systemd -u lesstif --hp /home/lesstif
그러면 복붙해서 실행하라는 코드를 쉘에서 다시 실행해 주면 systemd unit 파일이 생성됩니다. (경로는 다를 수 있습니다.)
$ sudo env PATH=$PATH:/usr/bin /home/lesstif/.node_modules/lib/node_modules/pm2/bin/pm2 startup systemd -u lesstif --hp /home/lesstif [PM2] Init System found: systemd Platform systemd Template [Unit] Description=PM2 process manager Documentation=https://pm2.keymetrics.io/ After=network.target ... Target path /etc/systemd/system/pm2-lesstif.service Command list [ 'systemctl enable pm2-lesstif' ] [PM2] Writing init configuration in /etc/systemd/system/pm2-lesstif.service [PM2] Making script booting at startup... [PM2] [-] Executing: systemctl enable pm2-lesstif... [PM2] [v] Command successfully executed. +---------------------------------------+ [PM2] Freeze a process list on reboot via: $ pm2 save [PM2] Remove init script via: $ pm2 unstartup systemd
로그를 보면 /etc/systemd/system/pm2-USERNAME.service 경로에 unit 파일이 생성되고 USERNAME 은 사용자의 계정으로 대체됩니다.
즉 lesstif 로 실행했으면 /etc/systemd/system/pm2-lesstif.service 유닛 파일이 생성됩니다.
유닛 파일이 생겼으므로 다른 데몬처럼 systemctl 명령으로 상태를 확인하거나 시작/중지할 수 있습니다.
$ sudo systemctl status pm2-lesstif
혹시 실행이 안 되었다면 다음 명령어로 저널에 남은 로그를 확인하면 됩니다.
$ journalctl -xn --no-pager | less
같이 보기
Ref
, multiple selections available,
Related content
nohup 를 대체하는 systemd-run 명령어 사용법
nohup 를 대체하는 systemd-run 명령어 사용법
More like this
구동 프로세스 최소화
구동 프로세스 최소화
More like this
eclipse/sts 에서 톰캣 구동시 프로그램 파라미터 및 JVM option 설정하는 법
eclipse/sts 에서 톰캣 구동시 프로그램 파라미터 및 JVM option 설정하는 법
More like this
RHEL/CentOS 8 network 설정 반영
RHEL/CentOS 8 network 설정 반영
More like this
minio client 사용법
minio client 사용법
More like this
login 없이 요청 생성할수 있게 JSM 프로젝트 설정
login 없이 요청 생성할수 있게 JSM 프로젝트 설정
More like this