Is there an event I can use to run `sudo shutdown -h now` on my server?
I try to shutdown the Raspberry Pi running the Virtual Server before I power down. I can do this by sshing in, but something that I could trigger from the client (UI) woud be helpful.
I know that the event system is locked down a bit ... and there are risks to opening it up. I'd be OK with that risk....
.
The only callbacks that you can use are these
You can put whatever you want in the config.ini file to call (you just cant set it from the client remotely for security reasons)
So for example if you could hook the onServerRename event and call a script to shutdown now. Like this
1. Stop and exit the virtualhere server process (sudo pkill vhusbdarm)
2. Edit the config.ini file using vi or your favorite editor and add the line
onServerRename=/home/pi/shutdown.sh
3. Save the config.ini file
#!/bin/sh shutdown -r now4. Create a new file called shutdown.sh in the /home/pi directory
5. Add this to it
6. Then save shutdown.sh and
chmod +x /home/pi/shutdown.sh
7. Now start the client and server, and right click on the server to rename it, put in any name it it will run that script to restart
What you can try instead is a
What you can try instead is a button connected to some GPIO pins on the Pi. Then use a library like gpiozero to make a python script. It will watch for the button press and shut down the pi. Then you can run that script as a service, so it just runs in the background. Just search for gpiozero. There should be some examples showing how to send a shutdown command. This is how I shut down my Pi4 without logging into it.
The rename event is brilliant
The rename event is brilliant! Thanks.
Also thanks on the gpio button. I have one and was looking for a soft shutdown method.