From 2bd9e7c93d65fb2086689cc8d51e1ca8950746dc Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Mon, 3 Oct 2022 20:01:07 +0900 Subject: [PATCH] supervisor does not have pre-stop like upstart, so we need to call /usr/sbin/@(name)-stop explictly when the @(name)-start script receives TERM signal --- src/robot_upstart/install_script.py | 1 + src/robot_upstart/job.py | 5 ++++- templates/job-start.em | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/robot_upstart/install_script.py b/src/robot_upstart/install_script.py index f238f40..a5cb547 100644 --- a/src/robot_upstart/install_script.py +++ b/src/robot_upstart/install_script.py @@ -92,6 +92,7 @@ def main(): name=job_name, interface=args.interface, user=args.user, workspace_setup=args.setup, rosdistro=args.rosdistro, master_uri=args.master, log_path=args.logdir, + sigterm_stop=(args.provider=='supervisor'), systemd_after=args.systemd_after, supervisor_priority=args.supervisor_priority) diff --git a/src/robot_upstart/job.py b/src/robot_upstart/job.py index 5062888..561680d 100644 --- a/src/robot_upstart/job.py +++ b/src/robot_upstart/job.py @@ -40,7 +40,7 @@ class Job(object): """ Represents a ROS configuration to launch on machine startup. """ def __init__(self, name="ros", interface=None, user=None, workspace_setup=None, - rosdistro=None, master_uri=None, log_path=None, + rosdistro=None, master_uri=None, log_path=None, sigterm_stop=None, systemd_after=None, supervisor_priority=None): """Construct a new Job definition. @@ -109,6 +109,9 @@ def __init__(self, name="ros", interface=None, user=None, workspace_setup=None, # of the generated Supservisor conf file self.supervisor_priority = supervisor_priority or 200 + # call @(name)-stop script when received TERM signal + self.sigterm_stop = sigterm_stop + # Set of files to be installed for the job. This is only launchers # and other user-specified configs--- nothing related to the system # startup job itself. List of strs. diff --git a/templates/job-start.em b/templates/job-start.em index d69fd03..e31a96b 100644 --- a/templates/job-start.em +++ b/templates/job-start.em @@ -107,6 +107,13 @@ fi setpriv --reuid @(user) --regid @(user) --init-groups roslaunch $LAUNCH_FILENAME @(roslaunch_wait?'--wait ')& PID=$! +@[if sigterm_stop]@ +_term() { + /usr/sbin/@(name)-stop +} +trap _term SIGTERM +@[end if] + log info "@(name): Started roslaunch as background process, PID $PID, ROS_LOG_DIR=$ROS_LOG_DIR" echo "$PID" > $log_path/@(name).pid