# # 고고컴퍼니 어드민 개발 서버 배포

개발 서버 접속 정보

```
주소 :
ID :
PW :
port : 
```



1. node.js 설치 (최초 1회)

```bash
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash

# vi ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# source ~/.bashrc

# nvm --version
0.40.2

# nvm install 20

# node -v
v20.19.0
```

2. pnpm 설치 (최초 1회)

```bash
# curl -fsSL https://get.pnpm.io/install.sh | sh -

# source ~/.bashrc

# pnpm -v
10.7.1
```

3. pm2 설치 (최초 1회)

```bash
# pnpm add -g pm2
```

4. 소스 코드 다운로드 (최초 1회)

```bash
// 다운로드할 경로 이동하여 git clone
# git clone http://${yona 아이디}@www.sjsofttech.co.kr:9000/GOGOCOMPANY_COUPON_SALE/ADMIN_COUPON_SALE

# cd ADMIN_COUPON_SALE

# git pull origin prod
```

* 개발 환경일 경우 (dev branch로 변경)

```bash
# git checkout -b dev origin/dev

# git pull origin dev
```

***

5\. 소스 최신화

5-1. 개발 환경

```bash
# git pull origin dev
```

5-2. 상용 환경

```bash
# git pull origin prod
```

6. 패키지 설치

```bash
# rm -rf ./node_modules ./pnpm-lock.yaml

# pnpm install
```

7. 빌드

```bash
# pnpm run build
```

* 빌드 캐시가 남아있을 경우

```bash
# rm -rf ./.next

# pnpm run build
```

8. 최초 실행

* pm2 start npm --name "${프로젝트명}" --interpreter $(which pnpm) -- run ${실행할 package.json의 script / 개발: start:dev, 상용: start:prod)}

```bash
# pm2 start npm --name "admin-coupon-sale" --interpreter $(which pnpm) -- run start
[PM2] Starting /home/gogodev/.nvm/versions/node/v20.19.0/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ admin-coupon-sale  │ fork     │ 0    │ online    │ 0%       │ 33.4mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
```

* 실행 확인

```bash
# pm2 list
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ admin-coupon-sale  │ fork     │ 0    │ online    │ 0%       │ 72.7mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

# pm2 logs {id} 또는 pm2 logs {name}
# pm2 logs 0
[TAILING] Tailing last 15 lines for [0] process (change the value with --lines option)
/home/gogodev/.pm2/logs/admin-coupon-sale-error.log last 15 lines:
/home/gogodev/.pm2/logs/admin-coupon-sale-out.log last 15 lines:
0|admin-co |
0|admin-co | > gogocompany-coupon-sale-admin@0.1.0 start
0|admin-co | > next start
0|admin-co |
0|admin-co |    ▲ Next.js 15.1.3
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 488ms

# pm2 logs admin-coupon-sale
[TAILING] Tailing last 15 lines for [0] process (change the value with --lines option)
/home/gogodev/.pm2/logs/admin-coupon-sale-error.log last 15 lines:
/home/gogodev/.pm2/logs/admin-coupon-sale-out.log last 15 lines:
0|admin-co |
0|admin-co | > gogocompany-coupon-sale-admin@0.1.0 start
0|admin-co | > next start
0|admin-co |
0|admin-co |    ▲ Next.js 15.1.3
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 488ms

```

* 서버 재부팅 시 자동 실행 설정 (명령어 실행 후 나오는 script를 복사하여 실행)

```bash
# pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/gogodev/.nvm/versions/node/v20.19.0/bin /home/gogodev/.local/share/pnpm/global/5/.pnpm/pm2@6.0.5/node_modules/pm2/bin/pm2 startup systemd -u gogodev --hp /home/gogodev

# sudo env PATH=$PATH:/home/gogodev/.nvm/versions/node/v20.19.0/bin /home/gogodev/.local/share/pnpm/global/5/.pnpm/pm2@6.0.5/node_modules/pm2/bin/pm2 startup systemd -u gogodev --hp /home/gogodev
로컬 시스템 관리자에게 일반적인 지침을 받았으리라 믿습니다.
보통 세가지로 요약합니다:

    #1) 타인의 사생활을 존중하십시오.
    #2) 입력하기 전에 한 번 더 생각하십시오.
    #3) 막강한 힘에는 상당한 책임이 뒤따릅니다.

[sudo] gogodev의 암호: password
```

* pm2 상태 저장

```bash
# pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/gogodev/.pm2/dump.pm2
```

9. 서버 재시작 (빌드까지 완료된 이후)

```bash
# pm2 restart {id} 또는 pm2 restart {name}

# pm2 restart 0
[PM2] Applying action restartProcessId on app [0](ids: [ '0' ])
[PM2] [admin-coupon-sale](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ admin-coupon-sale  │ fork     │ 1    │ online    │ 0%       │ 18.3mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

# pm2 logs 0
[TAILING] Tailing last 15 lines for [0] process (change the value with --lines option)
/home/gogodev/.pm2/logs/admin-coupon-sale-error.log last 15 lines:
/home/gogodev/.pm2/logs/admin-coupon-sale-out.log last 15 lines:
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 488ms
0|admin-co |
0|admin-co | > gogocompany-coupon-sale-admin@0.1.0 start
0|admin-co | > next start
0|admin-co |
0|admin-co |    ▲ Next.js 15.1.3
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 495ms

---------------------------------------------------------------------------------------
# pm2 restart admin-coupon-sale
[PM2] Applying action restartProcessId on app [admin-coupon-sale](ids: [ 0 ])
[PM2] [admin-coupon-sale](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ admin-coupon-sale  │ fork     │ 2    │ online    │ 0%       │ 17.1mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

# pm2 logs admin-coupon-sale
[TAILING] Tailing last 15 lines for [0] process (change the value with --lines option)
/home/gogodev/.pm2/logs/admin-coupon-sale-error.log last 15 lines:
/home/gogodev/.pm2/logs/admin-coupon-sale-out.log last 15 lines:
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 495ms
0|admin-co |
0|admin-co | > gogocompany-coupon-sale-admin@0.1.0 start
0|admin-co | > next start
0|admin-co |
0|admin-co |    ▲ Next.js 15.1.3
0|admin-co |    - Local:        http://localhost:3000
0|admin-co |    - Network:      http://110.10.189.211:3000
0|admin-co |
0|admin-co |  ✓ Starting...
0|admin-co |  ✓ Ready in 496ms
```

