Alby24 Posted August 14, 2021 Share Posted August 14, 2021 Hi there, I am trying to run a custom command whenever the power button of the server is pressed. In particular, I'm looking for a docker run command. I found at this page that one way to do that is sysctl -w kernel.poweroff_cmd="/sbin/powerdown" So I replaced "/sbin/powerdown" with "docker run ..." But it is not working and the system is shutting down normally. The page also says that: Quote Some motherboards support this, and some don't. Try it and see. Guess mine doesn't. Is there any other way to do this? Quote Link to comment
Alby24 Posted August 16, 2021 Author Share Posted August 16, 2021 So...Nobody? I started messing up with /etc/acpi/acpi_handler.sh and I have replaced "/sbin/init 0" with "docker run ... " The system does not turn off anymore when I press the power button, but the docker command isn't being executed either. I do not know how this works and how to debug it, so any help will be appricated. Quote Link to comment
SimonF Posted August 16, 2021 Share Posted August 16, 2021 14 minutes ago, Alby24 said: So...Nobody? I started messing up with /etc/acpi/acpi_handler.sh and I have replaced "/sbin/init 0" with "docker run ... " The system does not turn off anymore when I press the power button, but the docker command isn't being executed either. I do not know how this works and how to debug it, so any help will be appricated. You may need to include the full path which docker should provide full path Quote Link to comment
Alby24 Posted August 16, 2021 Author Share Posted August 16, 2021 (edited) Thanks for your repy. I see what you mean, I found out that docker is located at: EDIT: this is the right path /usr/bin/docker But I dont know the exact path to the executable. Isn't there a simple command that I can replace "/sbin/int 0" with, in order to see if this approach can work? Edited August 16, 2021 by Alby24 Quote Link to comment
SimonF Posted August 16, 2021 Share Posted August 16, 2021 14 minutes ago, Alby24 said: /var/lib/docker This is the full path Quote Link to comment
Alby24 Posted August 16, 2021 Author Share Posted August 16, 2021 But when I try to run a command like: /var/lib/docker run alpine:latest This is shown: bash: /var/lib/docker: Is a directory And nothing is executed Quote Link to comment
SimonF Posted August 16, 2021 Share Posted August 16, 2021 Is /usr/bin/docker on my system. Quote Link to comment
Alby24 Posted August 16, 2021 Author Share Posted August 16, 2021 2 hours ago, SimonF said: Is /usr/bin/docker on my system. Yes you are correct, now I can use the command. Anyway it doesn't seem like it is being executed when I press the power button. Does acpi logs anything? Here is my entire acpi_handler.sh script: #!/bin/sh # Default acpi script that takes an entry for all actions IFS=${IFS}/ set $@ case "$1" in button) case "$2" in power) /usr/bin/docker pull alpine:latest ;; *) logger "ACPI action $2 is not defined" ;; esac ;; *) # logger "ACPI group $1 / action $2 is not defined" ;; esac Quote Link to comment
itimpi Posted August 17, 2021 Share Posted August 17, 2021 Have you tried adding a ‘logger’ command in front of the ‘docker run’ one, and another one after so you get entries into the syslog? That would at least confirm that point is being reached and the command tried. Not sure if you should also redirect any output from the docker run command anywhere to see if is failing for some reason Quote Link to comment
Alby24 Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) Man if you aren't sure, I really don't know what to do, I know very little about this syntax. Do you mean writing something like this? case "$2" in power) logger "before run" && /usr/bin/docker pull alpine:latest && logger "after run" ;; Plus, where can I find the log? Thanks again. Edited August 17, 2021 by Alby24 Quote Link to comment
itimpi Posted August 17, 2021 Share Posted August 17, 2021 4 minutes ago, Alby24 said: Man if you aren't sure, I really don't know what to do. Do you mean writing something like this? case "$2" in power) logger "before run" && /usr/bin/docker pull alpine:latest && logger "after run" ;; Plus, where can I find the log? Thanks again. You can put them on separate lines so they get executed in order (as long as they are all before the ;; that terminates the case. The syslog is accessible via the 'Log' icon at the top right of the Unraid GUI. You can bring it up before pressing the power button and thus see the entries appearing if they are being executed Quote Link to comment
Alby24 Posted August 17, 2021 Author Share Posted August 17, 2021 I tried as you said and I believe nothing is being logged at all. I don't really know what to say... Quote Link to comment
itimpi Posted August 17, 2021 Share Posted August 17, 2021 1 hour ago, Alby24 said: I tried as you said and I believe nothing is being logged at all. I don't really know what to say... That implies that the code is not being reached in the first place. Quote Link to comment
Alby24 Posted August 17, 2021 Author Share Posted August 17, 2021 (edited) Indeed, and that is weird, since the standard "/sbin/init 0" was being reached. Plus, the system doesnt shut down with the button anymore, that implies that I have modified the correct file. We're missing something for sure, but I have no idea what Edited August 17, 2021 by Alby24 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.