Issue#51: Add service generator to BlendDB

Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent ea31a3cb
Pipeline #13454 passed with stage
in 1 minute and 12 seconds
......@@ -17,3 +17,4 @@
/build
/dist
/database/views
/service
......@@ -9,7 +9,8 @@
"test": "ts-node node_modules/istanbul/lib/cli.js cover -x \"**/*.spec.ts\" -e .ts _mocha",
"show-coverage": "xdg-open coverage/lcov-report/index.html",
"doc-api": "raml2html -i specs/blendb-api-v1.raml -o doc/api-v1-reference.html",
"database": "ts-node database/config.ts database"
"database": "ts-node database/config.ts database",
"service": "./scripts/service.sh"
},
"repository": {
"type": "git",
......
#! /bin/bash
#HUGE work around to make this script allways execute at his location in dir struct
basePath=$(echo $BASH_SOURCE | rev | cut -c 11- | rev)
cd $basePath/..
mkdir -p service
WORKSPACE=$(pwd)
REAL_USER=$USER
BLENDB_PORT=3001
if [[ $1 != "" ]]; then
BLENDB_PORT=$1
fi
if [[ $2 != "" ]]; then
REAL_USER=$2
fi
cd service
echo "[Unit]" > blendb.service
echo "Description=BlenDB API" >> blendb.service
echo "After=network.target" >> blendb.service
echo "" > blendb.service
echo "[Service]" >> blendb.service
echo "User=$REAL_USER" >> blendb.service
echo "WorkingDirectory=$WORKSPACE" >> blendb.service
echo "ExecStart=$WORKSPACE/service/service.sh" >> blendb.service
echo "" >> blendb.service
echo "[Install]" >> blendb.service
echo "WantedBy=multi-user.target" >> blendb.service
echo "#! /bin/bash" > service.sh
USING_NVM="false"
VERSION=$(node --version)
error=$(source $NVM_DIR/nvm.sh)
if [[ $? -eq 0 ]]; then
source $NVM_DIR/nvm.sh
echo "source $NVM_DIR/nvm.sh" >> service.sh
echo "nvm use $VERSION" >> service.sh
USING_NVM="true"
else
echo "nvm not found, using native node version"
echo ""
fi
echo "PORT=$BLENDB_PORT npm start" >> service.sh
chmod +x service.sh
echo "The service files were created with this parameters"
echo "User that runs the service: $REAL_USER"
echo "PORT: $BLENDB_PORT"
echo "Blendb home dir (WORKSPACE): $WORKSPACE"
echo "Node Version: $VERSION"
echo "Using NVM: $USING_NVM"
echo ""
echo "Node version is get using 'node --version, use nvm to change it"
echo "To set different user and port use npm run service -- <port> [<user>]"
echo "Run this commands, as root (or sudo) to finish the process and start blendb"
SYSTEMD_PATH=/etc/systemd/system/blendb.service
echo -n "rm -f $SYSTEMD_PATH && "
echo -n "ln -s $WORKSPACE/service/blendb.service $SYSTEMD_PATH && "
echo "systemctl daemon-reload && systemctl restart blendb.service"
Markdown is supported
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