parent
83836d13f6
commit
0f71299ebd
@ -1,12 +1,43 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
apt update && apt install openjdk-11-jdk sftp -y
|
echo "installing packages..."
|
||||||
|
yum update > /dev/null
|
||||||
|
yum -y install openssh-clients openssh-client > /dev/null
|
||||||
|
echo "done."
|
||||||
|
|
||||||
PATH="$PATH:."
|
rm -rf /root/.ssh
|
||||||
|
mkdir -p /root/.ssh
|
||||||
|
echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
|
||||||
|
echo "$SSH_PUBLIC_KEY" > /root/.ssh/id_rsa.pub
|
||||||
|
chmod 0600 /root/.ssh/*
|
||||||
|
chmod 700 /root/.ssh
|
||||||
|
ls -lsh /root/.ssh
|
||||||
|
ls -ld /root/.ssh
|
||||||
|
pwd
|
||||||
|
|
||||||
gradlew :shadowJar
|
case "$1" in
|
||||||
|
"dev")
|
||||||
|
USER=maxime
|
||||||
|
IP=92.132.18.192
|
||||||
|
DIR=server/TBasket/backend
|
||||||
|
;;
|
||||||
|
"production")
|
||||||
|
USER=palafour
|
||||||
|
IP=193.49.118.205
|
||||||
|
DIR=TBasket/backend
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
echo "first argument is missing" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "branch $1 is unable to perform delivery, authorized branches are 'dev and production' for delivery." >&2
|
||||||
|
echo "delivery step skipped"
|
||||||
|
exit 0
|
||||||
|
esac
|
||||||
|
|
||||||
mkdir -p ~/.ssh
|
./gradlew :shadowJar
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
||||||
echo "$SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
|
echo "making delivery onto '$USER@$IP:$DIR'"
|
||||||
sftp "$USER@$IP:tbasket/" <<< $'put build/libs/server-all.jar drone/deploy.sh'
|
scp -o "StrictHostKeyChecking no" "build/libs/server-all.jar" "drone/deploy.sh" "drone/start.sh" "$USER@$IP:$DIR/"
|
||||||
|
echo "chmod 700 $DIR/*; $DIR/deploy.sh" | ssh -o "StrictHostKeyChecking no" $USER@$IP
|
||||||
|
@ -1,19 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
DIR=$(readlink -e "$(dirname "$0")")
|
||||||
|
PROD_SERVER_JAR_NAME="server-prod.jar"
|
||||||
|
NEW_SERVER_JAR_NAME="server-all.jar"
|
||||||
|
|
||||||
SERVER_JAR_NAME="server-all.jar"
|
OLD_PID=$(ps -aux | tr -s " " | grep -E "\bjava -jar $PROD_SERVER_JAR_NAME\b" | cut -d " " -f2)
|
||||||
|
|
||||||
OLD_PID=$(ps -aux | grep "-jar $SERVER_JAR_NAME" | tr -s " " | cut -d " " -f2)
|
|
||||||
|
|
||||||
#if $OLD_PID is not empty but isn't a number, something went wrong
|
#if $OLD_PID is not empty but isn't a number, something went wrong
|
||||||
if [ "$OLD_PID" ] && ! grep -E -q "^[0-9]+$"; then
|
if [ "$OLD_PID" ] && ! echo "$OLD_PID" | grep -E -q "^[0-9]+$"; then
|
||||||
echo "error, unable to retrieve old server pid: $OLD_PID" >&2
|
echo "error, unable to retrieve old server pid: $OLD_PID" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$OLD_PID" ]; then
|
if [ "$OLD_PID" ]; then
|
||||||
#will cause the old server to gracefully shutdown
|
#will cause the old server to gracefully shutdown
|
||||||
echo "shutting down old server version ..."
|
echo "shutting down old server version ..."
|
||||||
kill SIGQUIT "$OLD_PID"
|
kill -s SIGQUIT "$OLD_PID"
|
||||||
wait "$OLD_PID"
|
while ! kill -s 0 "$OLD_PID"; do sleep 1; done #sleep until process ends
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm "$DIR/$PROD_SERVER_JAR_NAME"
|
||||||
|
mv "$DIR/$NEW_SERVER_JAR_NAME" "$DIR/$PROD_SERVER_JAR_NAME"
|
||||||
|
|
||||||
|
SCREEN="basket"
|
||||||
|
|
||||||
|
# create screen if not exists
|
||||||
|
if ! screen -ls | grep -q -E "\b[0-9]+\.$SCREEN\b"; then
|
||||||
|
screen -S "$SCREEN" -d -m
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
screen -d -r "$SCREEN" -X stuff $"$DIR/start.sh\n"
|
||||||
|
echo "server is started into $SCREEN screen."
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
echo "starting server"
|
||||||
|
java -jar "server-prod.jar"
|
Reference in new issue