[systemd-devel] Restart SystemD service when Memory Usage in More than a threshold

Ahmad Ismail ismail783 at gmail.com
Tue Sep 19 05:28:24 UTC 2023


Here is the bug https://github.com/linuxmint/nemo/issues/3306 .
Unfortunately nemo-desktop is a very important dependency for my regular
work.

Currently I manually restart it. Restarting this is not as bad as it sounds
like. Just the desktop icons go away and come back.

Here is the service file I am currently at:

[Unit]
Description=Nemo Desktop Bug Workaround
Wants=xdg-desktop-autostart.target
PartOf=graphical-session.target
BindsTo=graphical-session.target

[Service]
Type=forking
StartLimitIntervalSec=3
ExecStart=/usr/bin/nemo-desktop
# MemoryHigh=50000K
MemoryMax=100000K
Restart=always
KillMode=process
KillSignal=SIGKILL

[Install]
WantedBy=graphical-session.target xsession.target gnome-session.target
END

I have run:

> systemctl --user list-dependencies xdg-desktop-autostart.target
> xdg-desktop-autostart.target
> ○ ├─app-geoclue\x2ddemo\x2dagent at autostart.service
> ○ ├─app-gnome\x2dinitial\x2dsetup\x2dfirst\x2dlogin at autostart.service
> ○ ├─app-gnome\x2dshell\x2doverrides\x2dmigration at autostart.service
> ○ ├─app-im\x2dlaunch at autostart.service
> ○ ├─app-nemo\x2ddesktop at autostart.service
> ○ ├─app-nm\x2dapplet at autostart.service
> ○ ├─app-orca\x2dautostart at autostart.service
> ○ ├─app-org.gnome.Evolution\x2dalarm\x2dnotify at autostart.service
> ○ ├─app-org.gnome.SettingsDaemon.DiskUtilityNotify at autostart.service
> ○ ├─app-org.gnome.Software at autostart.service
> ○ ├─app-user\x2ddirs\x2dupdate\x2dgtk at autostart.service
> ○ ├─app-xdg\x2duser\x2ddirs\x2dkde at autostart.service
> ○ └─app-yandex\x2ddisk at autostart.service


Here app-nemo\x2ddesktop at autostart.service is most probably generated
by systemd-xdg-autostart-generator using:

[Desktop Entry]
> Type=Application
> Name=Nemo
> Comment=Start Nemo desktop at log in
> Exec=nemo-desktop
> X-GNOME-AutoRestart=true
> NoDisplay=true


How can I view  app-nemo\x2ddesktop at autostart.service ? If I can view this
file then would like to copy the contents and edit it then remove
app-nemo\x2ddesktop at autostart.service and install the custom service. On
that note, would be glad to know how to remove these auto-generated files
when i have a new one.


On Mon, Sep 18, 2023 at 11:12 PM Michal Koutný <mkoutny at suse.com> wrote:

> Hello Ahmad.
>
> On Sat, Sep 16, 2023 at 09:29:07PM +0600, Ahmad Ismail <
> ismail783 at gmail.com> wrote:
> > The file in ~/.config/autostart which autostart the service is:
>              ^^^
>
> > So, I came up with a systemd service which will restart nemo-desktop when
> > memory usage is 100MB.
>
> Is the bug you mention a memory leak? (A restart at arbitrary moment
> doesn't sound like the best user experience.)
>
> Or is it another cause? Nevertheless, you may want to report it to
> the respective upstream or upgrade to its latest version.
>
> > sudo tee /etc/systemd/system/nemo-desktop-bug-workaround.service << END
>                         ^^^^^^
>
> > [Service]
> > User=ismail
> > Group=ismail
> ...
> > ExecStart=/usr/bin/nemo-desktop
> ...
> > What am I doing wrong here?
>
> Maybe you conflate a system service (running with changed User=/Group=)
> and a user instance service (spawned under user@$UID.service) and some
> necessary settings are missing in the nemo-dektop's environment (I'm not
> familiar with that particular program, hence a guess only).
>
> HTH,
> Michal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20230919/a130dd47/attachment.htm>


More information about the systemd-devel mailing list