packaging: add pre-check.sh (#11135)

This commit is contained in:
Wei Zhou 2025-09-01 08:08:43 +02:00 committed by GitHub
parent 9184170b01
commit ba42d25162
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

38
scripts/installer/pre-check.sh Executable file
View File

@ -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