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

Nice in systemd unit is always 5 #229

Closed
jee-r opened this issue Jun 18, 2023 · 9 comments · Fixed by #409
Closed

Nice in systemd unit is always 5 #229

jee-r opened this issue Jun 18, 2023 · 9 comments · Fixed by #409
Assignees
Labels
bug Something isn't working

Comments

@jee-r
Copy link

jee-r commented Jun 18, 2023

Hello
I noticed that nice in global section is not correctly passed to systemd unit template.

for example with this config

version: "1"
global:
  nice: 17
default:
  repository: "my_repo"
  password-file: "key"
  backup:
    exclude-file: "excludes"
    exclude-caches: true
    one-file-system: true
    tag:
      - "test"
    source:
      - "/tmp/"
    schedule: "*-*-* 12:15:00"
    schedule-permission: system
    schedule-priority: background
    schedule-lock-mode: default
    schedule-lock-wait: 15m30s

After running schedule the systemd unit file is

cat /etc/systemd/system/[email protected]
[Unit]
Description=resticprofile backup for profile default in ./profiles.yaml

[Service]
Type=notify
WorkingDirectory=/tmp
ExecStart=/usr/local/bin/resticprofile --no-prio --no-ansi --config ./profiles.yaml --name default --lock-wait 15m30s backup
Nice=5
Environment="HOME=/root"
Environment="SUDO_USER=test"

Nice is set to 5 and not to 17 as expected

@creativeprojects
Copy link
Owner

This is right, I can see in systemd that nice is set to a predefined value:

nice := constants.DefaultBackgroundNiceFlag

Thanks for the report 👍🏻

@creativeprojects creativeprojects self-assigned this Jul 3, 2023
@creativeprojects creativeprojects added the bug Something isn't working label Jul 3, 2023
@flolilo
Copy link

flolilo commented Dec 18, 2023

Hello,
Just wanted to chime in that when starting resticprofile from the terminal with:

# leaving out definitely unrelated settings, i.e. paths
global:
  # neither this:
  priority: "idle"
  # nor this:
  nice: 19
  # ...nor both together change anything.

default:
  backup:
    verbose: 2

also will create restic instances with the default niceness.

  • resticprofile version: resticprofile version 0.24.0 commit bcfaaa7
  • restic version: restic 0.16.2 compiled with go1.21.3 on linux/amd64

Edit: resticprofile itself respects the setting, only the restic instances are started at the default niceness.

@scy
Copy link
Contributor

scy commented Mar 13, 2024

will create restic instances with the default niceness

Can confirm, I'm seeing this too.

  • resticprofile version 0.26.0 commit 2ab1f3a
  • restic 0.16.4 compiled with go1.21.6 on linux/amd64
  • Linux 6.1.0-17-amd64 SMP PREEMPT_DYNAMIC Debian 6.1.69-1 (2023-12-30) x86_64 (bookworm)

Now, I'm no Go programmer, and only somewhat familiar with the Unix/Linux API, but it looks to me as if you're creating a process group, but then setting the niceness only for the current process and not the group in https://github.com/creativeprojects/resticprofile/blob/master/priority/linux.go#L52-L60:

err = unix.Setpriority(unix.PRIO_PROCESS, pid, priority)

Could using PRIO_PGRP instead of PRIO_PROCESS be enough to fix that?

@creativeprojects
Copy link
Owner

creativeprojects commented Mar 13, 2024

Could using PRIO_PGRP instead of PRIO_PROCESS be enough to fix that?

Well spotted!

If you guys are ok with compiling go code, can you try again with this MR? #339

(This is a fix when running from the terminal, not from systemd)

@flolilo
Copy link

flolilo commented Mar 14, 2024

Hello again!

#339 seems to work for me!

@scy scy mentioned this issue Mar 14, 2024
@scy
Copy link
Contributor

scy commented Sep 14, 2024

(This is a fix when running from the terminal, not from systemd)

Can confirm that this indeed fixes it, but only when not running from a systemd unit (i.e. scheduled). In other words, scheduled runs are still broken.

@chymian
Copy link

chymian commented Oct 2, 2024

@creativeprojects any progress on that year old very annoying bug, while running from systemd?

using v.28 and my (elderly) laptop – since it gained a new, fast NVMe – gets always unresponsive while checking/backing up.

priority = "Idle" # tried 19, Background, etc…
ionice = true
ionice-class = 3
ionice-level = 7

@creativeprojects
Copy link
Owner

creativeprojects commented Oct 2, 2024

I was waiting for a big refactoring of the scheduling to allow for configuration v1 and v2 to be scheduled using the same code. That part is done ✅

Now I still need to ensure the parameters make sense, as with systemd, nothing is never straightforward 😆

https://unix.stackexchange.com/questions/340283/using-and-understanding-systemd-scheduling-related-options-in-a-desktop-context

I do have limited capacity (evening after work) but I'll look at it next 😛

@creativeprojects
Copy link
Owner

creativeprojects commented Oct 5, 2024

Do you guys want to give it a try before I push a new version?

You just need to install resticprofile from source, the code is merged into the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants