You are not logged in.

#1 2023-06-04 13:02:20

ollosh
Member
Registered: 2022-09-20
Posts: 51

[SOLVED] Run particular script only on "restart" of the systemd target

I know systemd does not have a specific flow when restarting, but basically what I want to achieve is for my systemd service to only trigger particular script when it's restarted. Not when it's started or stopped.

To be more specific, I have xsession.target and a polybar.service which is a part of that target. I wanted to create a theme-switcher.py script so when I click on the module of polybar it changes the theme in my config, and does some other things and restarts my theme.target. Pretty simple and it is working fine.
Apart from my chrome instances which I'd like to restart. theme-switcher.py looks like this:

subprocess.run('systemctl --user restart xsession.target', shell = True)
subprocess.run('/usr/bin/pkill chrome', shell=True)
subprocess.run('/usr/bin/gtk-launch chrome-ollosh', shell=True)

The thing is, I can't really find a way to effectively run these 2 following commands since my theme-switcher process I guess gets killed when I restart the target. I even tried creating a separate restarter.service, but I don't like that it restarts chromium whenever I boot my pc or login from lockscreen.

Is there a reliable way where I can somehow have this theme-switcher.py "fork" off from the polybar service and not get killed immediately, but rather execute these commands when xsession.target boots up again.

Last edited by ollosh (2023-06-04 15:54:36)

Offline

#2 2023-06-04 15:55:34

ollosh
Member
Registered: 2022-09-20
Posts: 51

Re: [SOLVED] Run particular script only on "restart" of the systemd target

I've opted to use a file to save the state for the restarter systemd service that then figures out if it needs to or not restart the apps

Offline

Board footer

Powered by FluxBB