From fdfbdf093f227c345ca6d94b1d8870252d59ddb2 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 18 Oct 2024 20:41:08 +0200 Subject: [PATCH] Create production installation guide --- docs/SETUP_PROD.md | 79 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/docs/SETUP_PROD.md b/docs/SETUP_PROD.md index ba86d92..2be18d1 100644 --- a/docs/SETUP_PROD.md +++ b/docs/SETUP_PROD.md @@ -45,4 +45,81 @@ The OTA update is then located in `build/main.bin` * DHCP configured on the network ## Configure server -TODO \ No newline at end of file + +### Create a user dedicated to the central +```bash +sudo adduser --disabled-login central +``` + +### Install binary +You can use `scp` to copy the binary to the target server: + +```bash +scp central_backend/target/release/central_backend pierre@central:/home/pierre +``` + +Then the executable must be installed system-wide: + +```bash +sudo mv central_backend /usr/local/bin/ +``` + +### Create configuration file +Create a configuration file in `/home/central/config.yaml`: + +```bash +sudo touch /home/central/config.yaml +sudo chown central:central /home/central/config.yaml +sudo chmod 400 /home/central/config.yaml +sudo nano /home/central/config.yaml +``` + +Sample configuration: + +```conf +SECRET=RANDOM_VALUE +COOKIE_SECURE=true +LISTEN_ADDRESS=0.0.0.0:443 +ADMIN_USERNAME=admin +ADMIN_PASSWORD=FIXME +HOSTNAME=central +STORAGE=/home/central/storage +FRONIUS_ORIG=http://10.0.0.10 +``` + +### Test configuration +Run the following command to check if the configuration is working: + +```bash +sudo -u central central_backend -c /home/central/config.yaml +``` + +### Create systemd unit file +Once you confirmed the configuration is working, you can configure a system service, in `/etc/systemd/system/central.service`: + +```conf +[Unit] +Description=Central backend server +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User=central +Group=central +WorkingDirectory=/home/central +ExecStart=/usr/local/bin/central_backend -c /home/central/config.yaml +Restart=always +Environment=USER=central +HOME=/home/central + +[Install] +WantedBy=multi-user.target +``` + +Enable & start service: +```bash +sudo systemctl enable central +sudo systemctl start central +``` \ No newline at end of file