Skip to content

sytemd service file ? #103

Open
Open

Description

@promeneur

Can you supply a systemd service file ?

Thanks

Activity

  1. Freso commented on Jan 28, 2024

    @Freso

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

  2. Mikaela commented on Apr 27, 2024

    @Mikaela

    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

  3. promeneur commented on Apr 27, 2024

    @promeneur
    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

  4. Mikaela commented on Apr 27, 2024

    @Mikaela

    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
  5. promeneur commented on Apr 27, 2024

    @promeneur
    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 %.

  6. Mikaela commented on Apr 27, 2024

    @Mikaela

    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).

  7. promeneur commented on Apr 27, 2024

    @promeneur
    Author

    @Mikaela

    thanks

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

  8. promeneur commented on Apr 28, 2024

    @promeneur
    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.

  9. Mikaela commented on Apr 30, 2024

    @Mikaela

    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.

  10. promeneur commented on Apr 30, 2024

    @promeneur
    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/

  11. promeneur commented on Apr 30, 2024

    @promeneur
    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.

  12. promeneur commented on Apr 30, 2024

    @promeneur
    Author

    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

  13. promeneur commented on Apr 30, 2024

    @promeneur
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions