Add systemd service support to installer - #59
Conversation
- Add has_systemd_support() function to detect if systemd is available - Checks for systemctl command - Verifies /run/systemd/system directory exists - Confirms PID 1 is systemd (handles Docker/GitHub Actions) - Tests communication with systemd via show-environment - Add install_systemd_service() function to create and enable service - Creates /etc/systemd/system/openplc-runtime.service - Runs daemon-reload and enables service with --now flag - Service runs start_openplc.sh as root - Update installation completion message - Shows systemctl commands when service is installed - Falls back to manual start instructions when systemd unavailable This allows native Linux installations to automatically start the runtime on boot while gracefully skipping service installation in Docker containers and GitHub Actions environments. Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Pull request overview
This PR adds systemd service support to the OpenPLC Runtime v4 installer, enabling automatic startup on boot for native Linux systems. The installer now detects systemd availability through multiple validation checks and creates a service configuration when appropriate.
Key changes:
- Added robust systemd detection with multiple fallback checks to avoid false positives in containerized environments
- Automatic service installation, enablement, and startup via systemctl
- Context-aware installation messages showing either systemd management commands or manual start instructions
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| User=root | ||
| Group=root |
There was a problem hiding this comment.
Running the OpenPLC Runtime service as root introduces unnecessary security risks. Consider creating a dedicated system user (e.g., 'openplc') with minimal required permissions and updating the service to run under that user account instead.
|
|
||
| # Create installation marker | ||
| # Create installation marker (must be done before starting the service) | ||
| touch "$OPENPLC_DIR/.installed" |
There was a problem hiding this comment.
The installation marker file is created twice with different content. Line 383 creates an empty file, then line 384 overwrites it. Remove the redundant touch command on line 383.
| touch "$OPENPLC_DIR/.installed" |
Summary
Adds automatic systemd service installation to the OpenPLC Runtime v4 installer for native Linux systems. The installer now detects if systemd is available and functional, and if so, creates and starts an
openplc-runtime.servicethat automatically starts the runtime on boot.Key changes:
has_systemd_support()function with multi-layer detection to avoid false positives in Docker/GitHub Actionsinstall_systemd_service()function that creates the service file at/etc/systemd/system/openplc-runtime.servicesystemctl enable --nowThe detection logic checks: systemctl command exists,
/run/systemd/systemdirectory exists, PID 1 is actually systemd, and systemd is reachable viasystemctl show-environment.Updates since last revision
Fixed user data persistence across reboots - User credentials were being lost after reboot because
/var/run/runtimeis a tmpfs that gets cleared. The fix:is_running_in_container()function to detect Docker/Podman environments (checks/.dockerenv, env vars,/proc/1/cgroup,/proc/1/environ)get_persistent_data_dir()function to determine where to store.envandrestapi.db/var/lib/openplc-runtimefor persistent data (survives reboot)/var/run/runtime(expected to be a mounted volume)/var/lib/openplc-runtimewhen systemd is availableReview & Testing Checklist for Human
sudo ./install.shand verify service is created, enabled, and started.envandrestapi.dbare in/var/lib/openplc-runtime/(not/var/run/runtime/)/var/run/runtime(mounted volume)Recommended Test Plan
systemctl status openplc-runtimeshows the service runningNotes
systemctl disable --now openplc-runtime && rm /etc/systemd/system/openplc-runtime.serviceand optionally remove/var/lib/openplc-runtime/Requested by: Thiago Alves (@thiagoralves)
Link to Devin run: https://app.devin.ai/sessions/ebc278ce265842bba5abf29df61e1201