# Rebuild and Restart Script

## Overview
Script untuk rebuild dan restart Calypso API + Frontend service secara otomatis.

## File
`/src/calypso/rebuild-and-restart.sh`

## Usage

### Basic Usage
```bash
cd /src/calypso
./rebuild-and-restart.sh
```

### Dengan sudo (jika diperlukan)
```bash
sudo /src/calypso/rebuild-and-restart.sh
```

## What It Does

### 1. Rebuild Backend
- Build Go binary dari `backend/cmd/calypso-api`
- Output ke `/opt/calypso/bin/calypso-api`
- Set permissions dan ownership ke `calypso:calypso`

### 2. Rebuild Frontend
- Install dependencies (jika diperlukan)
- Build frontend dengan `npm run build`
- Output ke `frontend/dist/`

### 3. Deploy Frontend
- Copy files dari `frontend/dist/` ke `/opt/calypso/web/`
- Set ownership ke `www-data:www-data`

### 4. Restart Services
- Restart `calypso-api.service`
- Reload Nginx (jika tersedia)
- Check service status

## Features
- ✅ Color-coded output untuk mudah dibaca
- ✅ Error handling dengan `set -e`
- ✅ Status checks setelah restart
- ✅ Informative progress messages

## Requirements
- Go installed (untuk backend build)
- Node.js dan npm installed (untuk frontend build)
- sudo access (untuk service management)
- Calypso project di `/src/calypso`

## Troubleshooting

### Backend build fails
- Check Go installation: `go version`
- Check Go modules: `cd backend && go mod download`

### Frontend build fails
- Check Node.js: `node --version`
- Check npm: `npm --version`
- Install dependencies: `cd frontend && npm install`

### Service restart fails
- Check service exists: `systemctl list-units | grep calypso`
- Check service status: `sudo systemctl status calypso-api.service`
- Check logs: `sudo journalctl -u calypso-api.service -n 50`

## Date
2026-01-09
