From cb08260a9313e015f3802b8589308f3ee0f7d525 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 3 Jul 2025 14:28:16 +0200 Subject: [PATCH] packaging: add pre-check.sh --- packaging/systemd/cloudstack-agent.service | 1 + .../systemd/cloudstack-management.service | 1 + packaging/systemd/cloudstack-usage.service | 1 + scripts/installer/pre-check.sh | 38 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100755 scripts/installer/pre-check.sh diff --git a/packaging/systemd/cloudstack-agent.service b/packaging/systemd/cloudstack-agent.service index 5e2e5db0b210..5b1c7cce8c7c 100644 --- a/packaging/systemd/cloudstack-agent.service +++ b/packaging/systemd/cloudstack-agent.service @@ -28,6 +28,7 @@ After=libvirtd.service [Service] Type=simple EnvironmentFile=/etc/default/cloudstack-agent +ExecStartPre=/usr/share/cloudstack-common/scripts/installer/pre-check.sh ExecStart=/usr/bin/java $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS Restart=always RestartSec=10s diff --git a/packaging/systemd/cloudstack-management.service b/packaging/systemd/cloudstack-management.service index 55780af7a5c6..ef8b608c0988 100644 --- a/packaging/systemd/cloudstack-management.service +++ b/packaging/systemd/cloudstack-management.service @@ -34,6 +34,7 @@ User=cloud EnvironmentFile=/etc/default/cloudstack-management WorkingDirectory=/var/log/cloudstack/management PIDFile=/var/run/cloudstack-management.pid +ExecStartPre=/usr/share/cloudstack-common/scripts/installer/pre-check.sh ExecStart=/usr/bin/java $JAVA_DEBUG $JAVA_OPTS -cp $CLASSPATH $BOOTSTRAP_CLASS StandardOutput=append:/var/log/cloudstack/management/management-server.out StandardError=append:/var/log/cloudstack/management/management-server.err diff --git a/packaging/systemd/cloudstack-usage.service b/packaging/systemd/cloudstack-usage.service index bf5bd2a189b9..76af47c746e7 100644 --- a/packaging/systemd/cloudstack-usage.service +++ b/packaging/systemd/cloudstack-usage.service @@ -32,6 +32,7 @@ After=network.target network-online.target mariadb.service mysqld.service mysql. Type=simple EnvironmentFile=/etc/default/cloudstack-usage Environment=JAVA_PID=$$ +ExecStartPre=/usr/share/cloudstack-common/scripts/installer/pre-check.sh ExecStart=/bin/sh -ec '/usr/bin/java -Dpid=${JAVA_PID} $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS' Restart=always RestartSec=10s diff --git a/scripts/installer/pre-check.sh b/scripts/installer/pre-check.sh new file mode 100755 index 000000000000..ce8772ed6062 --- /dev/null +++ b/scripts/installer/pre-check.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +if [ ! -f "/usr/bin/java" ];then + echo "ERROR: /usr/bin/java does not exist" + exit 1 +fi + +JAVA_MAJOR_VERSION=$(/usr/bin/java --version | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n 1 |cut -d "." -f1) + +if [ -z $JAVA_MAJOR_VERSION ];then + echo "WARNING: Cannot determine the JAVA version" + exit 0 +fi + +if [ "$JAVA_MAJOR_VERSION" != "17" ] && [ "$JAVA_MAJOR_VERSION" != "11" ];then + echo "ERROR: JAVA $JAVA_MAJOR_VERSION is not supported. Currently only JAVA 17 and JAVA 11 are supported." + exit 1 +fi + +if [ "$JAVA_MAJOR_VERSION" != "17" ];then + echo "WARNING: JAVA version is $JAVA_MAJOR_VERSION. JAVA 17 is recommended." +fi