Create the Odoo systemd Service
Run Odoo as a managed Linux service with automatic startup after reboots, crash recovery, and centralized logging via journalctl.
Why use systemd?
Running Odoo directly in the terminal means it stops when you close the SSH session. systemd solves this by managing Odoo as a proper Linux service.
journalctl, available system-wideCreate the Service File
Create the systemd unit file at /etc/systemd/system/odoo.service.
sudo nano /etc/systemd/system/odoo.service
Paste the following unit configuration.
[Unit]
Description=Odoo
Documentation=https://www.odoo.com/documentation
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
User=odoo
Group=odoo
WorkingDirectory=/opt/odoo/community
Environment="PATH=/opt/odoo/venv/bin"
ExecStart=/opt/odoo/venv/bin/python3 /opt/odoo/community/odoo-bin \
-c /etc/odoo/odoo.conf
Restart=always
RestartSec=5
TimeoutStopSec=60
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetUsing the full path to the virtual environment's Python interpreter ensures Odoo always runs with the correct Python version and all installed packages, regardless of what is set in PATH.
Directive Reference
| Directive | Value | Purpose |
|---|---|---|
After=postgresql.service | — | Start Odoo only after PostgreSQL is ready |
Requires=postgresql.service | — | Stop Odoo if PostgreSQL stops |
User / Group | odoo | Run the process as the non-root odoo user |
Environment=PATH | venv bin dir | Ensure the virtual environment executables are used |
Restart=always | — | Restart automatically after any exit |
RestartSec=5 | 5 seconds | Wait 5 seconds before attempting restart |
TimeoutStopSec=60 | 60 seconds | Allow up to 60 seconds for graceful shutdown |
StandardOutput=journal | — | Send stdout to systemd journal (accessible via journalctl) |
Enable and Start the Service
Reload systemd to pick up the new unit file, then enable and start the service.
sudo systemctl daemon-reload sudo systemctl enable odoo sudo systemctl start odoo
Useful Service Commands
sudo systemctl status odoo --no-pager sudo systemctl restart odoo sudo systemctl stop odoo journalctl -u odoo -n 50 --no-pager journalctl -u odoo -f
Verification
sudo systemctl is-enabled odoo sudo systemctl status odoo --no-pager curl -I http://127.0.0.1:8069/web/login
- ✓
systemctl is-enabled odooreturnsenabled - ✓
systemctl status odooshowsactive (running) - ✓
curlto port 8069 returns HTTP 200 or 303 - ✓ Logs visible via
journalctl -u odoo
Common Issues
| Problem | Likely Cause | Resolution |
|---|---|---|
| Service fails immediately | Incorrect ExecStart path | Verify the virtual environment Python path: which python inside source venv/bin/activate |
| Permission denied | Wrong file ownership | Ensure /opt/odoo and /etc/odoo are owned by the odoo user |
| Python module missing | Wrong interpreter | Confirm ExecStart uses the venv Python, not /usr/bin/python3 |
| PostgreSQL not found | DB service not started | Run sudo systemctl start postgresql first |
Running Odoo as the root user is a significant security risk. Always use a dedicated odoo Linux user with only the minimum permissions required.