From fa1bb0b548c400d0074fa28699e5924935f09207 Mon Sep 17 00:00:00 2001
From: Erik von Reis <evonreis@caltech.edu>
Date: Wed, 23 Mar 2022 13:18:21 -0700
Subject: [PATCH] startup sequencer: delay units now delay during shutdown

delay units now delay some amount during shutdown.
the delay during shutdown is configured as a separate value from the startup delay
---
 src/python/rtcds/fe_generator/sequencer.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/python/rtcds/fe_generator/sequencer.py b/src/python/rtcds/fe_generator/sequencer.py
index 0a80c990f..b306d60bd 100644
--- a/src/python/rtcds/fe_generator/sequencer.py
+++ b/src/python/rtcds/fe_generator/sequencer.py
@@ -42,10 +42,10 @@ class Sequencer(object):
                 self.processes.binds_to(dolphin_drivers.first_service, dolphin_port.start)
 
                 before_world.append(dolphin_port)
-                before_world.append(self.delay(15, "dolphin_port"))
+                before_world.append(self.delay(15, 5, "dolphin_port"))
             before_world.append(dolphin_drivers)
             klog("dolphin drivers added")
-        before_world.append(self.delay(30, "startup"))
+        before_world.append(self.delay(30, 10, "startup"))
         if self.options["HAS_EPICS_ONLY_MODELS"]:
             world.append(self.processes.epics_only_models(self.options["EPICS_ONLY_MODELS"]))
             models = True
@@ -71,9 +71,9 @@ class Sequencer(object):
     def create_cdsrfm_start_sequence(self, front_end_processes, cdsrfm_processes):
         before_world = [
             front_end_processes.dolphin_port(),
-            self.delay(15, "dolphin_port"),
+            self.delay(15, 5, "dolphin_port"),
             front_end_processes.dolphin_drivers(),
-            self.delay(30, "startup"),]
+            self.delay(30, 10, "startup"),]
         world = [
             cdsrfm_processes.module(),
             cdsrfm_processes.epics(),
@@ -103,15 +103,19 @@ class Sequencer(object):
             self.end = unit_name
             self.first_service = unit_name
 
-    def delay(self, time_s, name):
+    def delay(self, start_time_s, stop_time_s, name):
         file_name = f"rts-delay-{name}.service"
         file_path = path.join(self.target_dir, file_name)
         with open(file_path, "wt") as f:
             f.write(f"""[Unit]
-Description=Delay for {time_s} seconds
+Description=Delay for {start_time_s} seconds
 
 [Service]
-ExecStartPre=/bin/sleep {time_s}
-ExecStart=/bin/echo 'finished waiting for {name}'
+Type=oneshot
+RemainAfterExit=yes
+ExecStartPre=/bin/sleep {start_time_s}
+ExecStart=/bin/echo '[startup] finished waiting for {name}'
+ExecStop=/bin/sleep {stop_time_s}
+ExecStopPost=/bin/echo '[shutdown] finished waiting for {name}' 
 """)
         return self.Delay(file_name)
-- 
GitLab