# Best way to shut down programmatically - poweroff?

**URL:** <https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413>\
**Category:** Services\
**Created:** [February 27, 2019, 6:10am UTC](https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413 "2019-02-27T06:10:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdots83](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jdots83](https://mangoh.discourse.group/u/jdots83)\
**Post date:** [February 27, 2019, 6:10am UTC](https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413/1 "2019-02-27T06:10:28Z")

</div>

Using the cli, # poweroff does exactly what I want: a total power-down.  
I have seen other posts that describe using system(“poweroff”) in app-code.  
But my Wp7601 with Legato 18.08 doesn’t seem to include it.

I entered these lines into my app:  
system(“pwd”);  
system(“ls”);  
system(“poweroff”);  
The first two linux system calls result in a reasonable output as shown below, but the “poweroff” call is not found.

Has it been replaced?

Feb 27 05:54:49 swi-mdm9x28 user.info Legato: INFO | maxTrack[1485] | /legato/systems/current/appsWriteable/maxTracker  
Feb 27 05:54:49 swi-mdm9x28 user.info Legato: INFO | maxTrack[1485] | bin dev etc lib sys usr

Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] | sh:  
Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] | poweroff: not found  
Feb 27 05:54:49 swi-mdm9x28 user.err Legato: =ERR= | maxTrack[1485] |

---

<div class="post-metadata">

**Author:** ![jdots83](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jdots83](https://mangoh.discourse.group/u/jdots83)\
**Post date:** [February 27, 2019, 7:04am UTC](https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413/2 "2019-02-27T07:04:33Z")

</div>

Ok, that was an easy one.  
system("/sbin/poweroff -f");  
is a line that works for me.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [March 5, 2019, 10:50pm UTC](https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413/3 "2019-03-05T22:50:21Z")

</div>

Can I ask why you’re trying to programmatically power off? There won’t be any way to power back on again without physically interacting with the unit right? Is that ok?

---

<div class="post-metadata">

**Author:** ![jdots83](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jdots83](https://mangoh.discourse.group/u/jdots83)\
**Post date:** [February 21, 2020, 12:34am UTC](https://mangoh.discourse.group/t/best-way-to-shut-down-programmatically-poweroff/2413/4 "2020-02-21T00:34:55Z")

</div>

Hello @dfrey, I just saw your reply. Sorry to be late but to finish the story for others:  
We have a battery powered product that is also a consumer product. Consumers being capable of anything, they will surely run the thing until it dies before thinking to plug it in for re-charge of the battery. My goal was to get a clean, graceful shutdown, which will remain off until the user plugs in to charge. So I monitor the V and when it drops below 3.4 I shutdown. There is hysteresis built into the hardware to delay starting up again until V is back up to 3.7.
