How to create/enable AppVM-specific systemd unit?

Hi,

I am looking for a way to run some script before other.service starts. rc.local doesn’t seem to work, as the other.service (which runs Before=sysinit.target) seems to conflict the script execution, i.e. my script must run before other.service starts which I plan do to with:

...
Before=other.service
...
RequiredBy=other.service

I know how to do this using my own systemd unit in the template but the task is not to touch the template. I can obviously put it in /usr/local/lib/systemd/system/my.service but the question is how to enable the service without touching the template, i.e. make it entirely AppVM-specific?

1 Like

You can use bind-dirs:

1 Like

What is your idea?
How can bind-dirs help?

On second thought bind-dirs won’t help here since you need to reload files after mounting for systemd to see them.

Question: in rc.local, can’t you stop the other.service, alter the config, then start your service (or script) and start the other.service again?

I don’t think there is a way to do this “the Qubes way” right now.

The following was suggested on github and may be the answer to your question, but it’s not merged:

Question: in rc.local, can’t you stop the other.service, alter the config, then start your service (or script) and start the other.service again?

I have not tried but it seems to me it might have unpredicated negative effects.

I have actually found that I can do it without an extra unit. I found a way to fi my own script, which would allow me to run it through rc.local. It had something to do with ownership/permissions which behaved differently in AppVM and DispVMs.

It is still an interesting general problem though.

@DVM thanks for the extra info.

This pull request is quite similar to what I already use for my own units in templates, i.e. Before=qubes-early-vm-config.service.

This use case is explained in the file /rw/config/rc.local (for a simple version)

> cat /rw/config/rc.local 
#!/bin/sh

# This script will be executed at every VM startup, you can place your own
# custom commands here. This includes overriding some configuration in /etc,
# starting services etc.

# Example for overriding the whole CUPS configuration:
#  rm -rf /etc/cups
#  ln -s /rw/config/cups /etc/cups
#  systemctl --no-block restart cups