Warning, /swf-monitor/docs/SETUP_GUIDE.md is written in an unsupported language. File is not indexed.
0001 # Setup and Installation Guide
0002
0003 This guide walks you through setting up the `swf-monitor` for local development.
0004
0005 ## Quick Start
0006
0007 For experienced developers who want to get running immediately:
0008
0009 ```bash
0010 # Clone and setup
0011 git clone https://github.com/BNLNPPS/swf-monitor.git
0012 cd swf-monitor
0013 python3 -m venv .venv && source .venv/bin/activate
0014 pip install -r requirements.txt
0015
0016 # Configure environment
0017 cp .env.example .env
0018 # Edit .env with your SECRET_KEY, DB_PASSWORD, and SWF_TESTUSER_PASSWORD
0019
0020 # Setup database and users
0021 python manage.py migrate
0022 python manage.py createsuperuser
0023 python manage.py setup_testuser
0024 python manage.py runserver
0025 ```
0026
0027 Visit `http://127.0.0.1:8000/` to access the monitoring dashboard.
0028
0029 *For detailed step-by-step instructions, continue reading below.*
0030
0031 ## Installation Steps
0032
0033 ### 1. Clone and Setup Environment
0034
0035 ```bash
0036 git clone https://github.com/BNLNPPS/swf-monitor.git
0037 cd swf-monitor
0038
0039 # Create and activate virtual environment
0040 python3 -m venv .venv
0041 source .venv/bin/activate
0042
0043 # Install dependencies
0044 pip install -r requirements.txt
0045 ```
0046
0047 ### 2. Configure Environment Variables
0048
0049 Copy the example environment file:
0050 ```bash
0051 cp .env.example .env
0052 ```
0053
0054 Edit the `.env` file and set your `SECRET_KEY`, `DB_PASSWORD`, and `SWF_TESTUSER_PASSWORD`.
0055
0056 *Generate a new `SECRET_KEY` using:*
0057 ```bash
0058 python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
0059 ```
0060
0061 ### 3. Setup PostgreSQL Database
0062
0063 Log in to PostgreSQL and create the database:
0064
0065 ```sql
0066 CREATE DATABASE swfdb;
0067 CREATE USER admin WITH PASSWORD 'your_db_password';
0068 ALTER ROLE admin SET client_encoding TO 'utf8';
0069 ALTER ROLE admin SET default_transaction_isolation TO 'read committed';
0070 ALTER ROLE admin SET timezone TO 'UTC';
0071 GRANT ALL PRIVILEGES ON DATABASE swfdb TO admin;
0072 ```
0073
0074 ### 4. Run Database Migrations
0075
0076 ```bash
0077 python manage.py migrate
0078 ```
0079
0080 ### 5. Create Admin User
0081
0082 Create a superuser account for admin access:
0083
0084 ```bash
0085 python manage.py createsuperuser
0086 ```
0087
0088 Follow the prompts to set username, email, and password.
0089
0090 ### 6. Create Test User (For Development/Testing)
0091
0092 Create a test user account for automated testing and development:
0093
0094 ```bash
0095 python manage.py setup_testuser
0096 ```
0097
0098 This creates a user named `testuser` that can be used for:
0099 - Automated testing scripts
0100 - WebSocket authentication testing
0101 - Development workflow testing
0102
0103 *Note: The testuser is a regular user (not staff) for testing normal user functionality.*
0104
0105 ## Running the Application
0106
0107 ### Start Development Server
0108
0109 ```bash
0110 python manage.py runserver
0111 ```
0112
0113 The web interface will be available at `http://127.0.0.1:8000/`.
0114
0115
0116 ### HTTPS Development Testing
0117
0118 When running the local dual server via `start_django_dual.sh`, the HTTPS endpoint is served by Daphne. On some hosts, `localhost` resolves to IPv6 (`::1`) while Daphne listens on IPv4 (`0.0.0.0`). This can cause HTTPS handshakes to stall. Use `https://127.0.0.1:8443` for local testing.
0119
0120 ## Production Deployment
0121
0122 For complete production deployment instructions including Apache setup, SSL configuration, and deployment automation, see the comprehensive **[Production Deployment Guide](PRODUCTION_DEPLOYMENT.md)**.
0123
0124 **Quick Reference:**
0125 - Initial setup: Run `sudo ./setup-apache-deployment.sh`
0126 - Deploy updates: `sudo /opt/swf-monitor/bin/deploy-swf-monitor.sh branch main`
0127 - Configuration: Edit `/opt/swf-monitor/config/env/production.env`
0128
0129 ## Testing
0130
0131 Run the full test suite:
0132
0133 ```bash
0134 ./run_tests.py
0135 ```
0136
0137 This script automatically:
0138 - Activates the virtual environment (uses swf-testbed's .venv if available)
0139 - Runs pytest with proper Django configuration
0140 - Provides detailed test output and coverage
0141
0142 Alternatively, you can use Django's built-in test runner:
0143
0144 ```bash
0145 python manage.py test
0146 ```
0147
0148 *Note: `./run_tests.py` is the recommended approach as it handles environment setup automatically and provides better test output.*
0149
0150 All tests should pass.
0151
0152 ## Troubleshooting
0153
0154 ### Common Issues
0155
0156 - **Database connection errors**: Check PostgreSQL is running and credentials in `.env`
0157 - **Migration errors**: Ensure database user has proper permissions
0158 - **Import errors**: Verify virtual environment is activated
0159
0160 ### Getting Help
0161
0162 - Check the [main documentation](README.md) for architectural overview
0163 - Review [API documentation](MCP_REST_IMPLEMENTATION.md) for integration details
0164 - See the [testbed documentation](../../swf-testbed/README.md) for system context