Skip to content

Commit 3bca726

Browse files
authored
Merge pull request #136 from WEBcodeX1/copilot/fix-31360ab9-9285-4bcd-92f7-c3ad2647502d
Integrate startup scripts in CMake install process with automatic init system detection
2 parents dc7580a + c6c0e16 commit 3bca726

4 files changed

Lines changed: 146 additions & 8 deletions

File tree

BUILD.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ apt-get install python3-dev
3535
## 1.3. Compile / Install
3636

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

4041
```bash
4142
# compile / install
@@ -61,11 +62,43 @@ make install
6162

6263
## 1.4. Start Server
6364

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

68+
**Using systemd (Ubuntu 22.04+, Debian 12+):**
6769
```bash
68-
# start server
70+
# enable and start service
71+
sudo systemctl daemon-reload
72+
sudo systemctl enable falcon-as
73+
sudo systemctl start falcon-as
74+
75+
# check status
76+
sudo systemctl status falcon-as
77+
```
78+
79+
**Using OpenRC (Devuan, Gentoo, Alpine):**
80+
```bash
81+
# enable and start service
82+
sudo rc-update add falcon-as default
83+
sudo rc-service falcon-as start
84+
85+
# check status
86+
sudo rc-service falcon-as status
87+
```
88+
89+
**Using SysVinit (Debian ≤11, older systems):**
90+
```bash
91+
# enable and start service
92+
sudo update-rc.d falcon-as defaults
93+
sudo service falcon-as start
94+
95+
# check status
96+
sudo service falcon-as status
97+
```
98+
99+
**Manual start (without service):**
100+
```bash
101+
# start server manually
69102
. ./scripts/ulimit.sh
70103
. ./scripts/set-transparent-hugepages.sh
71104
/usr/local/bin/falcon-as

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ install(CODE "execute_process(COMMAND ./scripts/cp_etc.sh)")
124124
install(CODE "execute_process(COMMAND ./scripts/set-transparent-hugepages.sh)")
125125
install(CODE "execute_process(COMMAND ./scripts/patch_etc_hosts.sh)")
126126
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
127+
128+
# install startup script based on detected init system
129+
install(SCRIPT ${CMAKE_SOURCE_DIR}/scripts/install_startup_script.cmake)

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ apt-get install git cmake python3-pip libboost-all-dev python3-dev nlohmann-json
7070
# build and install
7171
cmake .
7272
make
73-
make install
73+
sudo make install
74+
75+
# start using systemd (automatically configured during install)
76+
sudo systemctl daemon-reload
77+
sudo systemctl enable falcon-as
78+
sudo systemctl start falcon-as
7479

75-
# configure system
80+
# OR start manually
7681
. ./scripts/ulimit.sh
7782
. ./scripts/set-transparent-hugepages.sh
78-
79-
# start server
8083
/usr/local/bin/falcon-as
8184
```
8285

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Detect Linux init system and install appropriate startup script
2+
# This script runs at install time to detect the init system and install the correct startup script
3+
4+
message(STATUS "========================================")
5+
message(STATUS "Installing startup script...")
6+
message(STATUS "========================================")
7+
8+
# Detect systemd
9+
if(EXISTS "/run/systemd/system" OR EXISTS "/usr/lib/systemd/system")
10+
set(INIT_SYSTEM "systemd")
11+
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/systemd/falcon-as.service")
12+
set(INIT_SCRIPT_DEST "/etc/systemd/system/falcon-as.service")
13+
message(STATUS "Detected init system: systemd")
14+
15+
# Detect OpenRC
16+
elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run")
17+
set(INIT_SYSTEM "openrc")
18+
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as")
19+
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
20+
message(STATUS "Detected init system: OpenRC")
21+
22+
# Fallback to SysVinit
23+
elseif(EXISTS "/etc/init.d")
24+
set(INIT_SYSTEM "sysvinit")
25+
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
26+
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
27+
message(STATUS "Detected init system: SysVinit")
28+
29+
else()
30+
message(WARNING "Could not detect init system. Defaulting to SysVinit.")
31+
set(INIT_SYSTEM "sysvinit")
32+
set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as")
33+
set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as")
34+
endif()
35+
36+
# Check if source script exists
37+
if(NOT EXISTS "${INIT_SCRIPT_SRC}")
38+
message(FATAL_ERROR "Startup script not found: ${INIT_SCRIPT_SRC}")
39+
endif()
40+
41+
# Install the startup script
42+
message(STATUS "Installing ${INIT_SYSTEM} startup script...")
43+
message(STATUS " Source: ${INIT_SCRIPT_SRC}")
44+
message(STATUS " Destination: ${INIT_SCRIPT_DEST}")
45+
46+
execute_process(
47+
COMMAND ${CMAKE_COMMAND} -E copy ${INIT_SCRIPT_SRC} ${INIT_SCRIPT_DEST}
48+
RESULT_VARIABLE INSTALL_RESULT
49+
ERROR_VARIABLE INSTALL_ERROR
50+
)
51+
52+
if(INSTALL_RESULT EQUAL 0)
53+
message(STATUS "✓ Startup script installed successfully")
54+
55+
# Make executable for init.d scripts
56+
if(INIT_SYSTEM STREQUAL "openrc" OR INIT_SYSTEM STREQUAL "sysvinit")
57+
execute_process(
58+
COMMAND chmod +x ${INIT_SCRIPT_DEST}
59+
RESULT_VARIABLE CHMOD_RESULT
60+
)
61+
if(CHMOD_RESULT EQUAL 0)
62+
message(STATUS "✓ Made script executable")
63+
endif()
64+
endif()
65+
66+
# Print instructions for the user
67+
message(STATUS "")
68+
message(STATUS "========================================")
69+
if(INIT_SYSTEM STREQUAL "systemd")
70+
message(STATUS "To enable and start the service:")
71+
message(STATUS " sudo systemctl daemon-reload")
72+
message(STATUS " sudo systemctl enable falcon-as")
73+
message(STATUS " sudo systemctl start falcon-as")
74+
message(STATUS "")
75+
message(STATUS "To check service status:")
76+
message(STATUS " sudo systemctl status falcon-as")
77+
elseif(INIT_SYSTEM STREQUAL "openrc")
78+
message(STATUS "To enable and start the service:")
79+
message(STATUS " sudo rc-update add falcon-as default")
80+
message(STATUS " sudo rc-service falcon-as start")
81+
message(STATUS "")
82+
message(STATUS "To check service status:")
83+
message(STATUS " sudo rc-service falcon-as status")
84+
elseif(INIT_SYSTEM STREQUAL "sysvinit")
85+
message(STATUS "To enable and start the service:")
86+
message(STATUS " sudo update-rc.d falcon-as defaults")
87+
message(STATUS " sudo service falcon-as start")
88+
message(STATUS "")
89+
message(STATUS "To check service status:")
90+
message(STATUS " sudo service falcon-as status")
91+
endif()
92+
message(STATUS "========================================")
93+
94+
else()
95+
message(WARNING "Failed to install startup script: ${INSTALL_ERROR}")
96+
message(WARNING "You may need to run 'make install' with sudo/root privileges.")
97+
message(WARNING "Or manually copy the script:")
98+
message(WARNING " sudo cp ${INIT_SCRIPT_SRC} ${INIT_SCRIPT_DEST}")
99+
endif()

0 commit comments

Comments
 (0)