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

But as for the root problem, it seems to be a memory leak bug affecting Plasma when running on Arch with my particular GPU. I haven’t found a solution for it yet.

Plasma runs as systemd service since… 5.25 or something. Write a systemd timer.

journalctl --no-pager :wink:

Hail Systemd.timer(5), death to cron and the like :rofl:
No seriously adapt to the new era…

To check logs you can use: (attribution)

journalctl -b 0 _COMM=plasmashell

If anyone can, please link me to a tutorial or wiki how to make a system.d timer job that runs a bash script as a standard user, not as root.
Alternatively, that will run the command

kquitapp5 plasmashell && kstart5 plasmashell

as standard user, not as root.

See systemd/User - ArchWiki and systemd/Timers - ArchWiki a timer is just a type of systemd-unit specially for timed executions.

  • See the link i gave in previous reply to the man page of timers.
  • To make a bash script executable you need to modify it’s file permissions plus add a shebang, im sure there are plenty of pages on the internet dealing with that topic. (its super easy)
#!/bin/env bash

PS: You can split that command into 2 commands that get executed in sequence by the service file you will need to create, which will be triggered by the timer.

1 Like

Aha, so in systemd/User - ArchWiki I see there is an issue with path.

If you customize your PATH and plan on launching applications that make use of it from systemd units, you should make sure the modified PATH is set on the systemd environment. Assuming you set your PATH in .bash_profile, the best way to make systemd aware of your modified PATH is by adding the following to .bash_profile after the PATH variable is set:

~/.bash_profile

systemctl --user import-environment PATH

Maybe that was the problem.

This has nothing to do with plasmashell or timers.

Why do you think you need to modify the path?

Create the service and timer file in ~/.config/systemd/user/, reload the files with systemctl --user daemon-reload and enable the timer: systemctl --user enable --now xxx.timer.

1 Like

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.