Giter Club home page Giter Club logo

Comments (44)

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 2

after I commanded sudo bat persist, the contents of the [email protected] reverted back to the previous version. When I try to enable the service with systemctl, this is what it said:

Failed to get properties: Unit name [email protected] is neither a valid invocation ID nor unit name.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024 2

Ah. I see. Then it might better to do in the unit file template since the setup logic already resolves the actual value.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 1

On your system, what is the output of cat /etc/systemd/system/bat*

It is identical to the source file.

[Unit]
Description=Persist the battery charging threshold after %i
After=%i.target
StartLimitBurst=0

[Service]
Type=oneshot
Restart=on-failure
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'

[Install]
WantedBy=%i.target

There really is no difference.

Looking at the %i and the description in the picture, %i seems to be equal to "multi-user"

I also notice that the battery limiter also works after shutting down, however when I turn it on, the threshold immediately resets to 100

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 1

Alright, I'll try that.

systemctl list-unit-files I see my bat with enabled enabled both in green

Mine's indirect enabled

Screenshot from 2023-09-17 21-19-59

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 1

@pepa65 you are correct.

After I turned the laptop on, the battery indicator turned red again, but when the ubuntu shell appeared, the battery indicator turned white again. This is a most peculiar turn of event.

The [email protected] is still indirect enabled, tho. What is happening and how do I fix it? The glob should work, right?

Should I close the issue when it is not fully solved?

from bat.

pepa65 avatar pepa65 commented on May 25, 2024 1

That confirms there is something wrong that @tshakalekholoane needs to fix.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024 1

@tshakalekholoane It is also good to include RemainAfterExit=true in the unit files under [Service], because then the service shows as Active when doing systemctl status.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024 1

I haven’t merged the changes yet. They’re in this PR if you want to checkout the code.

Yes I left the %s in there so that the application doesn’t have to contain logic to find the shell. systemd can take care of that. Does it not work for you?

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024 1

I just use /bin/sh as I assume that to be universally available on Linux.

I’m not sure that’s the case on NixOS but that could be a good default.

@cloudmadeofcandy are you sure you’re running the correct version? bat@multi-user shouldn’t be there anymore. There should be 5 different services for each event after the change.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 1

replacing %s with /bin/bash does though.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024 1

Yes, but being immutable and all, does it allow changing the threshold manually or otherwise?

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024 1

@cloudmadeofcandy, please let me know if the following works.

This works perfectly. Thank you so much 💯

from bat.

pepa65 avatar pepa65 commented on May 25, 2024 1

That line doesn't work because sh doesn't expand the question mark in echo 60 >/sys/class/power_supply/BAT?/charge_control_end_threshold. You have to do: b=$(echo /sys/class/power_supply/BAT?/charge_control_end_threshold); echo 80 >"$b" (or you have to substitute the actual value into the unit files, so BAT0 or BAT1 or whatever).

Of course NixOS allows you to do basic operations like this. Their focus is on package & configuration management. They use systemd, they have bash.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

On your system, what is the output of cat /etc/systemd/system/bat*

In any case, they are not running, they are just present. On my system those units are also not active. The difference is, I do have persistence after boot...

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

What is %s?
And what is cat /sys/class/power_supply/BAT?/charge_control_end_threshold??

But from what you're saying is that the unit file is not run boot (or, the value is overwritten later..? In that case, logging that the unit file does get run would show that.)

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

What is %s?

I don't really know how to print that out, however I believe that it should be the location of the /bin/bash.

And what is cat /sys/class/power_supply/BAT?/charge_control_end_threshold??

  1. After I run the bat file. After restarting, it is definitely 100.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

The unit file should not have %i and %s, but the substituted values. If you do cat /etc/systemd/system/bat* it should print /bin/bash and not %s.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

How very interesting. However, the %s and %i must have been substituted correctly, otherwise it wouldn't have run in the first place.

A picture of the cat /etc/systemd/system/bat* tho:

Screenshot from 2023-09-17 21-09-24

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

That is not going to run like that. When I do systemctl list-unit-files I see my bat with enabled enabled both in green. I am guessing that is not the case with you. I bet if you replace %s with /bin/bash and %i with multi-user it will work on reboot.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

If you did bat persist I would expect for it to work correctly. Let's wait for @tshakalekholoane to chime in, and see if there is something wrong with it.

(My fork is a bit different, and then this repo got changed as well...)

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

I suspect it may have something to do with the unit file not being in the correct format i.e., the target cannot be specified using a template (I think).

The latest version uses systemd templates (see man systemd.unit) instead of writing all the units manually. The thinking being this would allow services to be created for events that are only supported by the distribution and the %s specifier would also help with finding the shell on distributions like NixOS that do use standard paths.

The fix may well be going back to the previous implementation.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

I just pushed a fix, @cloudmadeofcandy. Please let me know if it works.

It also includes @pepa65's suggestion to set RemainAfterExit=true so the service status can now be queried.

bat.zip

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

When I checked out the repo and built, I got bat 0.13-3-g7f0908d and it was as before. When I downloaded the bat.zip I got bat 0.13-4-g32b7edc and it worked for the unit file path expansion, but the %s was still there instead of /bin/bash.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

Oh, I didn't know, does systemd do that, replace %s with a valid shell? In my fork, I just use /bin/sh as I assume that to be universally available on Linux.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

After uninstalling the old bat files in /etc/systemd/system and reloaded the daemon with systemctl, I reinstalled the new bat binary, set and persisted the threshold and restarted the laptop. It didn't work.

Screenshot from 2023-09-19 14-15-02

When I ran

systemctl --type=service

the system reported that [email protected]'s status is failed failed
Screenshot from 2023-09-19 14-22-43

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

The result after running cat /etc/systemd/system/bat* :

[Unit]
Description=Persist the battery charging threshold after hibernate
After=hibernate.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=hibernate.target
[Unit]
Description=Persist the battery charging threshold after hybrid-sleep
After=hybrid-sleep.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=hybrid-sleep.target
[Unit]
Description=Persist the battery charging threshold after multi-user
After=multi-user.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=multi-user.target
[Unit]
Description=Persist the battery charging threshold after suspend
After=suspend.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=suspend.target
[Unit]
Description=Persist the battery charging threshold after suspend-then-hibernate
After=suspend-then-hibernate.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=%s -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=suspend-then-hibernate.target

My service folder now have multiple [email protected] files, and they aren't sorted into folders like the previous version:

Screenshot from 2023-09-19 14-37-08

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

What’s their status after reboot?

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

@cloudmadeofcandy are you sure you’re running the correct version?

The version of the software said "18 September 2023"

Screenshot from 2023-09-19 14-39-55

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

Best disable & delete those old bat@* unit files, the new files start with bat-.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

Before the reboot, after setting and persisting:

Screenshot from 2023-09-19 14-42-46

After the reboot, querying the threshold:

Screenshot from 2023-09-19 14-43-40

There is only a service called bat-multi-user.service, in activating auto-restart

Screenshot from 2023-09-19 14-44-26

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

Best disable & delete those old bat@* unit files, the new files start with bat-.

I did, but to no avail...

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

So you still have %s in your unit file(s)? Check if replacing that with /bin/sh helps make it work. I am suspecting that systemd doesn't (always?) replace %s with a default shell.

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

replacing %s with /bin/sh doesn't work. I've just tried it
Screenshot from 2023-09-19 15-00-54

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

I guess the syntax in that line doesn't work for dash... I remember I adapted it on my fork.

If systemd indeed "replaces" %s, it could be it uses dash, and then the syntax is not correct.

Replace the bits between single quotes with: b=$(echo /sys/class/power_supply/BAT?/charge_control_end_threshold); echo 60 >$b

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

Which version of systemd are you using? The substitution seems to work fine on my system. But either way, maybe resolving it manually could be the solution here too.

Screenshot from 2023-09-19 10-02-07

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

Which version of systemd are you using?

Mine is systemd 249 (249.11-0ubuntu3.10)

from bat.

cloudmadeofcandy avatar cloudmadeofcandy commented on May 25, 2024

But either way, maybe resolving it manually could be the solution here too.

True, but whenever I want to change the threshold, I'd have to edit the file again.

I'll close the issue in the mean time.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

By that I mean in the code instead of delegating that to systemd. It wouldn't make sense to have the user change it every time they wanted to update the threshold.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

@tshakalekholoane You could adjust the line as I suggested, and it would work in either bash or dash or whatever POSIX shell. I am testing a NixOS installation, but the NixOS live CD had /bin/sh linked to one of their binaries.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

But according to #65 (comment) /bin/sh also doesn't work so I'd rather mark Bash as a hard requirement instead of trying to enumerate all the possibilities.

It also doesn't appear that this application could even run on NixOS so maybe having it this way won't be an issue for the majority of people.

@cloudmadeofcandy, please let me know if the following works.

bat.zip

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

I am pretty sure NixOS also has /bin/sh. But it would require a change in your line to make it work in dash.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

Yes, but being immutable and all, does it allow changing the threshold manually or otherwise?

I would hope so! I think it's more the software that's immutable than the system variables. Otherwise there would be no point to use bat, and no use for bat to support NixOS.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

I can now report that NixOS does have /bin/sh (it is the only entry they have in /bin, a link to their store for the bash shell). That said, POSIX does not require that, but they do require sh to be present in PATH, so if you want to be supersafe, you could use your approach to find bash, but instead use it to find sh (as bash is not guaranteed to be present).

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

Maybe. But I’m still reluctant to use bin/sh given for whatever reason that doesn’t seem to work on Ubuntu (per comment above).

Were you able to determine if NixOS also allows the charging threshold to be set?

from bat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.