2 # Stolen from and based on Robert Cutajar
3 # https://askubuntu.com/a/421718
7 echo "Session daemon missing command" >&2
8 echo "USAGE: $0 command [args...]"
9 echo "Executes given command with args only once per XDG seat (session)."
10 echo "Keeps PID and log of the executed command."
18 PIDFILE
=~
/.cache
/xsession-daemon
/$NAME-$XDG_SEAT.pid
19 LOGFILE
=~
/.cache
/xsession-daemon
/$NAME-$XDG_SEAT.log
21 PIDDIR
="${PIDFILE%/*}"
22 LOGDIR
="${LOGFILE%/*}"
26 echo "Session daemon PIDDIR not there: $PIDDIR" >&2
32 echo "Session daemon LOGDIR not there: $LOGDIR" >&2
36 if [ -e "$PIDFILE" ] ; then
38 echo "Session daemon '$NAME' PID found: $PID"
40 if pgrep
-F "$PIDFILE" "${NAME}" >/dev
/null
; then
41 echo "Session daemon '$NAME' was already running with PID $PID" >&2
45 echo "Session daemon '$NAME' PIDFILE NOT found: $PIDFILE"
49 echo "Session daemon running $COMMAND $* > $LOGFILE 2>&1"
50 $COMMAND $
* > "$LOGFILE" 2>&1 &
55 if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev
/null
; then
56 echo -n $PID > "$PIDFILE"
57 echo "Session daemon '$NAME' started with PID $PID"
59 echo "Session daemon '$NAME' did not start or finished early. PID: $PID, ERR: $ERR" >&2