Just to add to the answer by @FooBar (ROS nodes are really just regular Linux programs that have chosen to communicate with each other via the ROS middleware): shutting down a Linux system with a desktop environment is often possible without using something like shutdown
(which requires special privileges). See "Linux: Programatically shutdown or reboot computer from a user-level process" on stackoverflow for an example where they use ConsoleKit / DBus:
dbus-send \
--system \
---dest=org.freedesktop.ConsoleKit \
--type=method_call \
--print-reply \
--reply-timeout=2000 \
/org/freedesktop/ConsoleKit/Manager \
org.freedesktop.ConsoleKit.Manager.Stop
You could invoke dbus-send
using the system(..)
function call in C/C++, or execute it from a Python node.
For Python there are better (more integrated) ways to interface with ConsoleKit / DBus (copied from "shutting down computer (linux) using python" on stackoverflow):
import dbus
sys_bus = dbus.SystemBus()
ck_srv = sys_bus.get_object('org.freedesktop.ConsoleKit',
'/org/freedesktop/ConsoleKit/Manager')
ck_iface = dbus.Interface(ck_srv, 'org.freedesktop.ConsoleKit.Manager')
stop_method = ck_iface.get_dbus_method("Stop")
stop_method()
You could fi wrap the call to stop_method()
(which is just an example) in a ROS service call (I wouldn't use parameters for this, it is clearly a synchronous action).
Originally posted by gvdhoorn with karma: 86574 on 2015-07-26
This answer was ACCEPTED on the original site
Post score: 4
Original comments
Comment by nwanda on 2015-09-28:
This raised another question: Is it possible to close all nodes from within another node? Since this system is controlling some motors I would like to send a command to stop the motors and close all nodes before shutting down.
Comment by gvdhoorn on 2015-09-29:
As you already said: this is another question. Please open a new one for that.
Comment by nwanda on 2015-09-29:
You are totally right. I have already posted a different question. Thanks for the help!