From 6c02c447770670963603a9ceac2d1e010d10c1d6 Mon Sep 17 00:00:00 2001 From: Guilherme Afonso Date: Wed, 10 Apr 2024 21:09:56 -0300 Subject: [PATCH] ci: update config tu use user service unit --- .github/workflows/node.js.yml | 33 ++++++++++++++++++++++++++------- marquinhos-bot.service | 17 +++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 marquinhos-bot.service diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b0d5781..503f876 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -8,11 +8,11 @@ on: jobs: build: - runs-on: [self-hosted, Linux, X64] + runs-on: [self-hosted, Linux, X64, marquinhos-ci] strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} @@ -24,9 +24,28 @@ jobs: - run: npm run build deploy: needs: build - runs-on: [self-hosted, Linux, X64] + runs-on: [self-hosted, Linux, X64, marquinhos-ci] steps: - - name: Make deploy.sh executable - run: chmod +x ./deploy.sh - - name: Execute deploy.sh - run: echo "${{ secrets.DVNS_CLUSTER_PASSWORD }}" | sudo -S ./deploy.sh "$(pwd)/dist" + - name: Check if service exists + run: systemctl --user list-units --type=service --all | grep -q 'marquinhos-bot.service' + continue-on-error: true + id: check-service + - name: Stop service + if: steps.check-service.outputs.returncode == 0 + run: systemctl --machine=marquinhos@localhost --user stop marquinhos-bot.service + - name: Copy service file + run: cp marquinhos-bot.service ~/.config/systemd/user/marquinhos-bot.service + - name: Reload systemd + run: systemctl --machine=marquinhos@localhost --user daemon-reload + - name: Start service + run: systemctl --machine=marquinhos@localhost --user start marquinhos-bot.service + - name: Check status + id: check-status + run: + if [ "$(systemctl --machine=marquinhos@localhost --user is-active marquinhos-bot.service)" != "active" ]; then + echo "Service is not running or has failed" + exit 1 + fi + - name: Fail if service is not running + if: steps.check-status.outcome != 'success' + run: exit 1 diff --git a/marquinhos-bot.service b/marquinhos-bot.service new file mode 100644 index 0000000..35250fa --- /dev/null +++ b/marquinhos-bot.service @@ -0,0 +1,17 @@ +[Unit] +Description=MarquinhosBOT +After=network.target + +[Service] +EnvironmentFile=/etc/marquinhos/marquinhos.conf +Environment="NODE_ENV=production" +User=marquinhos +WorkingDirectory=$DESTINATION_DIR +ExecStart=node -r tsconfig-paths/register ./index.js +Restart=always +RestartSec=30 +StartLimitInterval=0 + + +[Install] +WantedBy=default.target \ No newline at end of file