Skip to content

Instantly share code, notes, and snippets.

@abraithwaite
Last active May 8, 2024 08:43
Show Gist options
  • Save abraithwaite/1d78a946f90be478faedb5ca4db6d62e to your computer and use it in GitHub Desktop.
Save abraithwaite/1d78a946f90be478faedb5ca4db6d62e to your computer and use it in GitHub Desktop.
Zoom in Systemd Cgroups on Linux. Change the max allocations to fit your workstation.
#!/usr/bin/bash -xe
cat <<EOF > "${HOME}/.config/systemd/user/zoom.slice"
[Slice]
AllowedCPUs=0-4
MemoryHigh=6G
EOF
cat /usr/share/applications/Zoom.desktop | sed -E 's#^(Exec=).*$#Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher#' > "${HOME}/.local/share/applications/Zoom.desktop"
update-desktop-database ~/.local/share/applications
@ZediAlreadyTaken
Copy link

ZediAlreadyTaken commented Jan 3, 2022

Doesn't seem to be working with the flatpak version of Zoom, is there an alternate version of this script for flatpak?

It says:
./chill-zoom.sh: line 3: /home/user/.config/systemd/user/zoom.slice: No such file or directory

@quilicicf
Copy link

@Zenklops You prolly need mkdir -p /home/user/.config/systemd/user or touch /home/user/.config/systemd/user/zoom.slice first.
My guess is, the folder doesn't exist on your disk. I've updated my version of the script above.

@ZediAlreadyTaken
Copy link

https://imgur.com/SHCHo2y

Doesn't seem to be working? Is this is the expected output? If so, there really should be a statement echo'ing "success", would make it a bit more user friendly.

@quilicicf
Copy link

Well you don't have a file /usr/share/applications/Zoom.desktop which is supposed to describe the Zoom launcher (icon, executable path etc...). I don't know how you run Zoom with flatpak or the distro you're using but it looks like it doesn't use those 🤔

More info on the desktop files

I think this should get you going. It explains how the flatpak files store their .desktop files.

If you find the zoom.desktop (might be named slightly differently) in ~/.local/share/flatpak/ then you could fix the script by just swapping the path /usr/share/applications/Zoom.desktop to ~/.local/share/flatpak/zoom.desktop (or whatever name it's got). Something like:

updatedLauncher="$(
  sed -E 's#^(Exec=).*$#Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher#' < "${HOME}/.local/share/flatpak/zoom.desktop"
)"
printf '%s' "${updatedLauncher}" > "${HOME}/.local/share/applications/Zoom.desktop"

Note: as for the output, this script is kinda rough as pointed out by its author so don't expect some polish 😉 But your PS1 shows that the command exited with return code 1 (error) and there's an error message in the output, which is enough to debug.

@ZediAlreadyTaken
Copy link

ZediAlreadyTaken commented Jan 4, 2022

I think code is not polished for the Flatpak version of Zoom which probably makes little sense because most people are gonna run Zoom under some kind of isolation aspect such as Flatpak or Docker. The code did run successfully thanks to @quilicicf's amendments and it made a separate .desktop as ~/.local/share/applications/Zoom.desktop I gave it execute permissions by chmod +x ~/.local/share/applications/Zoom.desktop but the result of ./Zoom.desktop inside of that directory gives the following result.

./Zoom.desktop: line 1: [Desktop: command not found
./Zoom.desktop: line 3: Video: command not found
./Zoom.desktop: line 4: Client: command not found
./Zoom.desktop: line 5: --user: command not found
./Zoom.desktop: line 10: InstantMessaging: command not found
./Zoom.desktop: line 10: VideoConference: command not found
./Zoom.desktop: line 10: Telephony: command not found
./Zoom.desktop: line 11: x-scheme-handler/zoomus: No such file or directory
./Zoom.desktop: line 11: x-scheme-handler/tel: No such file or directory
./Zoom.desktop: line 11: x-scheme-handler/callto: No such file or directory
./Zoom.desktop: line 11: x-scheme-handler/zoomphonecall: No such file or directory
./Zoom.desktop: line 11: application/x-zoom: No such file or directory
./Zoom.desktop: line 12: X-KDE-Protocols=zoommtg: command not found
./Zoom.desktop: line 12: zoomus: command not found
./Zoom.desktop: line 12: tel: command not found
./Zoom.desktop: line 12: callto: command not found
./Zoom.desktop: line 12: zoomphonecall: command not found

This is how the .desktop file looks inside Vim, is this expected behavior?

[Desktop Entry]
Name=Zoom
Comment=Zoom Video Conference
GenericName=Zoom Client for Linux
Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher
Icon=us.zoom.Zoom
Terminal=false
Type=Application
StartupNotify=true
Categories=Network;InstantMessaging;VideoConference;Telephony;
MimeType=x-scheme-handler/zoommtg;x-scheme-handler/zoomus;x-scheme-handler/tel;x-scheme-handler/callto;x-scheme-handler/zoomphonecall;application/x-zoom
X-KDE-Protocols=zoommtg;zoomus;tel;callto;zoomphonecall;
StartupWMClass=zoom

Edit: I am using Arch Linux, installed Flatpak through Pacman.

@quilicicf
Copy link

The *.desktop files are not supposed to be executed.
They should be used by your desktop to open applications.

Ex: in gnome, press Super key, the activities view opens. Type the name of the app and a shortcut appears. The available apps are found by gnome using the *.desktop files, the icon you see in the activities view is the icon referenced in the Icon= line of the file etc...

The script changes the Exec= line to change the code that is executed by your desktop when running the application.

I don't know what desktop you are using but the standard way of opening applications with it should rely on this mechanism.

Copy link

ghost commented Jan 8, 2023

is that systemd service or sum?

@murach
Copy link

murach commented Jul 17, 2023

Thanks for this little script! For convenience I needed to append %U to the Exec line, like this:
Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher %U

This solved issues with KDE's KIO system and facilitates joining meetings with fully-qualified URLs that include e.g. password keys (format https://....zoom.us/j/12345678?pwd=MeetingPasswordHash)

@desrod
Copy link

desrod commented Sep 5, 2023

I stumbled across this in a search to solve why Zoom consumes 150% of my 12 CPU cores when running, and it looked like it would solve the problem by constraining the memory and CPUs.

Unfortunately, this does not work if your Zoom session requires you to log in, or uses SSO or is tied to a company domain, which many to most would be (yes, even when passing %U at the end, as in the previous reply above this one).

Once that happens, you're stuck in an endless loop of systemd running the Zoom client unauthorized, prompting for auth using the browser, which then launches a new instance of Zoom (unauthorized), and round-and-round we go, never actually saving the login credentials or passing them to the Zoom client.

I'm back on the hunt for other solutions...

@maxxu05
Copy link

maxxu05 commented Dec 13, 2023

@desrod hey I think @brightonanc and I found a workaround for this. If you replace the exec line in ${HOME}/.local/share/applications/Zoom.desktop with

Exec=systemd-run --scope -p MemoryMax=4G -p MemoryHigh=2G -p MemorySwapMax=0 -p CPUQuota=25%% --user -- /usr/bin/zoom %U

Then it should work with SSO and limit RAM and CPU cores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment