From 5a9de3ea81bc26c03e43359630d8634c397492a5 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 16 Nov 2021 11:00:01 +0100 Subject: [PATCH] prepare packaging --- .../init-script/centreon-as400-sysconfig | 5 +- .../init-script/centreon-as400.service | 2 +- connector.as400.install/install.sh | 91 ++++++++----------- ...Operatingsystems-AS400-daemon.spectemplate | 23 +++-- 4 files changed, 58 insertions(+), 63 deletions(-) diff --git a/connector.as400.install/init-script/centreon-as400-sysconfig b/connector.as400.install/init-script/centreon-as400-sysconfig index eb0faee..1c52ce7 100644 --- a/connector.as400.install/init-script/centreon-as400-sysconfig +++ b/connector.as400.install/init-script/centreon-as400-sysconfig @@ -1,9 +1,8 @@ # centreon-as400 command line options -JAVA_BIN="@JAVA_BIN@" JAVA_OPTS="-Xms128M -Xmx2G -XX:MaxPermSize=128m" -CONNECTOR_OPTS="--daemon 8091" +CONNECTOR_OPTS="--port 8091" CONNECTOR_HOME=@CONNECTOR_HOME@ CONNECTOR_ETC=@CONNECTOR_ETC@ CONNECTOR_LOG=@CONNECTOR_LOG@ CONNECTOR_TMP=/tmp/ -CONNECTOR_BIN=${CONNECTOR_HOME}/bin/centreon-as400-2.0.0-jar-with-dependencies.jar +CONNECTOR_BIN=@CONNECTOR_HOME@/bin/centreon-as400-@CONNECTOR_VERSION@-jar-with-dependencies.jar diff --git a/connector.as400.install/init-script/centreon-as400.service b/connector.as400.install/init-script/centreon-as400.service index 06222f0..5120752 100644 --- a/connector.as400.install/init-script/centreon-as400.service +++ b/connector.as400.install/init-script/centreon-as400.service @@ -21,7 +21,7 @@ Description=Centreon AS400 [Service] EnvironmentFile=/etc/sysconfig/centreon-as400 -ExecStart=$JAVA_BIN $JAVA_OPTS -DCONNECTOR_HOME=$CONNECTOR_HOME -DCONNECTOR_ETC=$CONNECTOR_ETC -DCONNECTOR_LOG=$CONNECTOR_LOG -DCONNECTOR_TMP=$CONNECTOR_TMP -jar $connectorBin $CONNECTOR_OPTS +ExecStart=@JAVA_BIN@ $JAVA_OPTS -DCONNECTOR_HOME=${CONNECTOR_HOME} -DCONNECTOR_ETC=${CONNECTOR_ETC} -DCONNECTOR_LOG=${CONNECTOR_LOG} -DCONNECTOR_TMP=${CONNECTOR_TMP} -jar $CONNECTOR_BIN $CONNECTOR_OPTS Type=simple User=centreon-as400 diff --git a/connector.as400.install/install.sh b/connector.as400.install/install.sh index 8e03933..69d9a33 100755 --- a/connector.as400.install/install.sh +++ b/connector.as400.install/install.sh @@ -1,7 +1,5 @@ #!/bin/bash -cat `pwd`"/VERSION" - ################################################# ##Functions and vars for actions results printing ################################################# @@ -49,21 +47,24 @@ function echo_passed() { ################## INIT_FOLDER="init-script/" -INIT_FILE="connector-as400" +INIT_FILE="centreon-as400.service" +SYSCONFIG_FILE="centreon-as400-sysconfig" -CONNECTOR_HOME="/usr/share/centreon-connector-as400/" -CONNECTOR_LOG="/var/log/centreon-connector-as400/" -CONNECTOR_ETC="/etc/centreon-connector-as400/" +CONNECTOR_VERSION=2.0.0 +CONNECTOR_HOME="/usr/share/centreon-as400/" +CONNECTOR_LOG="/var/log/centreon-as400/" +CONNECTOR_ETC="/etc/centreon-as400/" LOG_ETC_FILE="log4j.xml" -CONNECTOR_USER="centreonConnectorAS400" -CONNECTOR_GROUP="centreonConnectorAS400" +CONNECTOR_USER="centreon-as400" +CONNECTOR_GROUP="centreon-as400" JAVA_BIN="" ETC_PASSWD="/etc/passwd" ETC_GROUP="/etc/group" -ETC_INITD="/etc/init.d/" +ETC_INITD="/etc/systemd/system/" +ETC_SYSCONFIG="/etc/sysconfig/" ###### ##INIT @@ -81,14 +82,14 @@ DONE="no" CREATE_HOME="no" temp_folder="$CONNECTOR_HOME" while [ "$DONE" = "no" ]; do - echo "Centreon CONNECTOR home Directory [$CONNECTOR_HOME]? " + echo "Centreon AS400 home Directory [$CONNECTOR_HOME]? " echo -n ">" read temp_folder if [ -z "$temp_folder" ]; then temp_folder="$CONNECTOR_HOME" fi temp_folder=`echo "$temp_folder" | sed "s/$/\//"` - + if [ -d "$temp_folder" ]; then DONE="yes" else @@ -113,14 +114,15 @@ while [ "$DONE" = "no" ]; do fi fi done +temp_folder=$(echo $temp_folder | sed "s/\/\/$/\//") CONNECTOR_HOME=${temp_folder} -echo_success "Centreon CONNECTOR home directory" "$CONNECTOR_HOME" +echo_success "Centreon AS400 home directory" "$CONNECTOR_HOME" ############################# ##Getting java home directory ############################# -JAVA_HOME="/usr/java/" +JAVA_HOME="/usr/" temp=$JAVA_HOME while [ ! -x "$temp/bin/java" ]; do echo_failure "Cannot find java binary" "FAILURE" @@ -139,22 +141,22 @@ echo_success "Java bin path :" "$JAVA_BIN" # CONNECTOR INIT SCRIPT ################### -echo "Do you want to install CONNECTOR init script [y/N]?" +echo "Do you want to install AS400 systemd script [y/N]?" echo -n ">" read response if [ -z "$response" ]; then response="N" fi while [ "$response" != "Y" ] && [ "$response" != "y" ] && [ "$response" != "N" ] && [ "$response" != "n" ]; do - echo "Do you want to install CONNECTOR init script [y/N]?" + echo "Do you want to install AS400 systemd script [y/N]?" echo -n ">" read response if [ -z "$response" ]; then - response="N" + response="N" fi done INSTALL_CONNECTOR_INIT=$response -echo_success "CONNECTOR init script :" "$ETC_INITD/$INIT_FILE" +echo_success "CONNECTOR systemd script :" "$ETC_INITD/$INIT_FILE" ######################## ## Centreon BI user and Group @@ -179,9 +181,14 @@ echo_success "Creating directories and moving binaries..." "OK" if [ ! -d "${CONNECTOR_HOME}" ]; then mkdir -p $CONNECTOR_HOME fi - -cp -R bin/ ${CONNECTOR_HOME} - +if [ ! -d "${CONNECTOR_HOME}/bin" ]; then + mkdir ${CONNECTOR_HOME}/bin +fi + +if [ -d bin/ ] ; then + cp -f bin/*.jar ${CONNECTOR_HOME}/bin/ +fi + if [ ! -d "${CONNECTOR_LOG}" ]; then mkdir -p ${CONNECTOR_LOG} fi @@ -190,7 +197,8 @@ if [ ! -d "${CONNECTOR_ETC}" ]; then fi cp etc/log4j.xml ${CONNECTOR_ETC} - +cp etc/config.properties ${CONNECTOR_ETC} + ################### ##Macro replacement ################### @@ -199,18 +207,18 @@ ETC_FILE=${CONNECTOR_ETC}${CONNECTOR_ETC_FILE} if [ "$INSTALL_CONNECTOR_INIT" = "y" ] || [ "$INSTALL_CONNECTOR_INIT" = "Y" ]; then echo_success "Copying CONNECTOR init script..." "OK" - if [ -x "$ETC_INITD/$INIT_FILE" ]; then - mv $ETC_INITD/$INIT_FILE $ETC_INITD/$INIT_FILE.bkp - fi + sed -e 's|@JAVA_BIN@|'"$JAVA_BIN"'|g' \ + $INIT_FOLDER/$INIT_FILE > $ETC_INITD/$INIT_FILE + chmod 644 $ETC_INITD/$INIT_FILE sed -e 's|@CONNECTOR_HOME@|'"$CONNECTOR_HOME"'|g' \ - -e 's|@JAVA_BIN@|'"$JAVA_BIN"'|g' \ - -e 's|@CONNECTOR_USER@|'"$CONNECTOR_USER"'|g' \ - -e 's|@CONNECTOR_ETC@|'"${CONNECTOR_ETC}"'|g' \ - -e 's|@CONNECTOR_LOG@|'"${CONNECTOR_LOG}"'|g' \ - $INIT_FOLDER/$INIT_FILE > $ETC_INITD/$INIT_FILE - chmod +x $ETC_INITD/$INIT_FILE + -e 's|@JAVA_BIN@|'"$JAVA_BIN"'|g' \ + -e 's|@CONNECTOR_USER@|'"$CONNECTOR_USER"'|g' \ + -e 's|@CONNECTOR_ETC@|'"${CONNECTOR_ETC}"'|g' \ + -e 's|@CONNECTOR_LOG@|'"${CONNECTOR_LOG}"'|g' \ + -e 's|@CONNECTOR_VERSION@|'"${CONNECTOR_VERSION}"'|g' \ + $INIT_FOLDER/$SYSCONFIG_FILE > $ETC_SYSCONFIG/centreon-as400 fi -echo_success "Deploying Centreon-Connector..." "OK" +echo_success "Deploying Centreon-AS400..." "OK" ################################################### ##Rights settings on install directory and binaries @@ -223,19 +231,7 @@ chmod -R 775 $CONNECTOR_HOME echo_success "Rights settings..." "OK" - -COMMAND=`whereis -b update-rc.d | sed -e 's|^update-rc:||'` -if [ ! -z "$COMMAND" ]; then - echo_success "Creating daemon connector" "OK" - update-rc.d connector start 20 3 5 . stop 20 0 1 6 . -fi -COMMAND=`whereis -b chkconfig | sed -e 's|^chkconfig:||'` -if [ ! -z "$COMMAND" ]; then - echo_success "Creating daemon Connector" "OK" - chkconfig --add connector - chkconfig --level 345 connector on -fi -#$ETC_INITD/$INIT_FILE restart +systemctl enable $INIT_FILE ######### # THE END @@ -245,10 +241,3 @@ echo "" $SETCOLOR_WARNING echo "Setup finished." echo "" -$SETCOLOR_FAILURE -echo "Compile and manually copy plugins to %nagios%/libexec/" -$SETCOLOR_NORMAL -echo "Use : cmake ./plugins" -echo "Use : cd ./plugins" -echo "Use : make" -echo "" \ No newline at end of file diff --git a/rpm/centreon-plugin-Operatingsystems-AS400-daemon.spectemplate b/rpm/centreon-plugin-Operatingsystems-AS400-daemon.spectemplate index 5fd77c8..9e9997d 100644 --- a/rpm/centreon-plugin-Operatingsystems-AS400-daemon.spectemplate +++ b/rpm/centreon-plugin-Operatingsystems-AS400-daemon.spectemplate @@ -8,32 +8,38 @@ Group: System Environment/Base License: Apache2 URL: http://www.centreon.com Source0: %{name}-%{version}.tar.gz -Requires: jre BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch +BuildRequires: maven +Requires: java-1.8.0-openjdk + %description Centreon Connector Server for AS400 %prep %setup -q -n %{name}-%{version} -find . \ - -type f \ - -exec %{__grep} -E '(@@CONNECTOR_HOME@@)|(@@CONNECTOR_ETC@@)|(@@CONNECTOR_LOG@@)|(@@CONNECTOR_USER@@)' {} ';' \ - -exec %{__sed} -i \ +find . \ + -type f \ + -exec %{__grep} -E '(@@CONNECTOR_HOME@@)|(@@CONNECTOR_ETC@@)|(@@CONNECTOR_LOG@@)|(@@CONNECTOR_USER@@)' {} ';' \ + -exec %{__sed} -i \ + -e 's|@@CONNECTOR_VERSION@@|'"%{version}"'|g' \ -e 's|@@CONNECTOR_HOME@@|'"%{_datadir}/centreon-as400"'|g' \ -e 's|@@CONNECTOR_ETC@@|'"/etc/centreon-as400/"'|g' \ -e 's|@@CONNECTOR_LOG@@|'"/var/log/centreon-as400/"'|g' \ -e 's|@@CONNECTOR_USER@@|'"centreon-as400"'|g' \ - -e 's|@@JAVA_BIN@@|'"/usr/bin/java"'|g' \ - {} ';' + -e 's|@@JAVA_BIN@@|'"/usr/bin/java"'|g' \ + {} ';' + +%build +mvn -f connector.as400/pom.xml clean install %install rm -rf %{buildroot} %{__install} -d %{buildroot}%{_datadir}/centreon-as400/bin -%{__cp} -p bin/centreon-as400-%{version}-jar-with-dependencies.jar $RPM_BUILD_ROOT%{_datadir}/centreon-as400/bin +%{__cp} connector.as400/target/centreon-as400-%{version}-jar-with-dependencies.jar $RPM_BUILD_ROOT%{_datadir}/centreon-as400/bin %{__cp} connector.as400.install/init-script/centreon-as400.service %{buildroot}%{_sysconfdir}/systemd/system/ @@ -65,6 +71,7 @@ chown centreon-as400:centreon-as400 /var/log/centreon-as400/ %doc %attr(-,centreon-as400,centreon-as400) %{_sysconfdir}/centreon-as400 %attr(-,centreon-as400,centreon-as400) %{_datadir}/centreon-as400 +%attr(644, root, root) %{_sysconfdir}/systemd/system/centreon-as400.service %config(noreplace) %{_sysconfdir}/sysconfig/centreon-as400 %config(noreplace) %{_sysconfdir}/centreon-as400/config.properties %config(noreplace) %{_sysconfdir}/centreon-as400/log4j.xml