Restart plasmashell on a schedule: Cron? Systemd timer? Edit system file?

I think that path was an issue because the bash script I tried to run was in

/home/shmuel/

and that location is not on $PATH by default.
However,

/home/shmuel/.local/bin

Is on $PATH, so I created that folder, and now put my bash script in it.

When I start the systemd timer service that I just now created (letā€™s forget about the cron job) I get this error:

Nov 15 19:49:41 shmuel-manjaro systemd[1]: Started "kill and restart Plasmashell".
Nov 15 19:49:41 shmuel-manjaro kquitapp5[19610]: "Application plasmashell could not be found using service org.kde.plasmashell and path /MainApplication."

PATH doesnā€™t matter because systemd services need the absolute path for the ExecStart directive.

Please start sharing all information.

What info would you like to see?
I canā€™t post info about the cron job that was the original subject of this thread, because on advice of the community, I made a systemd timer job instead. That is what I am now trying to deal with. Maybe my last post was not so clear, so I will edit it.

The service file, the timer file, the script, and all logs concerting these three elements.

restart_plasmashell.service

[Unit]
Description="kill and restart Plasmashell"

[Service]
ExecStart=/home/shmuel/.local/bin/plasmashell_restart.sh

restart_plasmashell.timer

[Unit]
Description="kill and restart Plasmashell"

[Timer]
OnBootSec=60min
OnUnitActiveSec=1h
Unit=restart_plasmashell.service

[Install]
WantedBy=multi-user.target

plasmashell_restart.sh

#!/bin/bash
kquitapp5 plasmashell && kstart5 plasmashell

I ran:

sudo systemctl start restart_plasmashell.service
[sudo] password for shmuel: 
 ļŒ’ ī‚° ļ¼ ~/.lo/bin ī‚°

And I got:

journalctl -S today -f -u restar
t_plasmashell.service
Nov 16 00:12:27 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 00:12:27 shmuel-manjaro kquitapp5[40564]: "A
pplication plasmashell could not be found using ser
vice org.kde.plasmashell and path /MainApplication.
"
Nov 16 00:12:27 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 00:12:27 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.
Nov 16 01:12:57 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 01:12:57 shmuel-manjaro kquitapp5[43623]: "A
pplication plasmashell could not be found using ser
vice org.kde.plasmashell and path /MainApplication.
"
Nov 16 01:12:57 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 01:12:57 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.
Nov 16 02:13:07 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 02:13:07 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 02:13:07 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.
Nov 16 03:13:17 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 03:13:17 shmuel-manjaro kquitapp5[49485]: "A
pplication plasmashell could not be found using ser
vice org.kde.plasmashell and path /MainApplication.
"
Nov 16 03:13:17 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 03:13:17 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.
Nov 16 04:13:18 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 04:13:18 shmuel-manjaro kquitapp5[52971]: "A
pplication plasmashell could not be found using ser
vice org.kde.plasmashell and path /MainApplication.
"
Nov 16 04:13:18 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 04:13:18 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.
Nov 16 04:16:12 shmuel-manjaro systemd[1]: Started
"kill and restart Plasmashell".
Nov 16 04:16:12 shmuel-manjaro kquitapp5[53666]: "A
pplication plasmashell could not be found using ser
vice org.kde.plasmashell and path /MainApplication.
"
Nov 16 04:16:12 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Main process exited, code=exit
ed, status=1/FAILURE
Nov 16 04:16:12 shmuel-manjaro systemd[1]: restart_
plasmashell.service: Failed with result 'exit-code'
.

You missed the point. Service already exists: /usr/lib/systemd/user/plasma-plasmashell.service

And to be honest, you probably donā€™t even need a timer. Just copy it under /etc/systemd/user/ and edit/add:

RuntimeMaxSec=3600
Restart=always

Not sure if this will work though. BUT! As it was already said, fix underlying issue if there even is one. This automatical restarting of plasmashell makes zero sense.

I donā€™t understand the point you are making. Can you please explain it?

I already did. Plasma runs as a systemd service. Already. You just restart that.

If you want to run it as your user, you have to put it into ~/.config/systemd/user/ and run it with
systemctl --user (no sudo).

It already runs as a user service, so no need for that. Just what I said in post #27.

That is useless because the script(process) does not stay running :wink:

@shmu26 , donā€™t use the timer functionality yet, first try to make your user-service unit work as expected, eg. successfully restarts your plasmashell.
Only after that works, you can add the timer to make it execute at your desired interval(s).

And as noted a few times, it needs to be a user-service not a global one under /etc/systemd/system and the likeā€¦

2 Likes

So I tried that way, too, following this tutorial

and also this one
https://www.xf.is/2020/06/27/configuring-systemd-user-timer/
But with both, when testing the service, I got an error message that it is not configured to run with systemctl, even though the content of the service file was the same as when I tried it globally. :thinking:

Try to fix that firstā€¦
Post the location where you placed the service file plus itā€™s contents, plus the command you used that gave you the error message inclusive the exact message you got. :wink:

@TriMoon Thanks a lot for the help. To you and to everyone. I think I am going back to my Manjaro Gnome installation, at least for the meantime. This is tiring me outā€¦

While Iā€™d agree with you thereā€¦ since a few versions Cinnamon has in fact integrated the by poster sought functionality natively: https://regmedia.co.uk/2021/03/01/restart-cinnamon.jpg

2 Likes

That canā€™t be right, right? right??

Edit: It really is real. :rofl:

2 Likes

Certainly canā€™t ā€“ but itā€™s there alright, and a fair few reviews around the web hailed it as a great advancement. Yes, I knowā€¦

Huh? I have it running and manually restarting just fine. (Didnā€™t test RuntimeMaxSec, but I donā€™t see why it wouldnā€™t restart it just the same.)

Thatā€™s because you are overcomplicating things. And we all are making 50 posts long topic about how to restart something. :smiley:

1 Like

That is a setting that limits the max time allowed for a process to stay running, thatā€™s why i said that :wink:
https://www.freedesktop.org/software/systemd/man/systemd.service.html#RuntimeMaxSec=