Skip to content

Production Deployment

Now that you have the app installed and tested from the command line it's time to set this up properly to run in a production environment. In this setup we will configure the PowerController app (and its web interface if configured) to run via system daemon.

Note: These instructions shoudl work for Linux (Ubuntu tested), CentOS (RaspberryPi) and macOS environments. Windows installations will be documented at a later date.

1. Create a service file

Edit a new systemd service file:

sudo nano  at /etc/systemd/system/PowerController.service

Edit the content below as appropriate for your environment.

[Unit]
Description=PowerController app
After=network.target

[Service]
ExecStart=/home/nick/scripts/PowerController/launch.sh
WorkingDirectory=/home/nick/scripts/PowerController
StandardOutput=journal
StandardError=journal
User=nick
Environment=PYTHONUNBUFFERED=1
Environment=PATH=/home/nick/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Logging and restart behavior
Restart=on-failure        # Only restart on non-zero exit code
RestartSec=10             # Wait 10 seconds before restarting

# Limit restart attempts (3 times in 60 seconds)
StartLimitIntervalSec=60
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

Key options to review:

  • ExecStart: Change the path to suit your installation.
  • WorkingDirectory: Change the path to suit your installation.
  • User: Change the username to suit your installation.
  • Environment: Change the path to suit your installation.
  • Restart=on-failure: restart if the script exits with a non-zero code.
  • RestartSec=5: wait 5 seconds before restarting.
  • StandardOutput=journal: logs go to journalctl.

2. Enable and start the service

Run each of the commands in turn to enable and start the service.

sudo systemctl daemon-reexec       # re-executes systemd in case of changes
sudo systemctl daemon-reload       # reload service files
sudo systemctl enable PowerController   # enable on boot
sudo systemctl start PowerController    # start now

3. View the logs

First view the application log to make sure it's running OK:

cd /home/nick/scripts/PowerController
tail -f logfile.log

If there are any problems, check the system logs

sudo systemctl status PowerController.service
sudo journalctl -u PowerController -f

4. View the website

If you have the web app enabled, check that you can access, ideally from another device on your local network. If you can't, make sure there are no firewall rules on the machine running that app that block access.