From ac888d5aa19e3d447602807382f59f39088e13f8 Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Tue, 6 Aug 2024 07:58:47 +0200 Subject: [PATCH 1/7] feat(#159): always output version & complete startup --- src/app.ts | 28 +++++++++++++++++-------- src/cli.ts | 61 ++++++++++++++++++++++++++++-------------------------- viv | 2 +- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/app.ts b/src/app.ts index e4b92a9f..b44cfdc1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -9,7 +9,7 @@ import { router as viewerRouter } from './routes/viewer.js'; import { router as openRouter } from './routes/_open.js'; import { setupSockets } from './sockets.js'; import { urlToPath } from './utils/path.js'; -import { handleArgs } from './cli.js'; +import { completeStartup, handleArgs } from './cli.js'; const app = express(); app.use(express.json()); @@ -39,11 +39,21 @@ export const { clientsAt, messageClients, openAndMessage } = setupSockets( }, ); -get(`${address}/health`, async () => { - // server is already running - await handleArgs(); - process.exit(0); -}).on('error', () => { - // server is not running so we start it - server.listen(config.port, handleArgs); -}); +const openTargetsAndCompleteStartup = handleArgs(); +if (openTargetsAndCompleteStartup) { + try { + get(`${address}/health`, async () => { + // server is already running + await openTargetsAndCompleteStartup(); + process.exit(0); + }).on('error', () => { + // server is not running so we start it + server.listen(config.port, openTargetsAndCompleteStartup); + }); + } catch (error) { + console.log(error); + completeStartup(); + } +} else { + completeStartup(); +} diff --git a/src/cli.ts b/src/cli.ts index 176fb03f..1d19e4bd 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -49,37 +49,40 @@ const openTarget = async (target: string) => { } }; -export const handleArgs = async () => { - try { - const args = process.argv.slice(2); - const positionals: string[] = []; - let parseOptions = true; +export const completeStartup = () => { + if (process.env['NODE_ENV'] !== 'development') { + // - viv executable waits for this string and then stops printing + // vivify-server's output and terminates + // - the string itself is not shown to the user + console.log('STARTUP COMPLETE'); + } +}; - for (let i = 0; i < args.length; i++) { - const arg = args[i]; - if (!(arg.startsWith('-') && parseOptions)) { - positionals.push(arg); - continue; - } - switch (arg) { - case '-v': - case '--version': - console.log(`vivify-server ${process.env.VERSION ?? 'dev'}`); - break; - case '--': - parseOptions = false; - break; - default: - console.log(`Unknown option "${arg}"`); - } +export const handleArgs = (): (() => Promise) | undefined => { + const args = process.argv.slice(2); + const positionals: string[] = []; + let parseOptions = true; + + for (let i = 0; i < args.length; i++) { + const arg = args[i]; + if (!(arg.startsWith('-') && parseOptions)) { + positionals.push(arg); + continue; } - await Promise.all(positionals.map((target) => openTarget(target))); - } finally { - if (process.env['NODE_ENV'] !== 'development') { - // - viv executable waits for this string and then stops printing - // vivify-server's output and terminates - // - the string itself is not shown to the user - console.log('STARTUP COMPLETE'); + switch (arg) { + case '-v': + case '--version': + console.log(`vivify-server ${process.env.VERSION ?? 'dev'}`); + return; + case '--': + parseOptions = false; + break; + default: + console.log(`Unknown option "${arg}"`); } } + return async () => { + await Promise.all(positionals.map((target) => openTarget(target))); + completeStartup(); + }; }; diff --git a/viv b/viv index 2730aec7..05a6a44d 100755 --- a/viv +++ b/viv @@ -12,7 +12,7 @@ arguments: source file options: --help show this help message and exit - --version show version information + --version show version information and exit EOF } From 59c5b165fa049c94e258ecccedff9e0d84affacf Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Fri, 9 Aug 2024 23:30:45 +0200 Subject: [PATCH 2/7] docs(#159): update bug report template --- .github/ISSUE_TEMPLATE/bug-report.md | 36 +++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index f618cc38..7a907ae2 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -7,25 +7,39 @@ assignees: '' --- -### Describe the bug +[//]: # (Hello and thank you for taking the time to submit a bug report! ) -A clear and concise description of what the bug is. +[//]: # (To make sure we can resolve this as quickly as possible, please ) +[//]: # (carefully fill out the information requested on this template. ) + +[//]: # (Hint: Lines that look like these are Markdown comments and won't be ) +[//]: # ( visible on the issue after you submit it so you don't need to ) +[//]: # ( delete them. ) + +### Description + +[//]: # (A clear and concise description of what the bug is and what you ) +[//]: # (expected to happen instead. Feel free to include additional material ) +[//]: # (such as screenshots if they contribute to the explanation. ) ### To Reproduce -Steps to reproduce the behavior: +[//]: # (A list of steps we can follow to consistently reproduce the bug ) + +### Context -1. Use version ... -2. +[//]: # (Please fill out the following list ) -### Expected behavior +> My operating system is: -A clear and concise description of what you expected to happen. +> Running `viv --version` outputs: -### Screenshots +```txt +output goes here +``` -If applicable, add screenshots to help explain your problem. +> I installed Vivify in the following way (e.g. name of the package manager, self-compiled or development mode): -### Additional context +> This is what happens when I run `vivify-server` at the absolute installation path instead of `viv` and try to reproduce the problem: -Add any other context about the problem here. +> In the following I specify if I use any custom configuration, and if so provide it in its entirety including any additional files referenced there (e.g. CSS or JavaScript): From 898dd0f37e8a3b3c70691fd2b3ba2056a756a7bc Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Fri, 9 Aug 2024 23:32:42 +0200 Subject: [PATCH 3/7] ci(#159): ignore issue template for md linting --- .github/.markdownlint-cli2.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/.markdownlint-cli2.yaml b/.github/.markdownlint-cli2.yaml index 9a080cc5..dc0a0086 100644 --- a/.github/.markdownlint-cli2.yaml +++ b/.github/.markdownlint-cli2.yaml @@ -4,3 +4,6 @@ globs: ignores: - 'node_modules/**/*' - 'tests/**/*' + # GitHub issues don't quite abide by Markdown standards (e.g. single line + # breaks are reproduced when rendered) + - '.github/ISSUE_TEMPLATE/**/*' From 08eb5051f6556084633d9af2bb3082f395a3ce13 Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Sun, 18 Aug 2024 10:51:01 +0200 Subject: [PATCH 4/7] docs(#159): mention killall vivify-server --- .github/ISSUE_TEMPLATE/bug-report.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 7a907ae2..9bc2298f 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -32,6 +32,8 @@ assignees: '' > My operating system is: + + > Running `viv --version` outputs: ```txt @@ -40,6 +42,12 @@ output goes here > I installed Vivify in the following way (e.g. name of the package manager, self-compiled or development mode): -> This is what happens when I run `vivify-server` at the absolute installation path instead of `viv` and try to reproduce the problem: + + +> This is what happens when I kill any running instance of Vivify with `killall vivify-server` and then run `vivify-server` at the absolute installation path (e.g. at `command -v vivify-server`) instead of `viv` and try to reproduce the problem: + + > In the following I specify if I use any custom configuration, and if so provide it in its entirety including any additional files referenced there (e.g. CSS or JavaScript): + + From 05378512987ebb15ac8406cf8ffd2db36b8df6fe Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Sun, 18 Aug 2024 11:35:25 +0200 Subject: [PATCH 5/7] feat(#159): catch any type of crash --- viv | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/viv b/viv index 05a6a44d..cdc31027 100755 --- a/viv +++ b/viv @@ -28,12 +28,36 @@ cleanup() { trap cleanup EXIT nohup vivify-server $@ > "$output" 2> /dev/null & +server_pid=$! + +monitor_server() { + while true; do + # server process ended + if ! kill -0 $server_pid 2>/dev/null; then + # check if startup was completed successfully, if so we can exit + test -f "$output" || exit 0 + grep --quiet "STARTUP COMPLETE" "$output" && exit 0 + + # if not, the startup failed + echo "Fatal: vivify-server crashed. Please use the link below to submit a bug report." + echo "" + echo "https://github.com/jannis-baum/Vivify/issues/new?labels=type%3Abug&template=bug-report.md" + # kill tail from while loop below + pkill -P $$ tail + exit 1 + fi + sleep 0.3 + done +} +monitor_server & # print stdout of vivify-server until STARTUP COMPLETE is found tail -f "$output" | while read line; do - if echo "$line" | grep -q "STARTUP COMPLETE"; then + # server finished starting + if echo "$line" | grep --quiet "STARTUP COMPLETE"; then pkill -P $$ tail break fi + echo "$line" done From f918f38ba8c8cb5c50d56b2f4566e9664ab99812 Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Mon, 19 Aug 2024 09:22:51 +0200 Subject: [PATCH 6/7] feat(#159): add newline --- viv | 1 + 1 file changed, 1 insertion(+) diff --git a/viv b/viv index cdc31027..23aada38 100755 --- a/viv +++ b/viv @@ -42,6 +42,7 @@ monitor_server() { echo "Fatal: vivify-server crashed. Please use the link below to submit a bug report." echo "" echo "https://github.com/jannis-baum/Vivify/issues/new?labels=type%3Abug&template=bug-report.md" + echo "" # kill tail from while loop below pkill -P $$ tail exit 1 From fcc1b644fc545b3b365fc9a74b95e83fe02b435b Mon Sep 17 00:00:00 2001 From: Jannis Baum Date: Mon, 19 Aug 2024 09:27:36 +0200 Subject: [PATCH 7/7] docs(#159): adjust bug report note --- viv | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/viv b/viv index 23aada38..25674f2b 100755 --- a/viv +++ b/viv @@ -16,6 +16,18 @@ options: EOF } +print_bug_report() { + cat <