Set server properties for production.

This commit is contained in:
2019-08-13 21:37:01 +02:00
parent a984aa769f
commit b3bb993867
6 changed files with 80 additions and 295 deletions

View File

@@ -0,0 +1,23 @@
pipeline {
agent any
tools {
maven 'Maven-3.5.0'
}
stages {
stage('Perform release') {
steps {
dir('minager-properties') {
git url:'https://gogs.takiguchi.ovh/Minager/minager-properties.git', branch: 'master', credentialsId: 'a6494064-8130-42fd-9d3d-e7734518c79e'
}
script {
sh '''
chmod u+x src/main/bash/do-release.bash
src/main/bash/do-release.bash
'''
}
}
}
}
}

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
function setVersion()
{
echo 'Update pom.xml file'
mvn versions:set -DnewVersion=$1
echo 'Update properties file'
sed -i -z -E "s/minager:\n version: ([0-9]+(\.[0-9]+){2}(-SNAPSHOT)?)/minager:\n version: $1/" \
minager-properties/application-prod.yml
echo 'Update Angular app version'
sed -i -E "s/appVersion: '([0-9]+(\.[0-9]+){2}(-SNAPSHOT)?)'/appVersion: $1/" \
src/main/ts/src/environments/environment.prod.ts
}
echo 'Retreive the project version...'
VERSION=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.version}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.6.0:exec)
VERSION_MAJOR=$(echo $VERSION | cut -d '-' -f 1 | cut -d '.' -f 1)
VERSION_MINOR=$(echo $VERSION | cut -d '-' -f 1 | cut -d '.' -f 2)
VERSION_PATCH=$(echo $VERSION | cut -d '-' -f 1 | cut -d '.' -f 3)
RELEASE_VERSION=$(echo $VERSION | cut -d '-' -f 1)
NEXT_VERSION=$(echo "$VERSION_MAJOR.$(($VERSION_MINOR + 1)).$VERSION_PATCH-SNAPSHOT")
echo "Project version: $VERSION"
echo "Release version: $RELEASE_VERSION"
echo "Next version: $NEXT_VERSION"
echo 'Change files to release version'
setVersion $RELEASE_VERSION
echo 'Git tag for release freezing'
git tag $RELEASE_VERSION
cd minager-properties && git tag $RELEASE_VERSION && cd ..
echo 'Change files to next version'
setVersion $NEXT_VERSION
echo 'Git commit and push'
# Minager-properties
cd minager-properties
git add application-prod.yml
git commit -m "Set version for next iteration: $NEXT_VERSION"
git push
cd ..
# Minager
git add pom.xml
git add src/main/ts/src/environments/environment.prod.ts
git commit -m "Set version for next iteration: $NEXT_VERSION"
git push

View File

@@ -1,28 +0,0 @@
#!/bin/sh
USER=minecraft
MINECRAFT_SERVER_PATH=/home/minecraft/minager/
MINECRAFT_SHELL=minager.sh
case "$1" in
'start')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL start"
;;
'stop')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL stop"
;;
'status')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL status"
;;
'restart')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL restart"
;;
*)
# If no argument, we launch the app in case of server startup
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL start &>/dev/null"
# And show the script usage
echo "Usage: /etc/init.d/minecraft {start|stop|status|restart}\n" >&2
exit 3
;;
esac
exit 0

View File

@@ -1,80 +0,0 @@
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
DESC="The Minager web app server"
NAME='minager'
MINECRAFT_HOME='/home/minecraft'
MINAGER_HOME="$MINECRAFT_HOME/minager"
DAEMON_HOME="$MINAGER_HOME/bin"
DAEMON="$DAEMON_HOME/$NAME.jar"
PIDFILE="$DAEMON_HOME/$NAME.pid"
SCRIPTNAME="$DAEMON_HOME/$0"
start()
{
# If PIDFILE exists and PID is in running processes
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
echo 'Service already running\n'
else
echo "Starting service $NAME"
cd $DAEMON_HOME
nohup 2>/dev/null java -jar $DAEMON &>/dev/null &
expr $! - 1 > $PIDFILE
echo "Service started [`cat $PIDFILE`]\n"
fi
}
stop()
{
# If PIDFILE doesn't exists or PID isn't in running processes
if [ ! -f "$PIDFILE" ] || ! kill -0 `cat "$PIDFILE"`
then
echo 'Service not running\n'
else
echo 'Stopping service...'
# Send signal to end to the process
kill -15 `cat "$PIDFILE"` && rm -f "$PIDFILE"
echo 'Service stopped\n'
fi
}
status()
{
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
echo "Service is running (${GREEN}● active${NC})\n"
else
echo "Service not running (${RED}● inactive${NC})\n"
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
sleep 5
start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}\n" >&2
exit 3
;;
esac
exit 0

