How to properly stop a bot

19 views
Skip to first unread message

Carl Ranson

unread,
Jul 17, 2018, 5:53:29 AM7/17/18
to gobotio

Hey all, 

Since my bot is running a headless pi I wanted a way to nicely shut it down. 

I think i've found gobot code to shutdown a pi, but its unclear how to call it from within a bot. 

what I want to do is something like 

joystickDriver.On("stop", func( data interface{} ) {

    bot.shutdown()
    <code here to trigger shutdown of the pi itself>

})

is it possible to cause a shutdown of the bot (and all of its goroutines) from within one of its goroutines?

thanks in advance, 
CR

Carl Ranson

unread,
Jul 19, 2018, 5:49:03 AM7/19/18
to gobotio
Cracked it

I used os.Exit(0) to terminate the go program (probably not that clean but never mind)
Then i had my startup script issue a shutdown +1 command which will cleanly shutdown the pi after a minute. 

This means I can now boot and exit the bot without a vnc connection or monitor
Reply all
Reply to author
Forward
0 new messages