Skip to content

Integrate startup scripts in CMake install process with automatic init system detection#136

Merged
clauspruefer merged 3 commits intomainfrom
copilot/fix-31360ab9-9285-4bcd-92f7-c3ad2647502d
Oct 1, 2025
Merged

Integrate startup scripts in CMake install process with automatic init system detection#136
clauspruefer merged 3 commits intomainfrom
copilot/fix-31360ab9-9285-4bcd-92f7-c3ad2647502d

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 1, 2025

Overview

This PR implements automatic detection and installation of startup scripts during the CMake install process. The system now automatically detects the Linux init system type (systemd, OpenRC, or SysVinit) and installs the appropriate startup script without any user intervention.

Problem

Previously, users had to manually:

  1. Identify their init system
  2. Copy the correct startup script from scripts/startup/
  3. Make the script executable (for init.d scripts)
  4. Configure and enable the service

This manual process was error-prone and required knowledge of different init systems.

Solution

Added a CMake script (scripts/install_startup_script.cmake) that runs during make install and:

  • Automatically detects the init system by checking for characteristic directories and files:
    • SystemD: /run/systemd/system or /usr/lib/systemd/system
    • OpenRC: /etc/runlevels, /sbin/openrc-run, or /usr/sbin/openrc-run
    • SysVinit: /etc/init.d (fallback)
  • Installs the appropriate script to the correct location:
    • SystemD → /etc/systemd/system/falcon-as.service
    • OpenRC → /etc/init.d/falcon-as
    • SysVinit → /etc/init.d/falcon-as
  • Sets proper permissions (makes init.d scripts executable)
  • Displays clear instructions for enabling and starting the service

Changes

New Files

  • scripts/install_startup_script.cmake - Detection and installation logic

Modified Files

  • CMakeLists.txt - Added single line to invoke the install script
  • BUILD.md - Updated installation instructions with service management commands for all init systems
  • README.md - Updated Quick Start guide to show systemd service management

Example Output

After running sudo make install, users see:

-- ========================================
-- Installing startup script...
-- ========================================
-- Detected init system: systemd
-- Installing systemd startup script...
--   Source: .../scripts/startup/systemd/falcon-as.service
--   Destination: /etc/systemd/system/falcon-as.service
-- ✓ Startup script installed successfully
-- 
-- ========================================
-- To enable and start the service:
--   sudo systemctl daemon-reload
--   sudo systemctl enable falcon-as
--   sudo systemctl start falcon-as
-- 
-- To check service status:
--   sudo systemctl status falcon-as
-- ========================================

Supported Distributions

  • SystemD: Ubuntu 22.04+, Debian 12+, Fedora, CentOS 8+, RHEL 8+
  • OpenRC: Devuan, Gentoo, Alpine Linux
  • SysVinit: Debian ≤11, Ubuntu ≤14.04, older systems

Benefits

  • Zero Configuration: Works automatically across different Linux distributions
  • User-Friendly: Clear, system-specific instructions displayed after installation
  • Robust: Graceful fallback and helpful error messages
  • Backward Compatible: Manual startup method still works
  • Minimal Changes: Surgical modifications to existing codebase

Testing

Comprehensive testing performed:

  • Init system detection verified for all three types
  • Path resolution and file existence validated
  • Script content and binary paths verified
  • Edge cases and error handling tested
  • Integration with CMake install process confirmed

Closes #[issue-number]

Original prompt

Please, integrate all startup scripts in the CMake install process. On installation check for the relevant linux type (which startup script should be chosen).


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@clauspruefer clauspruefer changed the title [WIP] Please, integrate all startup scripts in the CMake install process. On installation check for the relevant linux type (which startup script should be chosen). [WIP] Integrate Startup Script(s) into CMake Install Process. Oct 1, 2025
@clauspruefer
Copy link
Copy Markdown
Member

  • Create CMake script to detect Linux init system (systemd, OpenRC, or SysVinit)

    • Integrate init system detection in CMakeLists.txt

    • Install appropriate startup script based on detected init system

    • Test the installation process to verify correct script is installed

    • Update documentation if needed

