Created
June 30, 2017 23:22
-
-
Save bossjones/cadad5d4f036f2496e1b31f12c0f1ef2 to your computer and use it in GitHub Desktop.
Trying to make "cont-init.d/30-init-dbus" similar to "init_dbus.sh"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/execlineb -P | |
| # NOTE: cont-init.d/30-init-dbus | |
| # -*- mode: bash -*- | |
| # vi: set ft=bash: | |
| with-contenv | |
| trap -x | |
| { | |
| term | |
| { | |
| foreground | |
| { | |
| # find location of PID_FILE | |
| backtick -n PID_FILE { redirfd -w 2 /dev/null find /tmp -name 'pydbustest_pid_file*' -print } | |
| foreground { s6-echo " [sigterm-dbus-daemon] PID_FILE:${PID_FILE}" } | |
| importas PID_FILE PID_FILE | |
| backtick -n ADDRESS_FILE { redirfd -w 2 /dev/null find /tmp -name 'pydbustest_address*' -print } | |
| foreground { s6-echo " [sigterm-dbus-daemon] ADDRESS_FILE:${ADDRESS_FILE}" } | |
| importas ADDRESS_FILE ADDRESS_FILE | |
| # find PID number | |
| backtick -n PID { redirfd -w 2 /dev/null cat ${PID_FILE} } | |
| foreground { s6-echo " [sigterm-dbus-daemon] PID:${PID}" } | |
| importas PID PID | |
| # kill process | |
| foreground { | |
| kill -TERM ${PID} | |
| rm ${ADDRESS_FILE} | |
| rm ${PID_FILE} | |
| } | |
| } | |
| echo [sigterm-dbus-daemon] graceful shutdown complete | |
| } | |
| } | |
| foreground { | |
| backtick -n ADDRESS_FILE { redirfd -w 2 /dev/null s6-applyuidgid -u 1000 -g 1000 mktemp /tmp/pydbustest_address.XXXXXXXXX } | |
| importas ADDRESS_FILE ADDRESS_FILE | |
| backtick -n PID_FILE { redirfd -w 2 /dev/null s6-applyuidgid -u 1000 -g 1000 mktemp /tmp/pydbustest_pid_file.XXXXXXXXX } | |
| importas PID_FILE PID_FILE | |
| foreground { sudo chown pi:pi -R ${ADDRESS_FILE} ${PID_FILE} } | |
| foreground { s6-echo " [run] ADDRESS_FILE:${ADDRESS_FILE}" } | |
| foreground { s6-echo " [run] PID_FILE:${PID_FILE}" } | |
| } | |
| foreground { | |
| multisubstitute { | |
| importas ADDRESS_FILE ADDRESS_FILE | |
| importas PID_FILE PID_FILE | |
| } | |
| } | |
| foreground { s6-echo " [verify] ADDRESS_FILE:${ADDRESS_FILE}" } | |
| foreground { s6-echo " [verify] PID_FILE:${PID_FILE}" } | |
| redirfd -w 0 $ADDRESS_FILE | |
| redirfd -w 1 $PID_FILE | |
| s6-applyuidgid -u 1000 -g 1000 dbus-daemon --session --print-address=0 --print-pid=1 --fork |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # original script | |
| set -e | |
| # Startup dbus session | |
| ADDRESS_FILE=$(mktemp /tmp/pydbustest.XXXXXXXXX) | |
| PID_FILE=$(mktemp /tmp/pydbustest.XXXXXXXXX) | |
| dbus-daemon --session --print-address=0 --print-pid=1 --fork 0>"$ADDRESS_FILE" 1>"$PID_FILE" | |
| export DBUS_SESSION_BUS_ADDRESS=$(cat "$ADDRESS_FILE") | |
| PID=$(cat "$PID_FILE") | |
| echo "export DBUS_SESSION_BUS_ADDRESS=$(cat "$ADDRESS_FILE")" > ~pi/.exports | |
| echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS" | |
| trap 'kill -TERM $PID' EXIT | |
| rm "$ADDRESS_FILE" "$PID_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was the fix! Parallel multi-substitution is needed ... serial substitution causes problems.