I think what you are describing is somewhat different. From the XDG Base Directory specification:
$XDG_RUNTIME_DIR
defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, …) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700.The lifetime of the directory MUST be bound to the user being logged in. It MUST be created when the user first logs in and if the user fully logs out the directory MUST be removed. If the user logs in more than once he should get pointed to the same directory, and it is mandatory that the directory continues to exist from his first login to his last logout on the system, and not removed in between. Files in the directory MUST not survive reboot or a full logout/login cycle.
So it is expected behaviour for /run/user/0
to be cleared when the last login session for root closes, as happens when when the ssh session exits. If you are using the directory outside of a login session then all bets are off.
I suspect what you’re really after is “a way for an Ubuntu Core device to start a user login session on boot”. Together with the currently experimental user daemons feature, a snap would then be able to run code within that session (such as a display server and kiosk web browser). You’d get a predictably managed $XDG_RUNTIME_DIR
and session bus as a bonus, rather than having to work around these missing session features.