Original prompt

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@copilot GO!

Copilot AI and others added 2 commits October 1, 2025 10:54
Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate Startup Script(s) into CMake Install Process. Integrate startup scripts in CMake install process with automatic init system detection Oct 1, 2025
Copilot AI requested a review from clauspruefer October 1, 2025 11:00
Copy link
Copy Markdown
Member

@clauspruefer clauspruefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks goog, comprehensive tests following on v0.1.1rc.

@clauspruefer clauspruefer marked this pull request as ready for review October 1, 2025 11:03
Copilot AI review requested due to automatic review settings October 1, 2025 11:03
@clauspruefer clauspruefer merged commit 3bca726 into main Oct 1, 2025
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements automatic startup script installation during the CMake install process, detecting the Linux init system type and installing the appropriate service configuration without user intervention.

  • Automatic init system detection (systemd, OpenRC, or SysVinit) based on filesystem characteristics
  • Installation of the correct startup script to appropriate system directories with proper permissions
  • Clear post-installation instructions displayed to users for service management

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
scripts/install_startup_script.cmake New CMake script implementing init system detection and startup script installation logic
CMakeLists.txt Added invocation of the startup script installation during make install
README.md Updated Quick Start guide to include systemd service management commands
BUILD.md Enhanced installation documentation with comprehensive service management instructions for all init systems

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +14 to +28

# Detect OpenRC
elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run")
set(INIT_SYSTEM "openrc")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: OpenRC")

# Fallback to SysVinit
elseif(EXISTS "/etc/init.d")
set(INIT_SYSTEM "sysvinit")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: SysVinit")

Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The OpenRC detection logic is complex and could benefit from being split into separate conditions for better readability. Consider breaking this into multiple elseif statements or storing intermediate boolean variables.

Suggested change
# Detect OpenRC
elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run")
set(INIT_SYSTEM "openrc")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: OpenRC")
# Fallback to SysVinit
elseif(EXISTS "/etc/init.d")
set(INIT_SYSTEM "sysvinit")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: SysVinit")
# Prepare OpenRC detection variables for readability
set(OPENRC_DIR_DETECTED FALSE)
set(OPENRC_BIN_DETECTED FALSE)
if(EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels")
set(OPENRC_DIR_DETECTED TRUE)
endif()
if(EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run")
set(OPENRC_BIN_DETECTED TRUE)
endif()
# Detect OpenRC
elseif(OPENRC_DIR_DETECTED OR OPENRC_BIN_DETECTED)
set(INIT_SYSTEM "openrc")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: OpenRC")
# Fallback to SysVinit
elseif(EXISTS "/etc/init.d")
set(INIT_SYSTEM "sysvinit")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
message(STATUS "Detected init system: SysVinit")

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +33
message(WARNING "Could not detect init system. Defaulting to SysVinit.")
set(INIT_SYSTEM "sysvinit")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The fallback logic duplicates the SysVinit configuration from lines 24-26. Consider extracting this into a function or variable to avoid code duplication.

Copilot uses AI. Check for mistakes.
RESULT_VARIABLE CHMOD_RESULT
)
if(CHMOD_RESULT EQUAL 0)
message(STATUS "✓ Made script executable")
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chmod failure case is not handled. Consider adding an else clause to warn the user if the chmod operation fails, as this could prevent the service from starting properly.

Suggested change
message(STATUS "✓ Made script executable")
message(STATUS "✓ Made script executable")
else()
message(WARNING "Failed to make script executable: ${INIT_SCRIPT_DEST}")
message(WARNING "You may need to run 'chmod +x ${INIT_SCRIPT_DEST}' with sudo/root privileges.")

Copilot uses AI. Check for mistakes.
@clauspruefer clauspruefer deleted the copilot/fix-31360ab9-9285-4bcd-92f7-c3ad2647502d branch October 1, 2025 13:47
@clauspruefer clauspruefer added the installer Installer (CMakeLists.txt) label Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

installer Installer (CMakeLists.txt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants