--- name: systemd-vite-dev-service description: Configure systemd service for Vite development server with external network exposure. Use when setting up persistent Vite dev servers that need to survive SSH disconnections and accept connections from external IPs. --- # Systemd Vite Dev Service Configure Vite development server as a systemd service for persistent, externally-accessible development environments. ## When to Use - Setting up Vite dev server that persists after SSH disconnect - Need external access to dev server (not just localhost) - Creating standardized development environment across reboots - Managing multiple frontend projects with systemd ## Key Configuration ### ExecStart Pattern ```ini ExecStart=/bin/bash -c "cd /path/to/project && npm run dev -- --host 0.0.0.0 --port " ``` Required flags: - `--host 0.0.0.0` - Bind to all interfaces (external access) - `--port ` - Explicit port assignment ### Service File Template ```ini [Unit] Description=Project Frontend Dev Server After=network.target [Service] Type=simple User=ubuntu WorkingDirectory=/home/ubuntu/nanocode/project Environment=NODE_ENV=development ExecStart=/bin/bash -c "cd /home/ubuntu/nanocode/project && npm run dev -- --host 0.0.0.0 --port 10002" Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target ``` ## Commands ```bash # Install and start sudo cp project-frontend.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable project-frontend sudo systemctl start project-frontend # Check status sudo systemctl status project-frontend sudo journalctl -u project-frontend -f # Restart after code changes sudo systemctl restart project-frontend ``` ## Port Planning Reference | Project | Frontend Port | Backend Port | |---------|--------------|--------------| | Feidian Health | 10002 | 10003 | | fumamxCRM | 10000 | 10001 | | personal-blog | 8888 | 8889 | ## Output Format Provide: 1. Complete `.service` file content 2. Installation commands 3. Verification commands (status + journalctl) 4. Port conflict check command: `sudo netstat -tlnp | grep `