From 97b9380d215c24aaa73f247cbbefa5f306b1a51a Mon Sep 17 00:00:00 2001
From: Olivier Maury <Olivier.Maury@inrae.fr>
Date: Mon, 2 Oct 2023 07:52:36 +0200
Subject: [PATCH] =?UTF-8?q?Ajouter=20le=20script=20de=20d=C3=A9ploiement.?=
 =?UTF-8?q?=20refs=20agroclim/agrometinfo/www#1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bin/deploy.sh                                 | 76 +++++++++++++++++++
 pom.xml                                       |  4 +-
 .../system/agrometinfo-season-handler.service | 15 ++++
 3 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100755 bin/deploy.sh
 create mode 100644 src/scripts/etc/systemd/system/agrometinfo-season-handler.service

diff --git a/bin/deploy.sh b/bin/deploy.sh
new file mode 100755
index 0000000..3328911
--- /dev/null
+++ b/bin/deploy.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+set -e
+function echo_bold_green {
+	echo -e "\033[32;1m"$1"\033[0m";
+}
+function echo_bold_red {
+	echo -e "\033[31;1m"$1"\033[0m";
+}
+function usage {
+	echo "$0 -h		shows usage"
+	echo "$0 -p		deploy on pre-production"
+	echo "$0 -P		deploy on production"
+}
+while getopts ":pPh" option
+do
+	case "${option}" in
+		h)
+			usage
+			exit 0
+			;;
+		p)
+			COLOR="\033[33;1;7m"
+			PROFILE=preprod
+			SERVER=siclima-preprod
+			;;
+		P)
+			COLOR="\033[31;1;7m"
+			PROFILE=prod
+			SERVER=siclima-prod
+			;;
+		*)
+			usage
+			exit 0
+			;;
+	esac
+done
+if [ $OPTIND -eq 1 ]; then
+	echo_bold_red "No argument were passed"
+	usage
+	exit 0
+fi
+DESTDIR=/opt/agrometinfo/
+USER=agrometinfo
+echo -e "Are you sure to deploy AgroMetInfo-SEASON-handler on $COLOR$SERVER\033[0m:$COLOR$DESTDIR\033[0m ($COLOR$PROFILE\033[0m)? (y/N)"
+read -p "" -n 1 -r
+echo
+if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+        echo "Deployment is cancelled!";
+        exit 0;
+fi
+
+echo_bold_green "Check if $SERVER is available"
+if ping -c1 -w3 $SERVER >/dev/null 2>&1
+then
+	echo OK;
+else
+	echo_bold_red "ping on $SERVER did not respond, check VPN or host name or IP";
+	exit 1;
+fi
+
+echo_bold_green "Packaging..."
+mvn clean package
+NB=$(find target/. -name "agrometinfo-season-handler-*.jar" -printf '.' | wc -m)
+if [ $NB -ne 1 ]; then
+	echo_bold_red 'Strange, JAR package not found'
+	exit 1
+fi
+JAR=$(basename target/agrometinfo-season-handler-*.jar)
+FIXED_JAR=agrometinfo-season-handler.jar
+echo_bold_green "Send $JAR to $SERVER..."
+scp target/$JAR $SERVER:$DESTDIR
+echo_bold_green "Linking $JAR to $DESTDIR/$FIXED_JAR..."
+ssh $SERVER "ln -snf $DESTDIR/$JAR $DESTDIR/$FIXED_JAR"
+echo_bold_green "Restart service..."
+ssh $SERVER "sudo systemctl restart agrometinfo-season-handler"
+echo_bold_green "Deployment done."
diff --git a/pom.xml b/pom.xml
index f27ed36..6fd283e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,7 +41,7 @@
     <log4j.version>2.20.0</log4j.version>
     <lombok.version>1.18.28</lombok.version>
     <picoli.version>4.7.4</picoli.version>
-    <season.version>1.2.3-SNAPSHOT</season.version>
+    <season.version>1.2.3</season.version>
     <!-- Maven environment values -->
     <build.date>${maven.build.timestamp}</build.date>
     <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
@@ -242,7 +242,7 @@
           </execution>
         </executions>
         <configuration>
-          <finalName>${project.artifactId}-${project.version}</finalName>
+          <finalName>agrometinfo-season-handler-${project.version}</finalName>
           <transformers>
             <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
               <mainClass>${exec.mainClass}</mainClass>
diff --git a/src/scripts/etc/systemd/system/agrometinfo-season-handler.service b/src/scripts/etc/systemd/system/agrometinfo-season-handler.service
new file mode 100644
index 0000000..7e21f9d
--- /dev/null
+++ b/src/scripts/etc/systemd/system/agrometinfo-season-handler.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=SEASON handling for AgroMetInfo
+After=season.service
+
+[Service]
+Type=simple
+WorkingDirectory=/opt/agrometinfo/
+ExecStart=/usr/bin/java -jar agrometinfo-season-handler.jar --config AgroMetInfo_2.0/configurations-season/agrometinfo-season-handler.properties
+Restart=on-abort
+RestartSec=10
+User=agrometinfo
+Group=agrometinfo
+
+[Install]
+WantedBy=multi-user.target
-- 
GitLab