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%/*}"
27 echo "Session daemon PIDDIR not there: $PIDDIR" >&2
34 echo "Session daemon LOGDIR not there: $LOGDIR" >&2
38 if [ -e "$PIDFILE" ] ;
40 echo "Session daemon '$NAME' PIDFILE found: $PIDFILE"
42 echo "Session daemon '$NAME' PID found: $PID"
44 echo "Session daemon '$NAME' PIDFILE NOT found: $PIDFILE"
47 if [ "$PID" ] && kill -0 "$PID" 2>/dev
/null
;
49 echo "Session daemon '$NAME' was already running with PID $PID" >&2
53 echo "Session daemon running $COMMAND $* > $LOGFILE 2>&1"
54 $COMMAND $
* > "$LOGFILE" 2>&1 &
59 if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev
/null
;
61 echo -n $PID > "$PIDFILE"
62 echo "Session daemon '$NAME' started with PID $PID"
64 echo "Session daemon '$NAME' did not start or finished early. PID: $PID, ERR: $ERR" >&2