From b74bd67a4a25076812e86e7989a63b9540e68b25 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Sun, 10 Mar 2024 01:41:11 -0700 Subject: [PATCH] attempt systemd deployment --- deploy.sh | 7 ++++++- html/fruitvote/start.sh | 7 ------- html/public/fruitvote/GoPage.php | 13 ++----------- systemd/fruitvote.service | 10 ++++++++++ 4 files changed, 18 insertions(+), 19 deletions(-) delete mode 100755 html/fruitvote/start.sh create mode 100644 systemd/fruitvote.service diff --git a/deploy.sh b/deploy.sh index 06e13df..322c5b9 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,10 +1,12 @@ -#!/bin/sh +#!/bin/bash set -e echo $SSH_KEY | base64 -d >> /tmp/key chmod -R 0600 /tmp/key +rsync -e "ssh -i /tmp/key -o StrictHostKeyChecking=no" -avz --delete ./systemd/ $RSYNC_DESTINATION/.config/systemd/user/ + cd dist for item in *; do echo "copying $item" @@ -20,4 +22,7 @@ done cd .. echo "finished copying to remote host..." +ssh -i /tmp/key -o StrictHostKeyChecking=no $(echo "${$RSYNC_DESTINATION%%:*}") "systemctl daemon reload --user && systemctl restart --user fruitvote" +echo "reloading fruitvote..." + rm /tmp/key diff --git a/html/fruitvote/start.sh b/html/fruitvote/start.sh deleted file mode 100755 index dd3036b..0000000 --- a/html/fruitvote/start.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -nice -n 19 /home/simponic/fruitvote/fruitvote \ - --users simponic,nginx \ - --socket-path /home/simponic/fruitvote/http.sock \ - & -# --database /home/simponic/fruitvote/db.sqlite \ diff --git a/html/public/fruitvote/GoPage.php b/html/public/fruitvote/GoPage.php index 27fc361..864c1f7 100644 --- a/html/public/fruitvote/GoPage.php +++ b/html/public/fruitvote/GoPage.php @@ -4,28 +4,19 @@ class GoPage { private $socket; private $template; - public function __construct($page, $socket = "/home/simponic/fruitvote/http.sock", $start_cmd="/home/simponic/fruitvote/start.sh", $template = "../template.html") { + public function __construct($page, $socket = "/home/simponic/fruitvote/http.sock", $template = "../template.html") { $this->page = $page; $this->socket = $socket; $this->template = $template; - // test if socket exists - if (!file_exists($socket)) { - // start the server - exec($start_cmd); - } - for ($i = 0; $i < 10; $i++) { if (file_exists($socket)) { break; } usleep(100_000); // wait 100ms } - - if (!file_exists($socket)) { - throw new Exception("Could not start server"); - } } + public function go() { $ch = curl_init(); $url = "http://localhost".$this->page; diff --git a/systemd/fruitvote.service b/systemd/fruitvote.service new file mode 100644 index 0000000..424aaf1 --- /dev/null +++ b/systemd/fruitvote.service @@ -0,0 +1,10 @@ +[Unit] +Description=fruitvote + +[Service] +Type=simple +ExecStart=/usr/bin/nice -n 19 /home/simponic/fruitvote/fruitvote --socket-path /home/simponic/fruitvote/http.sock --users nginx,simponic +Restart=always + +[Install] +WantedBy=default.target