-
Notifications
You must be signed in to change notification settings - Fork 63
Add systemd service support to installer #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thiagoralves
merged 1 commit into
development
from
devin/1767164370-add-systemd-service
Dec 31, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -61,6 +61,79 @@ log_error() { | |||
| echo -e "${RED}[ERROR]${NC} $1" | ||||
| } | ||||
|
|
||||
| # Check if systemd is available and functional | ||||
| # Returns 0 if systemd is available, 1 otherwise | ||||
| has_systemd_support() { | ||||
| # Skip on MSYS2/Windows | ||||
| if is_msys2; then | ||||
| return 1 | ||||
| fi | ||||
|
|
||||
| # Check if systemctl command exists | ||||
| if ! command -v systemctl >/dev/null 2>&1; then | ||||
| return 1 | ||||
| fi | ||||
|
|
||||
| # Check if systemd is running as PID 1 | ||||
| # This handles Docker containers and GitHub Actions where systemctl may exist but systemd isn't PID 1 | ||||
| if [ ! -d "/run/systemd/system" ]; then | ||||
| return 1 | ||||
| fi | ||||
|
|
||||
| # Additional check: verify PID 1 is actually systemd | ||||
| if [ -f "/proc/1/comm" ]; then | ||||
| local pid1_name | ||||
| pid1_name=$(cat /proc/1/comm 2>/dev/null) | ||||
| if [ "$pid1_name" != "systemd" ]; then | ||||
| return 1 | ||||
| fi | ||||
| fi | ||||
|
|
||||
| # Final check: can we actually communicate with systemd? | ||||
| # Use 'if' to prevent set -e from aborting on failure | ||||
| if ! systemctl show-environment >/dev/null 2>&1; then | ||||
| return 1 | ||||
| fi | ||||
|
|
||||
| return 0 | ||||
| } | ||||
|
|
||||
| # Install systemd service for OpenPLC Runtime | ||||
| install_systemd_service() { | ||||
| local service_file="/etc/systemd/system/openplc-runtime.service" | ||||
|
|
||||
| log_info "Installing OpenPLC Runtime systemd service..." | ||||
|
|
||||
| # Create the service file | ||||
| cat > "$service_file" <<EOF | ||||
| [Unit] | ||||
| Description=OpenPLC Runtime v4 Service | ||||
| After=network.target | ||||
|
|
||||
| [Service] | ||||
| Type=simple | ||||
| Restart=always | ||||
| RestartSec=5 | ||||
| User=root | ||||
| Group=root | ||||
| WorkingDirectory=$OPENPLC_DIR | ||||
| ExecStart=$OPENPLC_DIR/start_openplc.sh | ||||
|
|
||||
| [Install] | ||||
| WantedBy=multi-user.target | ||||
| EOF | ||||
|
|
||||
| # Reload systemd daemon to recognize the new service | ||||
| systemctl daemon-reload | ||||
|
|
||||
| # Enable and start the service | ||||
| log_info "Enabling and starting OpenPLC Runtime service..." | ||||
| systemctl enable --now openplc-runtime.service | ||||
|
|
||||
| log_success "OpenPLC Runtime service installed and started" | ||||
| return 0 | ||||
| } | ||||
|
|
||||
| # Ensure we're in the project directory | ||||
| cd "$OPENPLC_DIR" | ||||
|
|
||||
|
|
@@ -305,15 +378,43 @@ setup_plugin_venvs | |||
| echo "Compiling OpenPLC..." | ||||
| if compile_plc; then | ||||
| echo "Build process completed successfully!" | ||||
| echo "OpenPLC Runtime v4 is ready to use." | ||||
| echo "" | ||||
| echo "To start the OpenPLC Runtime v4, run:" | ||||
| echo "sudo ./start_openplc.sh" | ||||
|
|
||||
| # Create installation marker | ||||
| # Create installation marker (must be done before starting the service) | ||||
| touch "$OPENPLC_DIR/.installed" | ||||
|
||||
| touch "$OPENPLC_DIR/.installed" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.