Commit 70ed3b29 authored by Florian Bruggisser's avatar Florian Bruggisser
Browse files

implemented scripts for manager service

parent 2e88424d
#!/bin/bash
### This scripts starts the manager and can be used for testsing or deployment.
### The manager iteself is configured by relative pahts, so it's important that
### it runs inside the ./manager directory.
### Florian Bruggisser 18.02.2021
# Read the asolute path to the script file.
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
echo "Working Directory: $SCRIPT_PATH"
# switch to working directory
pushd "$SCRIPT_PATH/manager/"
# setup npm
npm install
# run bus manager
node busManager.js
popd
\ No newline at end of file
#!/bin/bash
### Installs the manager as a service and all its dependencies.
### Florian Bruggisser 18.02.2021
# Read the asolute path to the script file.
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
pushd "$SCRIPT_PATH"
# load configuration
source manager-service.cfg
# install prerequisites if necessary (only on Linux)
echo "installing msoquitto..."
sudo apt update
sudo apt install acl -y
# add user
echo "adding service user..."
useradd -s /usr/sbin/nologin -r -M $SERVICE_USER_NAME
# grant access
setfacl -R -m u:$SERVICE_USER_NAME:rwx "$SCRIPT_PATH"
# prepare service configuration form template
echo "installing service..."
RUN_SCRIPT_PATH="$SCRIPT_PATH/broker-run.sh"
cp "broker/$SERVICE_NAME.service.txt" "$SERVICE_NAME.service"
sed -i -e "s~%COMMAND%~$RUN_SCRIPT_PATH~g" "$SERVICE_NAME.service"
sed -i -e "s~%USER%~$SERVICE_USER_NAME~g" "$SERVICE_NAME.service"
# install as service
sudo mv $SERVICE_NAME.service "/etc/systemd/system/$SERVICE_NAME.service"
echo "enabling service..."
sudo systemctl enable $SERVICE_NAME.service
echo ""
echo ""
echo "Please start your service now:"
echo "sudo systemctl start $SERVICE_NAME.service"
echo ""
echo ""
popd
\ No newline at end of file
#!/bin/bash
### Uninstalls the manager as a service without it's dependencies.
### Florian Bruggisser 18.02.2021
# Read the asolute path to the script file.
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
pushd "$SCRIPT_PATH"
# load configuration
source manager-service.cfg
echo "stopping service..."
sudo systemctl stop $SERVICE_NAME.service
echo "disabling service..."
sudo systemctl disable $SERVICE_NAME.service
echo "cleaning up service files..."
sudo rm -f "/etc/systemd/system/$SERVICE_NAME.service"
echo "removing service user"
userdel $SERVICE_USER_NAME
echo "uninstall completed!"
popd
\ No newline at end of file
# broker service configuration
SERVICE_NAME=telemersion-manager
SERVICE_USER_NAME=telemersion_manager
\ No newline at end of file
[Unit]
Description=Bus Manager Service for telemersion-manager.
# run after network and telemersion-broker is up
Requires=network-online.target telemersion-broker.service
After=network-online.target telemersion-broker.service
[Service]
Type=simple
ExecStart=%COMMAND%
User=%USER%
[Install]
WantedBy=multi-user.target
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment