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

Ahmad Ismail ismail783 at gmail.com
Sat Sep 16 15:29:07 UTC 2023


My nemo-desktop instance keeps crashing due to a bug.

The file in ~/.config/autostart which autostart the service is:

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

So, I came up with a systemd service which will restart nemo-desktop when
memory usage is 100MB.

sudo tee /etc/systemd/system/nemo-desktop-bug-workaround.service << END
[Unit]
Description=Nemo Desktop Bug Workaround
Wants=xdg-desktop-autostart.target
PartOf=graphical-session.target
BindsTo=graphical-session.target

[Service]
User=ismail
Group=ismail
Type=forking
StartLimitIntervalSec=3
ExecStart=/usr/bin/nemo-desktop
ExecStop=/usr/bin/nemo-desktop --quit
MemoryAccounting=true
# MemoryHigh=50000K
MemoryMax=100000K
Restart=always
KillMode=process

[Install]
WantedBy=graphical.target
END

systemctl daemon-reload
systemctl start nemo-desktop-bug-workaround.service
systemctl enable nemo-desktop-bug-workaround.service

Now the problem is, it crashes with the terminal emulators.

What am I doing wrong here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20230916/9096a7f6/attachment.htm>


More information about the systemd-devel mailing list