Add systemd services and single-server deployment examples
This commit is contained in:
1 parent
c20c41b2cd
commit
57e991ea2a
10 files changed
+306
-62
No files matched your search
@@ -6,6 +6,8 @@ and resellers. The project is in early development.
|
||||
The web panel gives operators a workspace to manage hosting accounts, request
|
||||
Apache configuration previews, and follow their progress.
|
||||
See [Local development](docs/development.md) to run it.
|
||||
See [Single-server deployment](docs/deployment.md) to install it with Apache,
|
||||
MariaDB, and RabbitMQ.
|
||||
|
||||
## Planned scope
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
Listen 192.168.10.20:8080
|
||||
|
||||
<VirtualHost 192.168.10.20:8080>
|
||||
ServerName panel.example.net
|
||||
|
||||
RemoteIPHeader X-Forwarded-For
|
||||
RemoteIPInternalProxy 192.168.10.10
|
||||
|
||||
<Location />
|
||||
Require expr "%{CONN_REMOTE_ADDR} == '192.168.10.10'"
|
||||
</Location>
|
||||
|
||||
Include /etc/coulobre/panel-proxy.inc
|
||||
</VirtualHost>
|
||||
@@ -0,0 +1,18 @@
|
||||
ProxyRequests Off
|
||||
ProxyPreserveHost On
|
||||
ProxyAddHeaders Off
|
||||
RequestHeader unset X-Forwarded-Protocol
|
||||
RequestHeader unset X-Forwarded-Ssl
|
||||
RequestHeader set X-Forwarded-Proto "https"
|
||||
RequestHeader set X-Forwarded-For "expr=%{REMOTE_ADDR}"
|
||||
|
||||
ProxyPass /static/ !
|
||||
Alias /static/ /var/www/coulobre-panel-static/
|
||||
<Directory /var/www/coulobre-panel-static/>
|
||||
AllowOverride None
|
||||
Options None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
ProxyPass / "unix:/run/coulobre-panel/panel.sock|http://localhost/"
|
||||
ProxyPassReverse / http://localhost/
|
||||
@@ -0,0 +1,13 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName panel.example.net
|
||||
Redirect permanent / https://panel.example.net/
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName panel.example.net
|
||||
SSLEngine On
|
||||
SSLCertificateFile /etc/ssl/coulobre-panel/fullchain.pem
|
||||
SSLCertificateKeyFile /etc/ssl/coulobre-panel/privkey.pem
|
||||
|
||||
Include /etc/coulobre/panel-proxy.inc
|
||||
</VirtualHost>
|
||||
@@ -0,0 +1,10 @@
|
||||
DJANGO_SETTINGS_MODULE=coulobre.settings
|
||||
COULOBRE_ALLOWED_HOSTS=panel.example.net
|
||||
COULOBRE_HTTPS_PROXY=1
|
||||
COULOBRE_STATIC_ROOT=/var/www/coulobre-panel-static
|
||||
COULOBRE_SECRET_KEY=
|
||||
COULOBRE_DB_NAME=coulobre_panel
|
||||
COULOBRE_DB_USER=coulobre
|
||||
COULOBRE_DB_PASSWORD=
|
||||
COULOBRE_DB_HOST=/run/mysqld/mysqld.sock
|
||||
COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre
|
||||
@@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=Coulobre Panel Celery scheduler
|
||||
Wants=network-online.target
|
||||
After=network-online.target rabbitmq-server.service
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=coulobre-panel
|
||||
Group=coulobre-panel
|
||||
EnvironmentFile=/etc/coulobre/panel.env
|
||||
WorkingDirectory=/opt/coulobre
|
||||
StateDirectory=coulobre-panel
|
||||
StateDirectoryMode=0700
|
||||
UMask=0077
|
||||
ExecStart=/opt/coulobre/bin/celery -A coulobre beat --loglevel=INFO --schedule=/var/lib/coulobre-panel/beat-schedule --pidfile=
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
ProtectSystem=strict
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,25 @@
|
||||
[Unit]
|
||||
Description=Coulobre Panel web service
|
||||
Wants=network-online.target
|
||||
After=network-online.target mariadb.service
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=coulobre-panel
|
||||
Group=www-data
|
||||
EnvironmentFile=/etc/coulobre/panel.env
|
||||
WorkingDirectory=/opt/coulobre
|
||||
RuntimeDirectory=coulobre-panel
|
||||
RuntimeDirectoryMode=0750
|
||||
UMask=0007
|
||||
ExecStart=/opt/coulobre/bin/gunicorn --bind unix:/run/coulobre-panel/panel.sock --umask 0o007 --no-control-socket --forwarder-headers= coulobre.wsgi:application
|
||||
KillMode=mixed
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
ProtectSystem=strict
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,23 @@
|
||||
[Unit]
|
||||
Description=Coulobre Panel Celery worker
|
||||
Wants=network-online.target
|
||||
After=network-online.target mariadb.service rabbitmq-server.service
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=coulobre-panel
|
||||
Group=coulobre-panel
|
||||
EnvironmentFile=/etc/coulobre/panel.env
|
||||
WorkingDirectory=/opt/coulobre
|
||||
UMask=0077
|
||||
ExecStart=/opt/coulobre/bin/celery -A coulobre worker --loglevel=INFO --concurrency=2
|
||||
KillMode=mixed
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
ProtectSystem=strict
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,175 @@
|
||||
# Install Coulobre Panel on one server
|
||||
|
||||
This setup runs the panel, its Celery worker and scheduler, MariaDB, RabbitMQ,
|
||||
and Apache on one Ubuntu server. Use Ubuntu 24.04 or later. Apache serves the
|
||||
panel and its static files and connects to Gunicorn over a Unix socket.
|
||||
|
||||
## Install the package and configure local services
|
||||
|
||||
Run these commands from a Coulobre checkout on the server.
|
||||
|
||||
```sh
|
||||
sudo apt install apache2 mariadb-server rabbitmq-server python3-venv python3-dev \
|
||||
build-essential pkg-config default-libmysqlclient-dev
|
||||
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \
|
||||
--shell /usr/sbin/nologin coulobre-panel
|
||||
sudo python3 -m venv /opt/coulobre
|
||||
sudo /opt/coulobre/bin/pip install '.[server,mariadb]'
|
||||
|
||||
sudo install -d -m 0750 /etc/coulobre
|
||||
sudo install -d -o coulobre-panel -g coulobre-panel -m 0755 /var/www/coulobre-panel-static
|
||||
if ! sudo test -e /etc/coulobre/panel.env; then
|
||||
sudo install -m 0600 deploy/panel.env.example /etc/coulobre/panel.env
|
||||
fi
|
||||
```
|
||||
|
||||
Generate separate random values for the Django secret key, the database
|
||||
password, and the broker password. Use this command for each value.
|
||||
|
||||
```sh
|
||||
python3 -c 'import secrets; print(secrets.token_urlsafe(48))'
|
||||
```
|
||||
|
||||
Start MariaDB and RabbitMQ. In `sudo mariadb`, create the panel database and
|
||||
login. Substitute the generated database password.
|
||||
|
||||
```sh
|
||||
sudo systemctl enable --now mariadb rabbitmq-server
|
||||
```
|
||||
|
||||
```sql
|
||||
CREATE DATABASE coulobre_panel CHARACTER SET utf8mb4;
|
||||
CREATE USER 'coulobre'@'localhost' IDENTIFIED BY 'replace-with-database-password';
|
||||
GRANT ALL PRIVILEGES ON coulobre_panel.* TO 'coulobre'@'localhost';
|
||||
```
|
||||
|
||||
Create a dedicated RabbitMQ virtual host and login. Enter the generated broker
|
||||
password when prompted by `rabbitmqctl add_user`.
|
||||
|
||||
```sh
|
||||
sudo rabbitmqctl add_vhost coulobre
|
||||
sudo rabbitmqctl add_user coulobre
|
||||
sudo rabbitmqctl set_permissions -p coulobre coulobre '.*' '.*' '.*'
|
||||
```
|
||||
|
||||
Set `listeners.tcp.1 = 127.0.0.1:5672` in `/etc/rabbitmq/rabbitmq.conf` and
|
||||
restart RabbitMQ to bind its AMQP listener to loopback. Keep MariaDB and
|
||||
RabbitMQ management and cluster ports private. [RabbitMQ listener settings](https://www.rabbitmq.com/docs/networking#listeners)
|
||||
|
||||
Edit `/etc/coulobre/panel.env` with `sudoedit`. Set `COULOBRE_ALLOWED_HOSTS`
|
||||
to the hostname browsers will use, enter the Django secret and the database
|
||||
password, and place the broker password after `coulobre:` in
|
||||
`COULOBRE_BROKER_URL`. The sample connects to MariaDB through its local Unix
|
||||
socket and uses the dedicated RabbitMQ virtual host.
|
||||
|
||||
## Prepare the panel
|
||||
|
||||
Run the Django management commands as the service user with the same
|
||||
environment the systemd services will use.
|
||||
|
||||
```sh
|
||||
panel_manage() {
|
||||
sudo systemd-run --quiet --wait --pipe --collect --uid=coulobre-panel \
|
||||
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||
/opt/coulobre/bin/python -m django "$@"
|
||||
}
|
||||
|
||||
panel_manage check --deploy
|
||||
panel_manage migrate --noinput
|
||||
panel_manage collectstatic --noinput
|
||||
|
||||
sudo systemd-run --quiet --pty --collect --uid=coulobre-panel \
|
||||
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||
/opt/coulobre/bin/python -m django createsuperuser
|
||||
```
|
||||
|
||||
HTTPS proxy mode enables HSTS for the panel hostname. Django reports `W005`
|
||||
and `W021` for the optional subdomain and browser preload settings.
|
||||
|
||||
## Configure Apache and DNS
|
||||
|
||||
Install the shared Apache directives and enable the modules for your setup.
|
||||
Replace the example hostname in the chosen virtual host with the hostname
|
||||
from `COULOBRE_ALLOWED_HOSTS`.
|
||||
|
||||
```sh
|
||||
sudo install -m 0644 deploy/apache/panel-proxy.inc /etc/coulobre/panel-proxy.inc
|
||||
sudo a2enmod headers proxy proxy_http
|
||||
```
|
||||
|
||||
### Public server
|
||||
|
||||
Publish A or AAAA records for the IPv4 and IPv6 addresses that can reach the
|
||||
panel. Allow TCP ports 80 and 443 at the firewall. If the server is behind NAT,
|
||||
use the router's public address in DNS and forward those ports to Apache.
|
||||
Install the TLS virtual host, enable `mod_ssl`, and set the certificate and key
|
||||
paths for the panel hostname.
|
||||
|
||||
```sh
|
||||
sudo a2enmod ssl
|
||||
sudo install -m 0644 deploy/apache/panel-tls.conf.example \
|
||||
/etc/apache2/sites-available/coulobre-panel.conf
|
||||
```
|
||||
|
||||
### LAN only
|
||||
|
||||
Use the same TLS virtual host with a hostname that internal DNS resolves to the
|
||||
server's private address. Use a certificate that clients on the LAN trust, such
|
||||
as one issued by your internal CA. Limit access to the panel's HTTP and HTTPS
|
||||
ports to your private network. On a host with public and private web traffic,
|
||||
use the private address in the panel's virtual hosts in place of `*`.
|
||||
|
||||
### External reverse proxy
|
||||
|
||||
Point the public DNS records at the reverse proxy. Configure it to redirect
|
||||
HTTP to HTTPS, preserve the requested hostname when forwarding, and replace
|
||||
`X-Forwarded-For` with the client address. The origin example uses HTTP on a
|
||||
private network. Use a TLS connection to Apache if the upstream connection
|
||||
crosses an untrusted network.
|
||||
|
||||
```sh
|
||||
sudo a2enmod remoteip
|
||||
sudo install -m 0644 deploy/apache/panel-origin.conf.example \
|
||||
/etc/apache2/sites-available/coulobre-panel.conf
|
||||
```
|
||||
|
||||
Set `192.168.10.20` to the private listener address on the Apache host and
|
||||
`192.168.10.10` to the network peer address of your reverse proxy. Use the
|
||||
proxy address in both `RemoteIPInternalProxy` and the `CONN_REMOTE_ADDR`
|
||||
access rule. Restrict the origin port to the proxy at the firewall too. The
|
||||
rule checks the peer connection, so it still applies when Apache recognizes a
|
||||
different visitor IP from the trusted proxy.
|
||||
[Apache client IP handling](https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html)
|
||||
|
||||
Each virtual host sends its HTTPS indicator to Gunicorn itself. The TLS
|
||||
virtual host handles HTTPS at Apache, while the private origin is reserved
|
||||
for the external proxy's HTTPS traffic. Apache passes a single visitor IP
|
||||
based on the connection or a trusted proxy. [Django HTTPS proxy settings](https://docs.djangoproject.com/en/5.2/ref/settings/#secure-proxy-ssl-header)
|
||||
|
||||
The addresses for hosted sites, mail, and authoritative DNS can differ from
|
||||
the panel hostname. Configure the corresponding public DNS records for each
|
||||
service using its reachable address.
|
||||
|
||||
## Start the services
|
||||
|
||||
Install and enable the three units. The panel's socket directory is available
|
||||
to Apache workers. The scheduler stores its state in a private directory and
|
||||
there is one scheduler for the installation.
|
||||
|
||||
```sh
|
||||
sudo install -m 0644 deploy/systemd/*.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now coulobre-panel.service coulobre-worker.service coulobre-beat.service
|
||||
|
||||
sudo a2ensite coulobre-panel
|
||||
sudo apache2ctl configtest
|
||||
sudo systemctl reload apache2
|
||||
```
|
||||
|
||||
Sign in with the administrator account. Add a hosting account and request an
|
||||
Apache preview to verify that RabbitMQ, the scheduler, and the worker are
|
||||
connected. Follow their logs with `journalctl`.
|
||||
|
||||
```sh
|
||||
sudo journalctl -u coulobre-panel -u coulobre-worker -u coulobre-beat
|
||||
```
|
||||
+2
-62
@@ -595,68 +595,8 @@ The container uses its own filesystem and loopback interface.
|
||||
|
||||
## Run the installed panel behind Apache
|
||||
|
||||
Install the panel with the `server` extra to include Gunicorn. Use the
|
||||
`mariadb` extra as well when the panel database runs on MariaDB.
|
||||
|
||||
```sh
|
||||
python -m pip install '.[server,mariadb]'
|
||||
```
|
||||
|
||||
Set the panel hostname and enable HTTPS proxy mode. Use a persistent random
|
||||
`COULOBRE_SECRET_KEY` for the panel, worker, and scheduler. Create the static
|
||||
directory with write access for the user running `collectstatic` and read
|
||||
access for Apache.
|
||||
|
||||
```sh
|
||||
export DJANGO_SETTINGS_MODULE=coulobre.settings
|
||||
export COULOBRE_ALLOWED_HOSTS=panel.example.net
|
||||
export COULOBRE_HTTPS_PROXY=1
|
||||
export COULOBRE_STATIC_ROOT=/var/www/coulobre-panel-static
|
||||
python -m django check --deploy
|
||||
python -m django migrate
|
||||
python -m django collectstatic --noinput
|
||||
```
|
||||
|
||||
HTTPS proxy mode enables HSTS for the panel hostname. Django reports `W005`
|
||||
and `W021` for the optional subdomain and browser preload settings.
|
||||
|
||||
Run Gunicorn as a dedicated unprivileged user. Give that user ownership of
|
||||
`/run/coulobre-panel` with group `www-data` and mode `0750`. Run Gunicorn with
|
||||
that directory's group so Apache workers can connect to its Unix socket.
|
||||
Restrict socket access to the panel process and Apache workers, including when
|
||||
the panel shares the server with hosted sites.
|
||||
|
||||
```sh
|
||||
gunicorn --bind unix:/run/coulobre-panel/panel.sock --umask 0o007 \
|
||||
--no-control-socket --forwarder-headers '' coulobre.wsgi:application
|
||||
```
|
||||
|
||||
Enable the Apache `headers`, `proxy`, and `proxy_http` modules. Add these
|
||||
directives inside the panel's HTTPS virtual host alongside the TLS certificate
|
||||
configuration. Redirect HTTP to HTTPS in the panel's port 80 virtual host.
|
||||
Apache sets the protocol header itself. Django uses it to recognize HTTPS
|
||||
requests and verify the origin of form submissions. HTTPS proxy mode also
|
||||
marks session and CSRF cookies as secure.
|
||||
[Django HTTPS proxy settings](https://docs.djangoproject.com/en/5.2/ref/settings/#secure-proxy-ssl-header)
|
||||
|
||||
```apache
|
||||
ProxyRequests Off
|
||||
ProxyPreserveHost On
|
||||
RequestHeader unset X-Forwarded-Protocol
|
||||
RequestHeader unset X-Forwarded-Ssl
|
||||
RequestHeader set X-Forwarded-Proto "https"
|
||||
|
||||
ProxyPass /static/ !
|
||||
Alias /static/ /var/www/coulobre-panel-static/
|
||||
<Directory /var/www/coulobre-panel-static/>
|
||||
AllowOverride None
|
||||
Options None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
ProxyPass / "unix:/run/coulobre-panel/panel.sock|http://localhost/"
|
||||
ProxyPassReverse / http://localhost/
|
||||
```
|
||||
See [Single-server deployment](deployment.md) for Gunicorn, Apache, and the
|
||||
systemd services for the panel, worker, and scheduler.
|
||||
|
||||
## MariaDB
|
||||
|
||||
|
||||
Reference in new issue
Block a user