perling/deploy-production.sh

110 lines
3.4 KiB
Bash

#!/bin/bash
# Production Deployment Script for Perizinan System
# Run this script after deploying to production server
echo "🚀 Setting up Perizinan API Integration for Production..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get current directory
CURRENT_DIR=$(pwd)
echo -e "${BLUE}Current directory: $CURRENT_DIR${NC}"
# Check if we're in Laravel project
if [ ! -f "artisan" ]; then
echo -e "${RED}❌ Error: artisan file not found. Make sure you're in Laravel project directory.${NC}"
exit 1
fi
# 1. Make shell scripts executable
echo -e "${YELLOW}📁 Making shell scripts executable...${NC}"
chmod +x sync-perizinan.sh
chmod +x run-scheduler.sh
echo -e "${GREEN}✅ Shell scripts are now executable${NC}"
# 2. Create log directories if they don't exist
echo -e "${YELLOW}📁 Creating log directories...${NC}"
mkdir -p storage/logs
echo -e "${GREEN}✅ Log directories created${NC}"
# 3. Set proper permissions
echo -e "${YELLOW}🔐 Setting proper permissions...${NC}"
chmod -R 775 storage/
chmod -R 775 bootstrap/cache/
echo -e "${GREEN}✅ Permissions set${NC}"
# 4. Update .env for production
echo -e "${YELLOW}⚙️ Checking .env configuration...${NC}"
if [ ! -f ".env" ]; then
echo -e "${RED}❌ .env file not found. Please create it first.${NC}"
exit 1
fi
# Check if API credentials are set
if grep -q "PERIZINAN_API_BEARER_TOKEN=your_actual_bearer_token" .env; then
echo -e "${RED}⚠️ Warning: Please update PERIZINAN_API_BEARER_TOKEN in .env${NC}"
fi
if grep -q "PERIZINAN_API_KEY=your_actual_api_key" .env; then
echo -e "${RED}⚠️ Warning: Please update PERIZINAN_API_KEY in .env${NC}"
fi
# 5. Run database migrations
echo -e "${YELLOW}🗄️ Running database migrations...${NC}"
php artisan migrate --force
echo -e "${GREEN}✅ Database migrations completed${NC}"
# 6. Test API connection
echo -e "${YELLOW}🌐 Testing API connection...${NC}"
php artisan perizinan:sync pertek
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ API connection test successful${NC}"
else
echo -e "${RED}❌ API connection test failed. Please check your credentials.${NC}"
fi
# 7. Setup cron job options
echo ""
echo -e "${BLUE}📅 Cron Job Setup Options:${NC}"
echo ""
echo -e "${YELLOW}Option 1: Laravel Scheduler (Recommended)${NC}"
echo "Add this line to crontab (crontab -e):"
echo -e "${GREEN}* * * * * cd $CURRENT_DIR && ./run-scheduler.sh >/dev/null 2>&1${NC}"
echo ""
echo -e "${YELLOW}Option 2: Direct Sync${NC}"
echo "Add this line to crontab (crontab -e):"
echo -e "${GREEN}0 0 * * * cd $CURRENT_DIR && ./sync-perizinan.sh >/dev/null 2>&1${NC}"
echo ""
# 8. Show commands for manual setup
echo -e "${BLUE}📋 Manual Commands:${NC}"
echo ""
echo "To edit crontab:"
echo -e "${GREEN}sudo crontab -e${NC}"
echo ""
echo "To view current crontab:"
echo -e "${GREEN}crontab -l${NC}"
echo ""
echo "To test sync manually:"
echo -e "${GREEN}php artisan perizinan:sync${NC}"
echo ""
echo "To check synced data:"
echo -e "${GREEN}php artisan perizinan:check${NC}"
echo ""
echo "To view logs:"
echo -e "${GREEN}tail -f storage/logs/cron.log${NC}"
echo -e "${GREEN}tail -f storage/logs/laravel.log${NC}"
echo ""
echo -e "${GREEN}🎉 Production setup completed!${NC}"
echo -e "${YELLOW}📝 Don't forget to:${NC}"
echo "1. Update API credentials in .env"
echo "2. Setup cron job using one of the options above"
echo "3. Monitor logs after deployment"