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

It sets a max time a service is allowed to stay running. I just went and edited those 2 lines, and set it to 120 (seconds):

● plasma-plasmashell.service - KDE Plasma Workspace
     Loaded: loaded (/etc/xdg/systemd/user/plasma-plasmashell.service; disabled; preset: enabled)
     Active: active (running) since Wed 2022-11-16 17:36:04 CET; 12s ago
      Until: Wed 2022-11-16 17:38:04 CET; 1min 47s left
   Main PID: 2380 (plasmashell)
     Memory: 214.2M

And after 120 seconds:

● plasma-plasmashell.service - KDE Plasma Workspace
     Loaded: loaded (/etc/xdg/systemd/user/plasma-plasmashell.service; disabled; preset: enabled)
     Active: active (running) since Wed 2022-11-16 17:38:05 CET; 2s ago
      Until: Wed 2022-11-16 17:40:05 CET; 1min 57s left
   Main PID: 2492 (plasmashell)
      Tasks: 30 (limit: 9514)
     Memory: 212.3M

EDIT:
So to recap what we learned, hopefully:

  • Copy /usr/lib/systemd/user/plasma-plasmashell.service into /etc/systemd/user/
  • Edit/add:
Restart=always
RuntimeMaxSec=1h
  • Reload daemons.
  • Restart service.
  • [Optionally add RuntimeRandomizedExtraSec=<some value> so you’ll never know when exactly restart is coming. More thrill. :smiley:]

EDIT 2:

As @TriMoon noted in a post below, there is a more correct way to do it. So read his post and/or check: systemd - ArchWiki.

2 Likes

WRONG
You should not copy the service file at all !
Because that will prevent you to receive updated config from the package maintainer.
You should use the proper way to override settings the systemd way :wink:

  1. Remove the /etc/systemd/user/plasma-plasmashell.service you copied first…
  2. Create a “drop-in” to override the settings of the original service file instead by creating:
    /etc/systemd/user/plasma-plasmashell.service.d/override.conf
    with the below as only content should be enough:
    # /etc/systemd/user/plasma-plasmashell.service.d/override.conf
    [Service]
    RuntimeMaxSec=1h
    
  3. Check if it is accepted by systemd by doing:
    3.1 systemctl --user daemon-reload
    3.2 followed by: systemctl --user cat plasma-plasmashell
    3.3 It should show you the contents of both the service file and your drop-in.
    3.4 If it showed both then you can restart the service to make it use your override :wink:

PS: If you do the above and it works, you should rename your thread, because it is not a cron job anymore :rofl:

3 Likes

Good point. I edited my post.

I think it’s fine. This way people who don’t know plasmashell runs as a systemd service can find this thread.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.