Comments (44)
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.
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.
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.
Alright, I'll try that.
systemctl list-unit-files I see my bat with enabled enabled both in green
Mine's indirect enabled
from bat.
@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.
That confirms there is something wrong that @tshakalekholoane needs to fix.
from bat.
@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.
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.
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.
replacing %s
with /bin/bash
does though.
from bat.
Yes, but being immutable and all, does it allow changing the threshold manually or otherwise?
from bat.
@cloudmadeofcandy, please let me know if the following works.
This works perfectly. Thank you so much 💯
from bat.
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.
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.
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.
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??
- After I run the bat file. After restarting, it is definitely 100.
from bat.
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.
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:
from bat.
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.
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.
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.
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.
from bat.
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.
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.
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.
When I ran
systemctl --type=service
the system reported that [email protected]
's status is failed failed
from bat.
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:
from bat.
What’s their status after reboot?
from bat.
@cloudmadeofcandy are you sure you’re running the correct version?
The version of the software said "18 September 2023"
from bat.
Best disable & delete those old bat@*
unit files, the new files start with bat-
.
from bat.
Before the reboot, after setting and persisting:
After the reboot, querying the threshold:
There is only a service called bat-multi-user.service
, in activating auto-restart
from bat.
Best disable & delete those old bat@* unit files, the new files start with bat-.
I did, but to no avail...
from bat.
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.
replacing %s
with /bin/sh
doesn't work. I've just tried it
from bat.
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.
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.
from bat.
Which version of systemd are you using?
Mine is systemd 249 (249.11-0ubuntu3.10)
from bat.
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.
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.
@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.
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.
from bat.
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.
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.
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.
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)
- issue: Charging does not stop no matter if the laptop is running or sleeping HOT 5
- issue: How to set charge resume level? HOT 3
- issue: Fails to build: cannot load embed: malformed module path "embed" HOT 3
- Works with T14 Gen2 Intel ThinkPads HOT 1
- issue: bat uninstall HOT 6
- issue: Could not find Bash on NixOS while setting persist mode HOT 5
- bat-asus-battery-bin package on AUR failed to build HOT 2
- Not working. After connect charger battery charging. ASUS TUF Gaming F17 FX706HE_FX706HE 1.0 HOT 2
- issue: when i run " # ./bat --threshold" HOT 1
- Request procedure how to update the app HOT 5
- Use system call to retrieve the Linux kernel version
- Run CI checks in parallel
- feat: battery health command HOT 18
- issue: 目前本人用thinkpad t15g gen1 移动工作站,以后可能换dell precision,请贵编以后加强下dell HOT 1
- feat: replace dependency on Bash with /bin/sh for cross-platform compatibility
- Not working on Asus Zenbook with Ubuntu 23.04 HOT 6
- build: create additional Make targets
- issue: charge threshold not working after waking up from sleep HOT 19
- build: package bat for NixOS HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bat.