How can I invoke poweroff from a script/process?

Posted November 5, 2021 124 views
Linux CommandsDigitalOcean Droplets

I’d like for my droplet image to do the following:

  • Boot Ubuntu 20
  • Start a process (using services.d or whatever)
  • When the process finishes, invoke poweroff
  • For the droplet to truly power off

I haven’t been able to make this work. The poweroff command works from the CLI, if I am logged in as a user, even if the user is not a sudoer.

But if noone is logged onto the CLI, and the task finishes without a user being logged into the shell, the poweroff command appears to have no effect.

How do I power off a droplet programmatically from a bash script?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer
Show answer This answer has been marked as resolved by jorisw.