-changed to dendrite-polylith-multi (v.0.2.0)

-creating templated systemd unit files dendrite@.service
This commit is contained in:
Dmitrij Pastian 2020-10-20 18:58:16 +02:00
parent cca4fdb86f
commit 4394930ce8

View file

@ -22,97 +22,51 @@ print_param_options()
done done
} }
declare PARAM_TEMPLATED="yes"
#Array with all servers #Array with all servers
SERVERS=( "client-api-proxy" \ SERVERS=( "clientapi" \
"federation-api-proxy" \ "syncapi" \
"dendrite-client-api-server" \ "mediaapi" \
"dendrite-sync-api-server" \ "federationapi" \
"dendrite-media-api-server" \ "roomserver" \
"dendrite-federation-api-server" \ "federationsender" \
"dendrite-room-server" \ "appservice" \
"dendrite-federation-sender-server" \ "keyserver" \
"dendrite-appservice-server" \ "signingkeyserver" \
"dendrite-key-server" \ "eduserver" \
"dendrite-signing-key-server" \ "userapi" \
"dendrite-edu-server" \
"dendrite-user-api-server" \
) )
#Generate unit files and output into /etc/systemd/system/<unit-file-name> #Generate unit files and output into /etc/systemd/system/<unit-file-name>
function generateServiceUnit() function generateServiceUnit()
{ {
declare SERVER=$1
declare USER=$2
declare DENDRITEDIR=$3
#
# Declaration of executin lines
#
declare -A EXECS
nl=$'\n'
read -r -d '' EXECS[clientapiproxy] <<EOF
/bin/client-api-proxy \
--bind-address ":8008" \
--client-api-server-url "http://localhost:7771" \
--sync-api-server-url "http://localhost:7773" \
--media-api-server-url "http://localhost:7774" \
EOF
read -r -d '' EXECS[federationapiproxy] <<EOF
/bin/federation-api-proxy \ $nl
--bind-address ":8448" \ $nl
--federation-api-url "http://localhost:7772" \ $nl
--media-api-server-url "http://localhost:7774" \ $nl
EOF
for ENTRY in $DENDRITEDIR/bin/dendrite-*-server; do
BINARY=$(basename $ENTRY)
EXECS[$(echo "${BINARY//-}")]="$ENTRY --config=dendrite.yaml"
done
#Check if already existent #Check if already existent
CHECK=0
if [[ -f /etc/systemd/system/$SERVER.service && ( "$PARAM_FORCE" != "yes" || -z "$PARAM_FORCE" ) ]]; then if [[ -f /etc/systemd/system/dendrite@.service && ( "$PARAM_FORCE" != "yes" || -z "$PARAM_FORCE" ) ]]; then
echo "Systemd-Unit file for $SERVER already exists." echo "Systemd-Unit-Template file \"dendrite@.service\" already exists."
while [[ "$CHECK" -ne 1 ]] echo "Add \"-x|--force\" to overwrite!"
do return 0
read -p " Overwrite? (Y/N):" -n1 -r INPUT
if [[ $INPUT =~ ^[Nn]$ ]]; then
echo "Skipping...";
return 0
elif [[ $INPUT =~ ^[Yy]$ ]]; then
CHECK=1
else
echo "Invalid input, try again!"
CHECK=0
fi
done
fi fi
current="${EXECS[$(echo "${SERVER//-}")]}" cat <<-EOF > /etc/systemd/system/dendrite@.service
cat <<-EOF > /etc/systemd/system/$SERVER.service
[Unit] [Unit]
Description= $SERVER 1 Description= Dendrite PolyLit Multi - %I
# When systemd stops or restarts the app.service, the action is propagated to this unit
PartOf=polyDendrite.service PartOf=polyDendrite.service
# Start this unit after the app.service start After=network.target
After=polyDendrite.service
[Service] [Service]
User=$USER User=$USER
WorkingDirectory=$DENDRITEDIR WorkingDirectory=$DENDRITEDIR
# Pretend that the component is running Type=forking
ExecStart=/home/dendrite/server$current ExecStart=/home/dendrite/server/bin/dendrite-polylith-multi --config=dendrite.yaml %i
Restart=on-failure Restart=on-failure
[Install] [Install]
# This unit should start when app.service is starting WantedBy=multi-user.target
WantedBy=polyDendrite.service
EOF EOF
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
@ -120,60 +74,11 @@ EOF
exit 1 exit 1
fi fi
/usr/bin/systemctl daemon-reload /usr/bin/systemctl daemon-reload
echo "Enabling $SERVER.service..." echo "Enabling dendrite@.service..."
/usr/bin/systemctl enable $SERVER.service /usr/bin/systemctl enable dendrite@.service
echo "$SERVER Unit-File created..."
return 0 return 0
} }
function generateServiceWrapper()
{
if [[ -f /etc/systemd/system/polyDendrite.service && ( "$PARAM_FORCE" != "yes" || -z "$PARAM_FORCE" ) ]]; then
echo "Systemd-Unit file for Dendrite Polylith Service wrapper already exists."
CHECK=0
while [[ "$CHECK" -ne 1 ]]
do
read -p " Overwrite? (Y/N):" -n1 -r INPUT
if [[ $INPUT =~ ^[Nn]$ ]]; then
echo
echo "Skipping...";
return 0
elif [[ $INPUT =~ ^[Yy]$ ]]; then
CHECK=1
else
echo "Invalid input, try again!"
CHECK=0
fi
done
fi
read -r -d '' polyUnit <<EOF
[Unit]
Description=Dendrite Polylith Service wrapper
[Service]
# The dummy program will exit
Type=oneshot
# Execute a dummy program
ExecStart=/bin/true
# This service shall be considered active after start
RemainAfterExit=yes
[Install]
# Components of this application should be started at boot time
WantedBy=multi-user.target
EOF
echo "$polyUnit" > /etc/systemd/system/polyDendrite.service
if [[ $? -ne 0 ]]; then
echo "An error occurred. Exiting..."
exit 1
fi
/usr/bin/systemctl daemon-reload
echo "Enabling polyDendrite.service..."
/usr/bin/systemctl enable polyDendrite.service
echo "$SERVER Unit-File created..."
return 0
}
function command_help() function command_help()
{ {
echo "\ echo "\
@ -262,20 +167,22 @@ if [[ -z "${inputarray[@]}" || "${inputarray[@]}" = "" ]]; then
done done
fi fi
generateServiceUnit
if [[ "${inputarray[@]}" = "" || "${inputarray[@]}" = "all" ]]; then if [[ "${inputarray[@]}" = "" || "${inputarray[@]}" = "all" ]]; then
for part in "${SERVERS[@]}"; do for part in "${SERVERS[@]}"; do
echo "$( generateServiceUnit $part $USER $DENDRITEDIR )" /usr/bin/systemctl enable dendrite@${part}.service && /usr/bin/systemctl start dendrite@${part}.service
done done
else else
for choice in "${inputarray[@]}"; do for choice in "${inputarray[@]}"; do
echo "$( generateServiceUnit $choice $USER $DENDRITEDIR )" /usr/bin/systemctl enable dendrite@${choice}.service && /usr/bin/systemctl start dendrite@${choice}.service
done done
fi fi
generateServiceWrapper
echo "Done.." echo "Done.."
echo "You can start all Services by typing: echo "You can start all Services by typing:
systemctl start polyDendrite.service" systemctl start dendrite@*"
echo "To start single servers use the appropriate service name instead." echo "To start single servers use:
systemctl start dendrite@<servicename>
"
exit 0 exit 0