blue-build / modules

BlueBuild standard modules used for building your Atomic Images
Apache License 2.0
23 stars 25 forks source link

module idea: boot-script #119

Open xynydev opened 5 months ago

xynydev commented 5 months ago

Allow user to specify scripts to run after boot, without them needing to make a systemd module. Name WIP.

fiftydinar commented 5 months ago

I'm not sure if making startup scripts outside of systemd is well supported.

....

Before systemd days, Fedora used init.d, which is now just a backwards compatibility placeholder for a systemd unit.

Location for init.d in Fedora is: /etc/rc.d/init.d

It still requires the user to know it's syntax, so I wouldn't use it for easy approach.

....

We can also try to use rc.local, where you can include direct commands or script locations before exit 0 is performed. I think this one is the most flexible & it's more easy to parse the output of user scripts/commands to write into it. It executes after all services start.

However, support for it in systemd is disabled by default.

https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/

Maybe we can enable it when this is module is used by default.

....

Systemd is a standard for making root startup scripts, so we don't have much solutions.

xynydev commented 5 months ago

What I was suggesting (apparently in an unclear manner) is that this module would make the systemd unit on behalf of the user, so that they don't need to do it manually.

fiftydinar commented 5 months ago

What I was suggesting (apparently in an unclear manner) is that this module would make the systemd unit on behalf of the user, so that they don't need to do it manually.

Yeah, I think It can be done.

Maybe we can add some options in yml, besides including commands & scripts, like requires-internet: yes

But we should not go overboard with this, just add some basic ones.

xynydev commented 5 months ago

It should probably always run after the system is ready with stuff like internet and starting the DE.

fiftydinar commented 5 months ago

It should probably always run after the system is ready with stuff like internet and starting the DE.

I am not comfortable with script/command not running when internet connection is not established (which can happen with buggy internet drivers, even Intel ones with good reputation can have this issue).

I agree that script should be executed after DE is started, when user is logged in.

This can be achieved by running script after xdg-desktop-autostart for root scripts. For non-root scripts, we can simply use --user systemd units.

Due to nature of some commands & scripts not being intended to run as root, I think we will have to separate section into root & non-root scripts & somehow explain this distinction in docs which will make the user clear on what he needs to select for his purpose.

Maybe we can try to use xdg-desktop-autostart directly too, with .desktop files. Advantage is that we don't need to make systemd units for this. Disadvantage is that we don't have granular & reliable configuration of systemd units behavior (if we require internet connection or not f.e.)

fiftydinar commented 3 months ago

I found out some interesting information which is related to this issue.

I wanted to silently autostart flatpaks on my image.

xdg-autostart seemed to work fine, except some apps failed because they require active internet connection. Intel internet driver can be quite buggy in my case, so it can happen that it starts a bit later or I have to replug ethernet cable.

When I looked into solutions, I stumbled upon this systemd template: https://gitlab.com/-/snippets/3669472#flatpak-apps

Initially, it didn't work.

I DM-ed the author on Discord & he kindly helped me debugging the issue.

He uses KDE & it works fine on his image.

It turns out that Gnome handles things differently & that WantedBy=xdg-desktop-autostart.target is not working there.

systemctl --user list-dependencies xdg-desktop-autostart.target lists that nothing has started, but EasyEffects clearly did when looking in Background apps. On KDE, it lists some started apps.

systemctl --user list-dependencies --reverse xdg-desktop-autostart.target lists also nothing, while on KDE it lists plasma-workspace.target.

To solve this issue, I changed WantedBy to gnome-session.target (graphical-session.target may also work, but this one is safer, as it starts later).

Additionally having Wants=gnome-session-initialized.target & After=gnome-session-initialized.target also helps.

Reddit post which also helped me: https://www.reddit.com/r/Ubuntu/comments/15t88ti/using_systemd_instead_of_startup_applications/