From 01c56d381ff5bb4bd511d98691c0980e956ed0b0 Mon Sep 17 00:00:00 2001 From: Zhengyi Jiang Date: Wed, 8 Nov 2023 21:53:05 +0000 Subject: [PATCH] added kill, restart options --- autostart/autostart.sh | 83 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/autostart/autostart.sh b/autostart/autostart.sh index 18a49a7..73b2127 100755 --- a/autostart/autostart.sh +++ b/autostart/autostart.sh @@ -1,5 +1,86 @@ #!/bin/bash +kill_auxiliary() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_auxiliary | head -1 | awk '{print $2}'` + kill ${pid} +} + +kill_camera() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_camera | head -1 | awk '{print $2}'` + kill ${pid} +} + +kill_reach() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_reach | head -1 | awk '{print $2}'` + kill ${pid} +} + +kill_slam() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_slam | head -1 | awk '{print $2}'` + kill ${pid} +} + +kill_unitree_base() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_unitree_base | head -1 | awk '{print $2}'` + kill ${pid} +} + +kill_roscore() { + pid=`ps ux | grep -v grep | grep "bash -c" | grep launch_roscore | head -1 | awk '{print $2}'` + kill ${pid} +} + +if [[ $1 == "-h" ]]; then + echo "Usage: $0" + echo "This script is used to launch all the necessary nodes for the ICE9 project." + echo "It is meant to be run on startup." + echo " -h, --help display this help and exit" + echo " -l, --log display log and exit" + echo " -ka, --killall kill all processes launched by autostart" + echo " -k [name], --kill [name] kill a specific process launched by autostart" + echo " [name] can be one of the following:" + echo " auxiliary, camera, reach, slam, unitree_base, roscore" + echo " -r, --restart restart all processes launched by autostart" + exit 0 +elif [[ $1 == "-l" || $1 == "--log" ]]; then + cat ${HOME}/Unitree_GPS_Integration/autostart/.log + exit 0 +elif [[ $1 == "-ka" || $1 == "--killall" ]]; then + kill_auxiliary + kill_camera + kill_reach + kill_slam + kill_unitree_base + kill_roscore + exit 0 +elif [[ $1 == "-k" || $1 == "--kill" ]]; then + if [[ $2 == "auxiliary" ]]; then + kill_auxiliary + elif [[ $2 == "camera" ]]; then + kill_camera + elif [[ $2 == "reach" ]]; then + kill_reach + elif [[ $2 == "slam" ]]; then + kill_slam + elif [[ $2 == "unitree_base" ]]; then + kill_unitree_base + elif [[ $2 == "roscore" ]]; then + kill_roscore + else + echo "Error! Unknown process name." + exit 1 + fi + exit 0 +elif [[ $1 == "-r" || $1 == "--restart" ]]; then + kill_auxiliary + kill_camera + kill_reach + kill_slam + kill_unitree_base + kill_roscore +fi + + log_file=${HOME}/Unitree_GPS_Integration/autostart/.log log() { printf "[%-12.12s]: %s\n" "main" "$1" >> ${log_file} @@ -7,7 +88,7 @@ log() { } export SUDO_ASKPASS=${HOME}/Unitree/autostart/passwd.sh -ice9_scripts=/home/unitree/Unitree_GPS_Integration/autostart +ice9_scripts=${HOME}/Unitree_GPS_Integration/autostart mv ${log_file} ${log_file}.backup log "ICE9 autostart list started."