-
Notifications
You must be signed in to change notification settings - Fork 0
fix(obsidian): enable obsidian-git auto-backup on headless server #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||
| # Trigger obsidian-git's commitAndSync via CDP. | ||||||||||||||||||
| # | ||||||||||||||||||
| # The Electron renderer's setTimeout doesn't fire under headless xvfb | ||||||||||||||||||
| # (futex_wait_queue blocks the event loop pump), but CDP messages use | ||||||||||||||||||
| # IPC and bypass the stuck loop. We trigger the backup and keep the | ||||||||||||||||||
| # websocket open with ping-interval for 15s to pump the event loop | ||||||||||||||||||
| # while git operations complete through the obsidian-git plugin. | ||||||||||||||||||
|
|
||||||||||||||||||
| CDP="http://localhost:9222" | ||||||||||||||||||
|
|
||||||||||||||||||
| WS_URL=$(@curl@/bin/curl -sf "$CDP/json" | @jq@/bin/jq -r '.[0].webSocketDebuggerUrl // empty') | ||||||||||||||||||
| [ -z "$WS_URL" ] && exit 0 | ||||||||||||||||||
|
|
||||||||||||||||||
| # Send trigger, then keep stdin open for 15s so websocat stays alive. | ||||||||||||||||||
| # The --ping-interval sends websocket pings that pump the Electron | ||||||||||||||||||
| # event loop, allowing the obsidian-git promise queue to execute. | ||||||||||||||||||
| { | ||||||||||||||||||
| echo '{"id":1,"method":"Runtime.evaluate","params":{"expression":"app.plugins.plugins['"'"'obsidian-git'"'"']?.automaticsManager?.doAutoCommitAndSync()"}}' | ||||||||||||||||||
| sleep 15 | ||||||||||||||||||
| } | @websocat@/bin/websocat --ping-interval 1 "$WS_URL" >/dev/null 2>&1 || true | ||||||||||||||||||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not mask CDP/websocket failures.
Suggested patch {
echo '{"id":1,"method":"Runtime.evaluate","params":{"expression":"app.plugins.plugins['"'"'obsidian-git'"'"']?.automaticsManager?.doAutoCommitAndSync()"}}'
sleep 15
-} | `@websocat`@/bin/websocat --ping-interval 1 "$WS_URL" >/dev/null 2>&1 || true
+} | `@websocat`@/bin/websocat --ping-interval 1 "$WS_URL" >/dev/null 2>&1📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| exec @xvfbRun@/bin/xvfb-run -a -s "-screen 0 1280x1024x24" @obsidian@/bin/obsidian --no-sandbox --disable-gpu --disable-features=FontationsFontIndexer --vault @homeDir@/ghq/github.com/shunkakinoki/wiki "$@" | ||
| exec @xvfbRun@/bin/xvfb-run -a -s "-screen 0 1280x1024x24" @obsidian@/bin/obsidian --no-sandbox --disable-gpu --disable-features=FontationsFontIndexer --remote-debugging-port=9222 --vault @homeDir@/ghq/github.com/shunkakinoki/wiki "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329 | ||
|
|
||
| Describe 'home-manager/services/obsidian/obsidian-git-trigger.sh' | ||
| SCRIPT="$PWD/home-manager/services/obsidian/obsidian-git-trigger.sh" | ||
|
|
||
| Describe 'script properties' | ||
| It 'uses bash shebang' | ||
| When run bash -c "head -1 '$SCRIPT'" | ||
| The output should include '#!/usr/bin/env bash' | ||
| End | ||
|
|
||
| It 'passes bash syntax check after replacing placeholders' | ||
| When run bash -c "sed -e 's|@curl@|/usr|g' -e 's|@jq@|/usr|g' -e 's|@websocat@|/usr|g' '$SCRIPT' | bash -n" | ||
| The status should be success | ||
| End | ||
| End | ||
|
|
||
| Describe 'placeholder references' | ||
| It 'references curl via placeholder' | ||
| When run bash -c "grep '@curl@' '$SCRIPT'" | ||
| The output should include '@curl@' | ||
| End | ||
|
|
||
| It 'references jq via placeholder' | ||
| When run bash -c "grep '@jq@' '$SCRIPT'" | ||
| The output should include '@jq@' | ||
| End | ||
|
|
||
| It 'references websocat via placeholder' | ||
| When run bash -c "grep '@websocat@' '$SCRIPT'" | ||
| The output should include '@websocat@' | ||
| End | ||
| End | ||
|
|
||
| Describe 'CDP integration' | ||
| It 'connects to CDP on port 9222' | ||
| When run bash -c "grep '9222' '$SCRIPT'" | ||
| The output should include '9222' | ||
| End | ||
|
|
||
| It 'triggers doAutoCommitAndSync' | ||
| When run bash -c "grep 'doAutoCommitAndSync' '$SCRIPT'" | ||
| The output should include 'doAutoCommitAndSync' | ||
| End | ||
| End | ||
|
|
||
| End |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current
jqfilter will produce a parse error on stderr ifcurlreturns an empty array[]or if the input is empty (e.g., when the debugging port is not yet reachable). Using the optional chaining operator?and suppressing stderr for these discovery commands will make the script more robust and keep the systemd logs cleaner during service startup or downtime.