Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ apt-get install python3-dev
## 1.3. Compile / Install

On installation "testapp1.local" and "testapp2.local" with address 127.0.0.1 will
be added to ```/etc/hosts```.
be added to ```/etc/hosts```. A startup script for your Linux init system (systemd, OpenRC,
or SysVinit) will also be automatically installed to ```/etc/systemd/system/``` or ```/etc/init.d/```.

```bash
# compile / install
Expand All @@ -61,11 +62,43 @@ make install

## 1.4. Start Server

Raise ulimit for open files and number of kernel hugepages before starting server.
This will be put inside server startup script later.
After installation, the appropriate startup script is automatically installed for your init system.
The startup script already includes ulimit settings for open files and kernel hugepages configuration.

**Using systemd (Ubuntu 22.04+, Debian 12+):**
```bash
# start server
# enable and start service
sudo systemctl daemon-reload
sudo systemctl enable falcon-as
sudo systemctl start falcon-as

# check status
sudo systemctl status falcon-as
```

**Using OpenRC (Devuan, Gentoo, Alpine):**
```bash
# enable and start service
sudo rc-update add falcon-as default
sudo rc-service falcon-as start

# check status
sudo rc-service falcon-as status
```

**Using SysVinit (Debian ≤11, older systems):**
```bash
# enable and start service
sudo update-rc.d falcon-as defaults
sudo service falcon-as start

# check status
sudo service falcon-as status
```

**Manual start (without service):**
```bash
# start server manually
. ./scripts/ulimit.sh
. ./scripts/set-transparent-hugepages.sh
/usr/local/bin/falcon-as
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ install(CODE "execute_process(COMMAND ./scripts/cp_etc.sh)")
install(CODE "execute_process(COMMAND ./scripts/set-transparent-hugepages.sh)")
install(CODE "execute_process(COMMAND ./scripts/patch_etc_hosts.sh)")
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

# install startup script based on detected init system
install(SCRIPT ${CMAKE_SOURCE_DIR}/scripts/install_startup_script.cmake)
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ apt-get install git cmake python3-pip libboost-all-dev python3-dev nlohmann-json
# build and install
cmake .
make
make install
sudo make install

# start using systemd (automatically configured during install)
sudo systemctl daemon-reload
sudo systemctl enable falcon-as
sudo systemctl start falcon-as

# configure system
# OR start manually
. ./scripts/ulimit.sh
. ./scripts/set-transparent-hugepages.sh

# start server
/usr/local/bin/falcon-as
```

Expand Down
99 changes: 99 additions & 0 deletions scripts/install_startup_script.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Detect Linux init system and install appropriate startup script
# This script runs at install time to detect the init system and install the correct startup script

message(STATUS "========================================")
message(STATUS "Installing startup script...")
message(STATUS "========================================")

# Detect systemd
if(EXISTS "/run/systemd/system" OR EXISTS "/usr/lib/systemd/system")
set(INIT_SYSTEM "systemd")
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/systemd/falcon-as.service")
set(INIT_SCRIPT_DEST "/etc/systemd/system/falcon-as.service")
message(STATUS "Detected init system: systemd")

# 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")

Comment on lines +14 to +28
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.
else()
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")
Comment on lines +30 to +33
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.
endif()

# Check if source script exists
if(NOT EXISTS "${INIT_SCRIPT_SRC}")
message(FATAL_ERROR "Startup script not found: ${INIT_SCRIPT_SRC}")
endif()

# Install the startup script
message(STATUS "Installing ${INIT_SYSTEM} startup script...")
message(STATUS " Source: ${INIT_SCRIPT_SRC}")
message(STATUS " Destination: ${INIT_SCRIPT_DEST}")

execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${INIT_SCRIPT_SRC} ${INIT_SCRIPT_DEST}
RESULT_VARIABLE INSTALL_RESULT
ERROR_VARIABLE INSTALL_ERROR
)

if(INSTALL_RESULT EQUAL 0)
message(STATUS "✓ Startup script installed successfully")

# Make executable for init.d scripts
if(INIT_SYSTEM STREQUAL "openrc" OR INIT_SYSTEM STREQUAL "sysvinit")
execute_process(
COMMAND chmod +x ${INIT_SCRIPT_DEST}
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.
endif()
endif()

# Print instructions for the user
message(STATUS "")
message(STATUS "========================================")
if(INIT_SYSTEM STREQUAL "systemd")
message(STATUS "To enable and start the service:")
message(STATUS " sudo systemctl daemon-reload")
message(STATUS " sudo systemctl enable falcon-as")
message(STATUS " sudo systemctl start falcon-as")
message(STATUS "")
message(STATUS "To check service status:")
message(STATUS " sudo systemctl status falcon-as")
elseif(INIT_SYSTEM STREQUAL "openrc")
message(STATUS "To enable and start the service:")
message(STATUS " sudo rc-update add falcon-as default")
message(STATUS " sudo rc-service falcon-as start")
message(STATUS "")
message(STATUS "To check service status:")
message(STATUS " sudo rc-service falcon-as status")
elseif(INIT_SYSTEM STREQUAL "sysvinit")
message(STATUS "To enable and start the service:")
message(STATUS " sudo update-rc.d falcon-as defaults")
message(STATUS " sudo service falcon-as start")
message(STATUS "")
message(STATUS "To check service status:")
message(STATUS " sudo service falcon-as status")
endif()
message(STATUS "========================================")

else()
message(WARNING "Failed to install startup script: ${INSTALL_ERROR}")
message(WARNING "You may need to run 'make install' with sudo/root privileges.")
message(WARNING "Or manually copy the script:")
message(WARNING " sudo cp ${INIT_SCRIPT_SRC} ${INIT_SCRIPT_DEST}")
endif()