Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sytemd service file ? #103

Open
promeneur opened this issue Nov 25, 2021 · 13 comments
Open

sytemd service file ? #103

promeneur opened this issue Nov 25, 2021 · 13 comments

Comments

@promeneur
Copy link

Can you supply a systemd service file ?

Thanks

@Freso
Copy link

Freso commented Jan 28, 2024

What would you want a service file for this to do/provide?

@Mikaela
Copy link

Mikaela commented Apr 27, 2024

I am also curious considering systemd service files can already do this for what it manages.

[Service]
CPUQuota=20%

See also man systemd.resource-control

@promeneur
Copy link
Author

What would you want a service file for this to do/provide?

Sorry @Freso I am late.

In the past, before systemd, we put the statement cpulimit in a special system file according to start it during system startup.

With systemd now all is started with a systemd service file. I speak about a service file to start cpulimit.

Please I am not a techie person about systemd so a ref to systemd doc is not for me.

Thanks

@Mikaela
Copy link

Mikaela commented Apr 27, 2024

What I am saying is that when you write a systemd service file, in addition to ExecStart=/usr/local/bin/mydaemon you can add CPUQuota=20% without having to call cpulimit separately in the service.

A fuller example (although where I cut Unit.{After,Wants} and Service.{Environment,WorkingDirectory,PIDFile,ExecReload,Restart,RestartSec}) would be

[Unit]
Description=R-66Y Limnoria instance (IRC bot)

[Service]
Type=simple
ExecStart=/home/limnoria/venv/bin/limnoria /home/limnoria/R-66Y/R-66Y.conf
User=limnoria
CPUQuota=30%

[Install]
WantedBy=multi-user.target

@promeneur
Copy link
Author

@Mikaela thanks

But the problem is a way complex for my case.

An app FAH is started by systemd service file.

FAH launches randomly others app named "FahCore_a8", "Fahcore_22".

So we must launch a service file which detects that "Fahcore_a8" and "Fahcore_22" are running and limits their cpu consumption to 20 %.

@Mikaela
Copy link

Mikaela commented Apr 27, 2024

I think what you should do is systemctl edit whatever-starts-fah.service and there add the

[Service]
CPUQuota=20%

and it should just work without having to even touch the actual service file (as this creates a drop-in file e.g. /etc/systemd/system/whatever-starts-fah.service.d/override.conf).

@promeneur
Copy link
Author

@Mikaela

thanks

I will try this as soon as I have some time.

@promeneur
Copy link
Author

20% is not enough according Fahcore_a8 consumes 20 %.
We need CPUQuota=200%.

More

With CPUQuota=200% FahCore_22 consumes only 5 % instead of 20 % !

My conf is :

  • the cpu is an 8 cores CPU
  • Fahcore_a8 uses by settings 4 cores
  • Fahcore_22 uses by settings 1 core and the dGPU.

I choose how many cores are used, but Fah decides how to dispatch them between Fahcore_a8 and Fahcore_22.

@Mikaela
Copy link

Mikaela commented Apr 30, 2024

I don't understand what is going on there, but I do have another idea (that actually includes cpulimit this time 😅)

  1. Check what is the service that starts fah in /usr/lib/systemd/system/whatever.service and take note on the ExecStart= line.
  2. sudo systemctl edit whatever.service
  3. Add the following override
[Service]
# Empty ExecStart erases whatever ExecStart has been specified before
ExecStart=
# and do adjust the flags to be more suitable for you
ExecStart=/usr/bin/cpulimit --lazy --include-children --limit=30 /usr/bin/fahcore-or-whatever
  1. sudo systemctl daemon-reload
  2. sudo systemctl restart whatever.service

My third idea would be creating a systemd oneshot service and a timer for running cpulimit with --pid or --exe, but at that point it would be shorter to just use crontab for it assuming it was available and I am still unconvinced about it being a systemd service file for cpulimit, while I guess my second idea could be documented somewhere.

PS. Sorry for long response time, I seem to have went a couple of days without reading my email.

@promeneur
Copy link
Author

@Mikaela

No problem.

The ExecStart of Fah-client service :

ExecStart=/usr/local/bin/fah-client --config=/etc/fah-client/config.xml --log=/var/log/fah-client/log.txt --log-rotate-dir=/var/log/fah-client/

Are you sure the new ExecStart runs without any problem ?

ExecStart=/usr/bin/cpulimit --lazy --include-children --limit=30 /usr/local/bin/fah-client --config=/etc/fah-client/config.xml --log=/var/log/fah-client/log.txt --log-rotate-dir=/var/log/fah-client/

@promeneur
Copy link
Author

I created a cpulimit service.

[Unit]
Description=Run cpulimit

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=cpulimit --include-children --exe fah-client --limit 75

[Install]
WantedBy=multi-user.target

--include-children is not an option of cpulimit. This lead to an exit code when sarting cpulimit service.

@promeneur
Copy link
Author

promeneur commented Apr 30, 2024

I discovered a big problem.

openSUSE supplies a cpulimit package which is in fact Limitcpu 3.0
see
https://limitcpu.sourceforge.net/

it is not the original cpulimit from here

@promeneur
Copy link
Author

i keep my previous solution.

a script cpulimit.sh

cpulimit --exe FahCore_a7 --limit 50 &
cpulimit --exe FahCore_a8 --limit 50 &
cpulimit --exe FahCore_22 --limit 75 &
cpulimit --exe FahCore_23 --limit 75 &

when it is needed

  • I delete a statement about Fahcore_x which are no more used by fah-client
  • I add a statement about a new Fahcore_x which are used by fah-client

a service to launch the script

[Unit]
Description=Run cpulimit

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/roubach/bin/cpulimit.sh

[Install]
WantedBy=multi-user.target

Anyway, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants