From 846285e5b75a8857fa20b481ccd26f6ea8a6e461 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 19 May 2021 10:08:16 +0900 Subject: [PATCH 1/5] Initial Systemd services --- systemd/matrix-puppeteer-line-chrome.service | 11 +++++++++++ systemd/matrix-puppeteer-line-chrome.target | 6 ++++++ systemd/matrix-puppeteer-line.service | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 systemd/matrix-puppeteer-line-chrome.service create mode 100644 systemd/matrix-puppeteer-line-chrome.target create mode 100644 systemd/matrix-puppeteer-line.service diff --git a/systemd/matrix-puppeteer-line-chrome.service b/systemd/matrix-puppeteer-line-chrome.service new file mode 100644 index 0000000..e08b436 --- /dev/null +++ b/systemd/matrix-puppeteer-line-chrome.service @@ -0,0 +1,11 @@ +[Unit] +Description=Matrix-puppeteer-line Chrome backend +PartOf=matrix-puppeteer-line-chrome.target + +[Service] +; User=matrix +WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line/puppet +ExecStart=/bin/xvfb-run /usr/bin/node src/main.js + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/systemd/matrix-puppeteer-line-chrome.target b/systemd/matrix-puppeteer-line-chrome.target new file mode 100644 index 0000000..e5e32cc --- /dev/null +++ b/systemd/matrix-puppeteer-line-chrome.target @@ -0,0 +1,6 @@ +[Unit] +Description=Matrix puppeteer line bridge target +Requires=multi-user.target network.target +After=multi-user.target network.target +BindsTo=matrix-puppeteer-line-chrome.service +PartOf=matrix-puppeteer-line.service \ No newline at end of file diff --git a/systemd/matrix-puppeteer-line.service b/systemd/matrix-puppeteer-line.service new file mode 100644 index 0000000..d06f5ec --- /dev/null +++ b/systemd/matrix-puppeteer-line.service @@ -0,0 +1,12 @@ +[Unit] +Description=Matrix-puppeteer-line bridge +Requires=matrix-puppeteer-line-chrome.target +After=matrix-puppeteer-line-chrome.target + +[Service] +; User=matrix +WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line +ExecStart=/opt/synapse/bridges/matrix-puppeteer-line/.venv/bin/python -m matrix_puppeteer_line + +[Install] +WantedBy=multi-user.target \ No newline at end of file From 10308fdf6d26271a54cd1eff44cd9fe4d71ca222 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Sun, 13 Jun 2021 21:09:15 +0900 Subject: [PATCH 2/5] Use notify for systemd --- puppet/package.json | 1 + puppet/src/main.js | 2 ++ puppet/yarn.lock | 32 ++++++++++++++++++++ systemd/matrix-puppeteer-line-chrome.service | 2 ++ 4 files changed, 37 insertions(+) diff --git a/puppet/package.json b/puppet/package.json index 0e6270d..8de12b6 100644 --- a/puppet/package.json +++ b/puppet/package.json @@ -20,6 +20,7 @@ "dependencies": { "arg": "^4.1.3", "chrono-node": "^2.1.7", + "systemd-daemon": "^1.1.2", "puppeteer": "5.5.0" }, "devDependencies": { diff --git a/puppet/src/main.js b/puppet/src/main.js index 81f8b9d..8741701 100644 --- a/puppet/src/main.js +++ b/puppet/src/main.js @@ -15,6 +15,7 @@ // along with this program. If not, see . import process from "process" import fs from "fs" +import sd from "systemd-daemon" import arg from "arg" @@ -55,6 +56,7 @@ function stop() { api.start().then(() => { process.once("SIGINT", stop) process.once("SIGTERM", stop) + sd.notify("READY=1") }, err => { console.error("[Main] Error starting:", err) process.exit(2) diff --git a/puppet/yarn.lock b/puppet/yarn.lock index 6c7af9c..2ca2bf3 100644 --- a/puppet/yarn.lock +++ b/puppet/yarn.lock @@ -226,6 +226,13 @@ base64-js@^1.0.2: resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g== +bindings@^1.3.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== + dependencies: + file-uri-to-path "1.0.0" + bl@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.2.tgz#52b71e9088515d0606d9dd9cc7aa48dc1f98e73a" @@ -621,6 +628,11 @@ file-entry-cache@^5.0.1: dependencies: flat-cache "^2.0.1" +file-uri-to-path@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== + find-up@^2.0.0, find-up@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" @@ -952,6 +964,11 @@ ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +nan@^2.13.2: + version "2.14.2" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19" + integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -1374,6 +1391,13 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +systemd-daemon@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/systemd-daemon/-/systemd-daemon-1.1.2.tgz#63171f4353e0f96ef2d2257a5e6258cb89136cc3" + integrity sha512-1s3JH5W78WYQI6iAQdsgoz9LMO5Sj5OtanjeNopJ15iX2q6QupRvkG5SQPJIj+YN3IgUMqPbtzfWxweCVKe28g== + optionalDependencies: + unix-dgram "^2.0.2" + table@^5.2.3: version "5.4.6" resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" @@ -1450,6 +1474,14 @@ unbzip2-stream@^1.3.3: buffer "^5.2.1" through "^2.3.8" +unix-dgram@^2.0.2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/unix-dgram/-/unix-dgram-2.0.4.tgz#14d4fc21e539742b8fb027de16eccd4e5503a344" + integrity sha512-7tpK6x7ls7J7pDrrAU63h93R0dVhRbPwiRRCawR10cl+2e1VOvF3bHlVJc6WI1dl/8qk5He673QU+Ogv7bPNaw== + dependencies: + bindings "^1.3.0" + nan "^2.13.2" + uri-js@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0" diff --git a/systemd/matrix-puppeteer-line-chrome.service b/systemd/matrix-puppeteer-line-chrome.service index e08b436..1ccc647 100644 --- a/systemd/matrix-puppeteer-line-chrome.service +++ b/systemd/matrix-puppeteer-line-chrome.service @@ -4,6 +4,8 @@ PartOf=matrix-puppeteer-line-chrome.target [Service] ; User=matrix +Type=notify +NotifyAccess=all WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line/puppet ExecStart=/bin/xvfb-run /usr/bin/node src/main.js From 4172541e9b283e8b2840bfdb257cc2acbbdacd37 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Sun, 13 Jun 2021 21:35:14 +0900 Subject: [PATCH 3/5] Fix ordering and dependence --- systemd/matrix-puppeteer-line-chrome.target | 1 - systemd/matrix-puppeteer-line.service | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/systemd/matrix-puppeteer-line-chrome.target b/systemd/matrix-puppeteer-line-chrome.target index e5e32cc..98b981a 100644 --- a/systemd/matrix-puppeteer-line-chrome.target +++ b/systemd/matrix-puppeteer-line-chrome.target @@ -3,4 +3,3 @@ Description=Matrix puppeteer line bridge target Requires=multi-user.target network.target After=multi-user.target network.target BindsTo=matrix-puppeteer-line-chrome.service -PartOf=matrix-puppeteer-line.service \ No newline at end of file diff --git a/systemd/matrix-puppeteer-line.service b/systemd/matrix-puppeteer-line.service index d06f5ec..aa9fe10 100644 --- a/systemd/matrix-puppeteer-line.service +++ b/systemd/matrix-puppeteer-line.service @@ -1,6 +1,6 @@ [Unit] Description=Matrix-puppeteer-line bridge -Requires=matrix-puppeteer-line-chrome.target +BindsTo=matrix-puppeteer-line-chrome.target After=matrix-puppeteer-line-chrome.target [Service] From 3c0dd1561623dab53148566ce6d078bb2be831fd Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 14 Jun 2021 08:13:42 +0900 Subject: [PATCH 4/5] Add `RuntimeDirectory` for sockets --- systemd/matrix-puppeteer-line-chrome.service | 4 +++- systemd/matrix-puppeteer-line.service | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/systemd/matrix-puppeteer-line-chrome.service b/systemd/matrix-puppeteer-line-chrome.service index 1ccc647..179e612 100644 --- a/systemd/matrix-puppeteer-line-chrome.service +++ b/systemd/matrix-puppeteer-line-chrome.service @@ -3,11 +3,13 @@ Description=Matrix-puppeteer-line Chrome backend PartOf=matrix-puppeteer-line-chrome.target [Service] -; User=matrix +; User=matrix-line +; Group=matrix Type=notify NotifyAccess=all WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line/puppet ExecStart=/bin/xvfb-run /usr/bin/node src/main.js +RuntimeDirectory=matrix/puppeteer-line [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/systemd/matrix-puppeteer-line.service b/systemd/matrix-puppeteer-line.service index aa9fe10..ff1f259 100644 --- a/systemd/matrix-puppeteer-line.service +++ b/systemd/matrix-puppeteer-line.service @@ -4,9 +4,11 @@ BindsTo=matrix-puppeteer-line-chrome.target After=matrix-puppeteer-line-chrome.target [Service] -; User=matrix +; User=matrix-line +; Group=matrix WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line ExecStart=/opt/synapse/bridges/matrix-puppeteer-line/.venv/bin/python -m matrix_puppeteer_line +RuntimeDirectory=matrix/puppeteer-line [Install] WantedBy=multi-user.target \ No newline at end of file From d5cd9fe8b9eea38e4c4d99bfaa640bd0fdcb6f1f Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 14 Jul 2021 01:36:15 -0400 Subject: [PATCH 5/5] Tweak systemd units Changes include: * Remove target unit * Create and use config directory * Use directory directly under /opt as home * Rename suggested user/group * Restart on failure * (aside) Rename Node module name after Chrome unit --- puppet/package.json | 4 ++-- systemd/matrix-puppeteer-line-chrome.service | 19 ++++++++++------- systemd/matrix-puppeteer-line-chrome.target | 5 ----- systemd/matrix-puppeteer-line.service | 22 ++++++++++++-------- 4 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 systemd/matrix-puppeteer-line-chrome.target diff --git a/puppet/package.json b/puppet/package.json index cb73159..04c935b 100644 --- a/puppet/package.json +++ b/puppet/package.json @@ -1,7 +1,7 @@ { - "name": "matrix-puppeteer-line-puppeteer", + "name": "matrix-puppeteer-line-chrome", "version": "0.1.0", - "description": "Puppeteer module for matrix-puppeteer-line", + "description": "Chrome/Puppeteer backend for matrix-puppeteer-line", "repository": { "type": "git", "url": "git+https://src.miscworks.net/fair/matrix-puppeteer-line.git" diff --git a/systemd/matrix-puppeteer-line-chrome.service b/systemd/matrix-puppeteer-line-chrome.service index 179e612..a3b47f1 100644 --- a/systemd/matrix-puppeteer-line-chrome.service +++ b/systemd/matrix-puppeteer-line-chrome.service @@ -1,15 +1,18 @@ [Unit] -Description=Matrix-puppeteer-line Chrome backend -PartOf=matrix-puppeteer-line-chrome.target +Description=Chrome/Puppeteer backend for matrix-puppeteer-line +After=multi-user.target network.target [Service] -; User=matrix-line -; Group=matrix +; User=matrix-puppeteer-line +; Group=matrix-puppeteer-line Type=notify NotifyAccess=all -WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line/puppet -ExecStart=/bin/xvfb-run /usr/bin/node src/main.js -RuntimeDirectory=matrix/puppeteer-line +WorkingDirectory=/opt/matrix-puppeteer-line/puppet +ConfigurationDirectory=matrix-puppeteer-line +RuntimeDirectory=matrix-puppeteer-line +ExecStart=/usr/bin/xvfb-run -a yarn start --config ${CONFIGURATION_DIRECTORY}/puppet-config.json +Restart=on-failure +RestartSec=3 [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/systemd/matrix-puppeteer-line-chrome.target b/systemd/matrix-puppeteer-line-chrome.target deleted file mode 100644 index 98b981a..0000000 --- a/systemd/matrix-puppeteer-line-chrome.target +++ /dev/null @@ -1,5 +0,0 @@ -[Unit] -Description=Matrix puppeteer line bridge target -Requires=multi-user.target network.target -After=multi-user.target network.target -BindsTo=matrix-puppeteer-line-chrome.service diff --git a/systemd/matrix-puppeteer-line.service b/systemd/matrix-puppeteer-line.service index ff1f259..6b60870 100644 --- a/systemd/matrix-puppeteer-line.service +++ b/systemd/matrix-puppeteer-line.service @@ -1,14 +1,18 @@ [Unit] -Description=Matrix-puppeteer-line bridge -BindsTo=matrix-puppeteer-line-chrome.target -After=matrix-puppeteer-line-chrome.target +Description=matrix-puppeteer-line bridge +BindsTo=matrix-puppeteer-line-chrome.service +PartOf=matrix-puppeteer-line-chrome.service +After=matrix-puppeteer-line-chrome.service [Service] -; User=matrix-line -; Group=matrix -WorkingDirectory=/opt/synapse/bridges/matrix-puppeteer-line -ExecStart=/opt/synapse/bridges/matrix-puppeteer-line/.venv/bin/python -m matrix_puppeteer_line -RuntimeDirectory=matrix/puppeteer-line +; User=matrix-puppeteer-line +; Group=matrix-puppeteer-line +WorkingDirectory=/opt/matrix-puppeteer-line +ConfigurationDirectory=matrix-puppeteer-line +RuntimeDirectory=matrix-puppeteer-line +ExecStart=/opt/matrix-puppeteer-line/.venv/bin/python -m matrix_puppeteer_line -c ${CONFIGURATION_DIRECTORY}/config.yaml +Restart=on-failure +RestartSec=3 [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target