attempt systemd deployment
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Elizabeth Hunt 2024-03-10 01:41:11 -07:00
parent 1115512817
commit b74bd67a4a
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
4 changed files with 18 additions and 19 deletions

View File

@ -1,10 +1,12 @@
#!/bin/sh #!/bin/bash
set -e set -e
echo $SSH_KEY | base64 -d >> /tmp/key echo $SSH_KEY | base64 -d >> /tmp/key
chmod -R 0600 /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 cd dist
for item in *; do for item in *; do
echo "copying $item" echo "copying $item"
@ -20,4 +22,7 @@ done
cd .. cd ..
echo "finished copying to remote host..." 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 rm /tmp/key

View File

@ -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 \

View File

@ -4,28 +4,19 @@ class GoPage {
private $socket; private $socket;
private $template; 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->page = $page;
$this->socket = $socket; $this->socket = $socket;
$this->template = $template; $this->template = $template;
// test if socket exists
if (!file_exists($socket)) {
// start the server
exec($start_cmd);
}
for ($i = 0; $i < 10; $i++) { for ($i = 0; $i < 10; $i++) {
if (file_exists($socket)) { if (file_exists($socket)) {
break; break;
} }
usleep(100_000); // wait 100ms usleep(100_000); // wait 100ms
} }
if (!file_exists($socket)) {
throw new Exception("Could not start server");
}
} }
public function go() { public function go() {
$ch = curl_init(); $ch = curl_init();
$url = "http://localhost".$this->page; $url = "http://localhost".$this->page;

10
systemd/fruitvote.service Normal file
View File

@ -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