fix: preflight Linux service manager
Signed Release / release (push) Failing after 23s

This commit is contained in:
Qiufeng
2026-08-04 08:28:15 +08:00
parent 1affcd9a5e
commit 6e22b24996
2 changed files with 25 additions and 1 deletions
+11 -1
View File
@@ -64,6 +64,14 @@ detect_platform() {
fi fi
} }
validate_service_manager() {
[[ "$PLATFORM" != "linux" || "$NO_SERVICE" == "1" ]] && return 0
command -v systemctl >/dev/null 2>&1 \
|| fail 'systemd is required for a production Linux install; use --no-service only for development'
[[ -d /run/systemd/system ]] \
|| fail 'systemd is not running on this Linux host; use --no-service only for development'
}
java_major() { java_major() {
local java_bin="${1:-java}" local java_bin="${1:-java}"
"$java_bin" -version 2>&1 | awk -F'[".]' '/version/ {print $2; exit}' "$java_bin" -version 2>&1 | awk -F'[".]' '/version/ {print $2; exit}'
@@ -294,10 +302,11 @@ shell_setting() {
prepare_layout() { prepare_layout() {
if [[ "$PLATFORM" == "linux" ]]; then if [[ "$PLATFORM" == "linux" ]]; then
ERP_USER="${ERP_SERVICE_USER:-kaidi-erp}" ERP_USER="${ERP_SERVICE_USER:-kaidi-erp}"
ERP_GROUP="$ERP_USER"
[[ "$ERP_USER" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] || fail 'invalid Linux service user name' [[ "$ERP_USER" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] || fail 'invalid Linux service user name'
id "$ERP_USER" >/dev/null 2>&1 \ id "$ERP_USER" >/dev/null 2>&1 \
|| useradd --system --home-dir "$INSTALL_ROOT" --shell /usr/sbin/nologin "$ERP_USER" || useradd --system --home-dir "$INSTALL_ROOT" --shell /usr/sbin/nologin "$ERP_USER"
ERP_GROUP="$(id -gn "$ERP_USER" 2>/dev/null)" \
|| fail "unable to resolve the primary group for Linux service user: $ERP_USER"
CONFIG_ROOT="${ERP_CONFIG_ROOT:-/etc/kaidi-erp}" CONFIG_ROOT="${ERP_CONFIG_ROOT:-/etc/kaidi-erp}"
STATE_ROOT="${ERP_STATE_ROOT:-/var/lib/kaidi-erp}" STATE_ROOT="${ERP_STATE_ROOT:-/var/lib/kaidi-erp}"
LOG_ROOT="${ERP_LOG_ROOT:-/var/log/kaidi-erp}" LOG_ROOT="${ERP_LOG_ROOT:-/var/log/kaidi-erp}"
@@ -506,6 +515,7 @@ detect_lan_address() {
main() { main() {
detect_platform detect_platform
validate_service_manager
if [[ -z "$INSTALL_ROOT" ]]; then if [[ -z "$INSTALL_ROOT" ]]; then
if [[ "$PLATFORM" == "linux" ]]; then if [[ "$PLATFORM" == "linux" ]]; then
INSTALL_ROOT=/opt/kaidi-erp INSTALL_ROOT=/opt/kaidi-erp
+14
View File
@@ -456,6 +456,19 @@ test_installer_requires_explicit_gitea_url() (
[[ "$status" -ne 0 && "$output" == *'Gitea URL is required'* ]] [[ "$status" -ne 0 && "$output" == *'Gitea URL is required'* ]]
) )
test_linux_service_preflight_requires_systemd() (
local tmp output status=0
tmp="$(mktemp -d "${TMPDIR:-/tmp}/erp-systemd-test.XXXXXX")" || return 1
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/bin"
source "$PROJECT_ROOT/install.sh"
PLATFORM=linux
NO_SERVICE=0
output="$(PATH="$tmp/bin" validate_service_manager 2>&1)" || status=$?
[[ "$status" -ne 0 && "$output" == *'systemd'* ]] || return 1
NO_SERVICE=1 PATH="$tmp/bin" validate_service_manager
)
test_no_service_install_disables_online_update() ( test_no_service_install_disables_online_update() (
local tmp local tmp
tmp="$(mktemp -d "${TMPDIR:-/tmp}/erp-no-service-test.XXXXXX")" || return 1 tmp="$(mktemp -d "${TMPDIR:-/tmp}/erp-no-service-test.XXXXXX")" || return 1
@@ -506,6 +519,7 @@ run_test 'update helper rolls back an unhealthy release end to end' test_update_
run_test 'update helper rejects a concurrent process' test_update_lock_rejects_concurrent_process run_test 'update helper rejects a concurrent process' test_update_lock_rejects_concurrent_process
run_test 'installer moves database setup to the web wizard' test_installer_moves_database_setup_to_web_wizard run_test 'installer moves database setup to the web wizard' test_installer_moves_database_setup_to_web_wizard
run_test 'installer requires an explicit Gitea URL' test_installer_requires_explicit_gitea_url run_test 'installer requires an explicit Gitea URL' test_installer_requires_explicit_gitea_url
run_test 'Linux production install requires systemd' test_linux_service_preflight_requires_systemd
run_test 'no-service install disables online update' test_no_service_install_disables_online_update run_test 'no-service install disables online update' test_no_service_install_disables_online_update
run_test 'release workflow uses the scoped Gitea job token' test_release_workflow_uses_scoped_job_token run_test 'release workflow uses the scoped Gitea job token' test_release_workflow_uses_scoped_job_token
run_test 'installer starts correctly when piped to bash' test_installer_runs_when_piped_to_bash run_test 'installer starts correctly when piped to bash' test_installer_runs_when_piped_to_bash