View File

@@ -1,28 +0,0 @@
#!/bin/sh
USER=takiguchi
MINECRAFT_SERVER_PATH=/home/minecraft/server
MINECRAFT_SHELL=minecraft-server.sh
case "$1" in
'start')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL start"
;;
'stop')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL stop"
;;
'status')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL status"
;;
'restart')
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL restart"
;;
*)
# If no argument, we launch the app in case of server startup
sudo -H -u $USER bash -c "$MINECRAFT_SERVER_PATH/$MINECRAFT_SHELL start &>/dev/null"
# And show the script usage
echo "Usage: /etc/init.d/minecraft {start|stop|status|restart}\n" >&2
exit 3
;;
esac
exit 0

View File

@@ -1,159 +0,0 @@
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
DESC="The Minecraft server"
NAME='minecraft-server'
MINECRAFT_HOME='/home/minecraft'
DAEMON_HOME="$MINECRAFT_HOME/server"
DAEMON="$DAEMON_HOME/$NAME.jar"
PIDFILE="$DAEMON_HOME/$NAME.pid"
SCRIPTNAME="$DAEMON_HOME/$0"
JAVA_OPT='-Xms=512M -Xmx=2048M'
# ***********************************************
# Normal functions for bash commands.
# ***********************************************
start()
{
# If PIDFILE exists and PID is in running processes
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
echo 'Service already running\n'
else
echo "Starting service $NAME"
cd $DAEMON_HOME
nohup 2>/dev/null java $JAVA_OPT -jar $DAEMON &>/dev/null &
expr $! - 1 > $PIDFILE
echo "Service started [`cat $PIDFILE`]\n"
fi
}
stop()
{
# If PIDFILE doesn't exists or PID isn't in running processes
if [ ! -f "$PIDFILE" ] || ! kill -0 `cat "$PIDFILE"`
then
echo 'Service not running\n'
else
echo 'Stopping service...'
# Send signal to end to the process
kill -15 `cat "$PIDFILE"` && rm -f "$PIDFILE"
echo 'Service stopped\n'
fi
}
status()
{
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
echo "Service is running (${GREEN}● active${NC})\n"
else
echo "Service not running (${RED}● inactive${NC})\n"
fi
}
# ***********************************************
# Commands used by Minager to drive the server.
# ***********************************************
api_check_error()
{
if [ $1 != 0 ]
then
exit 1
fi
}
api_status()
{
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
echo 1 # Running
else
echo 0 # Stopped
fi
}
api_start() {
# If PIDFILE exists and PID is in running processes
if [ -f $PIDFILE ] && kill -0 `cat $PIDFILE` 2>/dev/null
then
exit 2 # STATE_UNCHANGED
else
cd $DAEMON_HOME
api_check_error $?
nohup 2>/dev/null java $JAVA_OPT -jar $DAEMON &>/dev/null &
api_check_error $?
expr $! - 1 > $PIDFILE
api_check_error $?
fi
}
api_stop()
{
# If PIDFILE doesn't exists or PID isn't in running processes
if [ ! -f "$PIDFILE" ] || ! kill -0 `cat "$PIDFILE"`
then
exit 2 # STATE_UNCHANGED
else
# Send signal to end to the process
kill -15 `cat "$PIDFILE"` && rm -f "$PIDFILE"
api_check_error $?
fi
}
api_restart()
{
# Stop if running
if [ $(api_status) = 1 ]
then
kill -15 `cat "$PIDFILE"` && rm -f "$PIDFILE"
api_check_error $?
fi
sleep 5
api_start
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
sleep 5
start
;;
'api_status')
api_status
;;
'api_start')
api_start
;;
'api_stop')
api_stop
;;
'api_restart')
api_restart
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}\n" >&2
exit 3
;;
esac
exit 0