Skip to content

Commit

Permalink
supervisor does not have pre-stop like upstart, so we need to call /u…
Browse files Browse the repository at this point in the history
…sr/sbin/@(name)-stop explictly when the @(name)-start script receives TERM signal
  • Loading branch information
k-okada committed Oct 3, 2022
1 parent 99644c4 commit 2bd9e7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/robot_upstart/install_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion src/robot_upstart/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions templates/job-start.em
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2bd9e7c

Please sign in to comment.