Autostart on login in minimal templates

28 views
Skip to first unread message

Abel Luck

unread,
Jan 11, 2020, 8:58:03 AM1/11/20
to qubes...@googlegroups.com
Hi there,

Using the fedora and debian minimal templates, how can I execute a
script on *login*? I'm aware of /rw/config/rc.local, but that runs on
system boot.

Rather, I want to run something after X11 has initialized and my user is
logged in.

Since no DE is installed, .desktop files in ~/.config/autostart are not
executed in the minimal templates

~abel

Claudia

unread,
Jan 11, 2020, 3:09:51 PM1/11/20
to Abel Luck, qubes...@googlegroups.com

Would .xinitrc work?

Systemd units with After=graphical.target and properly configured User=, Display=, Session=, Seat=, and/or whatever else might be necessary. Or maybe user-mode systemd units. https://wiki.archlinux.org/index.php/Systemd/User

Or maybe rc.local with `systemctl is-system-running --wait` before your commands - I often have to use this with qvm-run. Running from rc.local though, commands might not be running as the right user/session/seat/slice/scope/whatever, I don't know.

Abel Luck

unread,
Jan 12, 2020, 6:23:38 AM1/12/20
to Claudia, qubes...@googlegroups.com
The systemd route does seem promising. Thanks.

If I edited the template vm, I could just put my unit file in
/etc/systemd/system and it would work fine.

However I'd like to do this for a specific AppVm, so I dropped the unit
file in /usr/local/lib/systemd/system. This file persists across boots
as expected, however systemd doesn't load units from it until I
daemon-reload after boot.

I suppose this is because /usr/local is symlinked from /rw/usrlocal
sometime after systemd has loaded its units.

Is there anyway to get systemd to load units from
/usr/local/lib/systemd/system as part of appvm boot?

~abel

Claudia:

Abel Luck

unread,
Jan 12, 2020, 6:43:14 AM1/12/20
to qubes...@googlegroups.com

Abel Luck:
Oops, sorry for the top post D:

I did some more research and this appears to be a systemd limitation:
https://github.com/systemd/systemd/issues/8307

/rw/usrlocal is mounted to /usr/local as part of
qubes-mount-dirs.service when a vm is booting. This means the unit files
in /usr/local are not visible to systemd.

As poettering state in that issue: "unit files have to reside on a
partition that is mounted at the moment the host PID 1 is invoked. i.e.
either on the root partition or some other partition that the initrd
premounts."

This is quite sad. I have several use cases for app-vm specific systemd
units:

* Automount network drive on boot (for backupvm)
* Run some special daemons on boot
* Execute scripts on user login

I guess I'll just need to revist the use of rc scripts :/ (ala
https://entropux.net/article/systemd-rc-local-service-with-qubes/)

~abel

Claudia

unread,
Jan 12, 2020, 6:45:27 AM1/12/20
to Abel Luck, qubes...@googlegroups.com
January 12, 2020 11:33 AM, "Abel Luck" <ab...@guardianproject.info> wrote:

> The systemd route does seem promising. Thanks.
>
> If I edited the template vm, I could just put my unit file in
> /etc/systemd/system and it would work fine.
>
> However I'd like to do this for a specific AppVm, so I dropped the unit
> file in /usr/local/lib/systemd/system. This file persists across boots
> as expected, however systemd doesn't load units from it until I
> daemon-reload after boot.
>
> I suppose this is because /usr/local is symlinked from /rw/usrlocal
> sometime after systemd has loaded its units.
>
> Is there anyway to get systemd to load units from
> /usr/local/lib/systemd/system as part of appvm boot?
>
> ~abel

Try putting `systemctl daemon-reload` in rc.local. I haven't tried it, but this should work, as rc.local itself resides on /rw, so /rw has to be available by that time. (Arguably the stock rc.local in Qubes templates should be preinstalled with this line. But then, arguably, systemd should always automatically reload units any time it mounts something.)

Abel Luck

unread,
Jan 12, 2020, 6:50:50 AM1/12/20
to qubes...@googlegroups.com


Claudia:
> Try putting `systemctl daemon-reload` in rc.local. I haven't tried it, but this should work, as rc.local itself resides on /rw, so /rw has to be available by that time. (Arguably the stock rc.local in Qubes templates should be preinstalled with this line. But then, arguably, systemd should always automatically reload units any time it mounts something.)

I've tried this, and unfortunately it doesn't work IF the goal is to get
the units in /usr/local to participate in the boot process. This is
because by the time qubes-misc-post.service executes
/rw/config/rc.local, the boot process is already well in progress. See
my other reply for more details.

If the goal is simply to make the /usr/local units available to systemd,
for later start/stopping, then it will work. But you cannot enable them
to be started at boot.

I suppose one could add `systemctl daemon-reload` to rc.local and then a
series of `systemctl start your-thing.service` statements, but you still
miss out on the benefits of systemd's 'enable' (After,Before, etc).

~abel
Reply all
Reply to author
Forward
0 new messages