|
| 1 | +# Private Server 🛡️ |
| 2 | + |
| 3 | +To enhance privacy and control, you can host your own private server. This keeps all message data within your infrastructure while maintaining push notification capabilities through our public server at `api.sms-gate.app`. This setup eliminates the need to configure Firebase Cloud Messaging (FCM) or rebuild the Android app, but it does demand some technical know-how. |
| 4 | + |
| 5 | +<center> |
| 6 | +```mermaid |
| 7 | +flowchart |
| 8 | + %% === MAIN BLOCKS === |
| 9 | + Users["👥 Users"] |
| 10 | + Android["🤖 SMSGate App"] |
| 11 | +
|
| 12 | + subgraph PrivateServer["Private Server"] |
| 13 | + GoServerPrivate["🐹 Server"] |
| 14 | + GoWorkerPrivate["🐹 Worker"] |
| 15 | + DB["🦭 DB"] |
| 16 | +
|
| 17 | + GoServerPrivate <--> DB |
| 18 | + GoWorkerPrivate --> DB |
| 19 | + end |
| 20 | +
|
| 21 | + subgraph Google["Google"] |
| 22 | + FCM["🔥 FCM"] |
| 23 | + end |
| 24 | +
|
| 25 | + subgraph PublicServer["Public Server"] |
| 26 | + GoServerPublic["🐹 api.sms-gate.app"] |
| 27 | + end |
| 28 | +
|
| 29 | + %% === CONNECTIONS === |
| 30 | + |
| 31 | + Users -->|REST API| GoServerPrivate |
| 32 | + GoServerPrivate -->|notification| GoServerPublic |
| 33 | + GoServerPublic -->|notification| FCM |
| 34 | + FCM -->|PUSH| Android |
| 35 | + Android <--> GoServerPrivate |
| 36 | +
|
| 37 | + %% === ALTERNATIVE NOTIFICATION PATH === |
| 38 | + Android -.->|SSE| GoServerPrivate |
| 39 | +
|
| 40 | + %% === STYLING === |
| 41 | + classDef altConn stroke-dasharray: 5 5,stroke:#888,fill:none; |
| 42 | + class Android,GoServerPrivate,GoWorkerPrivate,DB altConn; |
| 43 | +``` |
| 44 | +</center> |
| 45 | + |
| 46 | +## Prerequisites ✅ |
| 47 | + |
| 48 | +=== "🐳 With Docker" |
| 49 | + - Docker installed on Linux VPS |
| 50 | + - MySQL/MariaDB server with empty database and privileged user |
| 51 | + - Reverse proxy with valid SSL certificate ([project CA](../services/ca.md) supported) |
| 52 | + |
| 53 | +=== "🖥️ From Sources" |
| 54 | + - Git and Go 1.23+ toolchain |
| 55 | + - MySQL/MariaDB server with empty database and privileged user |
| 56 | + - Reverse proxy with valid SSL certificate ([project CA](../services/ca.md) supported) |
| 57 | + |
| 58 | +=== "📦 With Helm" |
| 59 | + - Kubernetes cluster with Helm 3+ |
| 60 | + |
| 61 | +## Installation Methods 📦 |
| 62 | + |
| 63 | +=== "🐳 With Docker" |
| 64 | + |
| 65 | + ```sh title="Docker Command" |
| 66 | + docker run -d --name sms-gateway \ |
| 67 | + -p 3000:3000 \ |
| 68 | + -v $(pwd)/config.yml:/app/config.yml \ |
| 69 | + ghcr.io/android-sms-gateway/server:latest |
| 70 | + ``` |
| 71 | + |
| 72 | +=== "🖥️ From Sources" |
| 73 | + |
| 74 | + 1. **Build the binary** |
| 75 | + ```sh |
| 76 | + git clone https://github.com/android-sms-gateway/server.git |
| 77 | + cd server |
| 78 | + go build -o sms-gateway ./cmd/sms-gateway |
| 79 | + chmod +x sms-gateway |
| 80 | + ``` |
| 81 | + |
| 82 | + 2. **Run database migrations** |
| 83 | + ```sh |
| 84 | + ./sms-gateway db:migrate up |
| 85 | + ``` |
| 86 | + |
| 87 | + 3. **Launch the server** |
| 88 | + ```sh |
| 89 | + ./sms-gateway |
| 90 | + ``` |
| 91 | + |
| 92 | +=== "📦 With Helm" |
| 93 | + |
| 94 | + 1. **Add the chart repository** |
| 95 | + ```sh |
| 96 | + helm repo add sms-gate https://s3.sms-gate.app/charts |
| 97 | + helm repo update |
| 98 | + ``` |
| 99 | + |
| 100 | + 2. **Create values.yaml file** |
| 101 | + ```yaml title="values.yaml" |
| 102 | + image: |
| 103 | + pullPolicy: IfNotPresent |
| 104 | + |
| 105 | + database: |
| 106 | + deployInternal: true |
| 107 | + mariadb: |
| 108 | + rootPassword: ${GENERATE_MARIADB_ROOT_PASSWORD} |
| 109 | + password: ${GENERATE_DATABASE_PASSWORD} |
| 110 | + |
| 111 | + gateway: |
| 112 | + privateToken: ${GENERATE_PRIVATE_TOKEN} |
| 113 | + ``` |
| 114 | + |
| 115 | + 3. **Install the chart** |
| 116 | + ```sh |
| 117 | + helm upgrade --install sms-gate-server sms-gate/server \ |
| 118 | + --create-namespace \ |
| 119 | + --namespace sms-gate \ |
| 120 | + --values values.yaml |
| 121 | + ``` |
| 122 | + !!! danger "Security Warning" |
| 123 | + **Never commit secrets to version control!** |
| 124 | + Replace placeholder values with actual high-entropy secrets: |
| 125 | + |
| 126 | + - Generate unique passwords/tokens using: `openssl rand -base64 32` |
| 127 | + - Use environment variables or secret management tools |
| 128 | + - Consider [sealed-secrets](https://github.com/bitnami-labs/sealed-secrets) for Kubernetes |
| 129 | + - Use cloud secret managers (AWS Secrets Manager, Azure Key Vault, GCP Secret Manager) |
| 130 | + |
| 131 | + For detailed Helm chart documentation, see [Helm Chart Documentation](https://github.com/android-sms-gateway/server/blob/master/deployments/helm-chart/README.md). |
| 132 | + |
| 133 | +## Reverse Proxy Configuration 🌐 |
| 134 | + |
| 135 | +### Example Nginx Configuration |
| 136 | + |
| 137 | +```nginx title="Example Nginx Config" |
| 138 | +location / { |
| 139 | + proxy_pass http://localhost:3000; |
| 140 | + proxy_set_header Host $host; |
| 141 | + proxy_set_header X-Forwarded-For $remote_addr; |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +### Advanced Configuration |
| 146 | + |
| 147 | +For SSL termination and advanced routing scenarios, consider: |
| 148 | + |
| 149 | +- Enabling HTTP/2 support |
| 150 | +- Configuring proper timeout values |
| 151 | +- Adding security headers |
| 152 | +- Setting up rate limiting |
| 153 | +- Implementing proxying for SSE connections |
| 154 | + |
| 155 | +## Background Worker ⚙️ |
| 156 | + |
| 157 | +The background worker operates as a separate process from the main server and handles these core maintenance tasks: |
| 158 | + |
| 159 | +- **`devices:cleanup`**: Removes inactive devices older than retention period |
| 160 | +- **`messages:cleanup`**: Cleans up old message records |
| 161 | +- **`messages:hashing`**: Processes message content for privacy compliance |
| 162 | + |
| 163 | +### Launching the Worker |
| 164 | + |
| 165 | +=== "🐳 With Docker" |
| 166 | + |
| 167 | + ```sh title="Docker Command" |
| 168 | + docker run -d --name sms-gateway-worker \ |
| 169 | + -v $(pwd)/config.yml:/app/config.yml \ |
| 170 | + ghcr.io/android-sms-gateway/server:latest \ |
| 171 | + /app/app worker |
| 172 | + ``` |
| 173 | + |
| 174 | +=== "🖥️ From Sources" |
| 175 | + |
| 176 | + Use the same binary as the main server: |
| 177 | + |
| 178 | + ```sh |
| 179 | + ./sms-gateway worker |
| 180 | + ``` |
| 181 | + |
| 182 | +=== "📦 With Helm" |
| 183 | + |
| 184 | + The Helm chart automatically deploys the worker as a separate deployment. No additional configuration is needed beyond the main `values.yaml`. |
| 185 | + |
| 186 | +### Worker Configuration |
| 187 | + |
| 188 | +The worker uses the following sections from the `config.yml`: |
| 189 | + |
| 190 | +```yaml |
| 191 | +http: |
| 192 | + listen: :3000 # Metrics endpoint |
| 193 | +database: |
| 194 | + host: localhost |
| 195 | + port: 3306 |
| 196 | + user: root |
| 197 | + password: root |
| 198 | + database: sms |
| 199 | + timezone: UTC |
| 200 | +tasks: |
| 201 | + devices_cleanup: |
| 202 | + interval: 24h |
| 203 | + max_age: 720h # 30 days |
| 204 | + messages_cleanup: |
| 205 | + interval: 24h |
| 206 | + max_age: 720h # 30 days |
| 207 | + messages_hashing: |
| 208 | + interval: 168h # 7 days |
| 209 | +``` |
| 210 | +
|
| 211 | +### Monitoring |
| 212 | +
|
| 213 | +The worker exposes Prometheus metrics at `/metrics`: |
| 214 | + |
| 215 | +- `worker_executor_active_tasks_total`: Current running tasks count |
| 216 | +- `worker_executor_task_result_total{task, result}`: Task success/failure counts |
| 217 | +- `worker_executor_task_duration_seconds{task}`: Task execution duration histogram |
| 218 | + |
| 219 | +For production deployments, set up alerts for: |
| 220 | + |
| 221 | +- Task failures exceeding threshold (monitor `worker_executor_task_result_total{result="error"}`) |
| 222 | +- Tasks running longer than expected (monitor `worker_executor_task_duration_seconds`) |
| 223 | +- Worker process downtime (monitor process uptime) |
| 224 | + |
| 225 | +### Operational Best Practices |
| 226 | + |
| 227 | +- **Task Configuration**: Adjust intervals based on your data volume and retention requirements |
| 228 | +- **Batch Processing**: For high-volume systems, consider shorter intervals with smaller batch sizes |
| 229 | +- **Zero-Downtime Updates**: Worker can be restarted independently of the main server |
| 230 | +- **Lock Management**: The worker uses MySQL named locks (e.g., `worker:devices:cleanup`) to coordinate execution |
0 commit comments