I’m currently testing the new script you provided. I modified it a little.
#!/usr/bin/env python
import rospy
import os
from threading import Timer
from std_msgs.msg import Bool
from std_srvs.srv import Empty, EmptyRequest, EmptyResponse
from ros_jetson_stats.srv import fan, fanRequest
def preshutdown():
rospy.loginfo("pre-shutdown command invoked")
relay1_pub = rospy.Publisher("relay1", Bool, queue_size=1)
relay2_pub = rospy.Publisher("relay2", Bool, queue_size=1)
relay_msg = Bool()
relay_msg.data = True
relay1_pub.publish(relay_msg)
relay2_pub.publish(relay_msg)
try:
rospy.logdebug("Setting fan to manual speed: 0")
rospy.wait_for_service("/jtop/fan", 2)
msg = fanRequest()
msg.mode = "manual"
msg.fanSpeed = 0
resp = fan_srv(msg)
except rospy.ROSException as e:
rospy.logerr(e)
try:
rospy.logdebug("Stopping the LiDAR motor")
rospy.wait_for_service('/stop_motor', 2)
stop_motor = rospy.ServiceProxy('/stop_motor', Empty)
resp = stop_motor(EmptyRequest())
except rospy.ROSException as e:
rospy.logerr(e)
def jetson_reboot(req):
rospy.logdebug("Reboot timer starting")
reboot_timer.start()
return EmptyResponse()
def jetson_shutdown(req):
preshutdown()
rospy.logdebug("Shutdown timer starting")
shutdown_timer.start()
return EmptyResponse()
def do_reboot():
os.system("shutdown -r now")
def do_shutdown():
os.system("shutdown -h now")
def initialise():
rospy.wait_for_service("/jtop/fan", 5)
global fan_srv
fan_srv = rospy.ServiceProxy("/jtop/fan", fan)
msg = fanRequest()
msg.mode = "default"
resp = fan_srv(msg)
reboot_timer = Timer(3.0, do_reboot)
shutdown_timer = Timer(3.0, do_shutdown)
rospy.init_node("leo_system_jetson", log_level=rospy.DEBUG)
initialise()
reboot_srv = rospy.Service("/leo_system/jetson_reboot", Empty, jetson_reboot)
shutdown_srv = rospy.Service("/leo_system/jetson_shutdown", Empty, jetson_shutdown)
rospy.loginfo("Jetson system node started!")
rospy.spin()
I get the following error when my script gets to the os.system("shutdown -r now")
call.
Failed to set wall message, ignoring: Interactive authentication required.
Failed to reboot system via logind: Interactive authentication required.
Failed to open /dev/initctl: Permission denied
Failed to talk to init daemon.
I’m guessing there’s a permission error somewhere but I can’t seem to locate where.
EDIT: I found part of the solution here: Non-interactive shutdown from ssh - #10 by alciregi - Ask Fedora.
I then needed to add sudo
in the reboot and shutdown service of my jetson script.