DiamondLightSource / procServControl

EPICS/CA control of running procServ instances
Apache License 2.0
1 stars 0 forks source link

Cleanly exit IOC when stopping IOC execution #2

Open gguyotte opened 1 year ago

gguyotte commented 1 year ago

Currently, stopping an IOC only terminates the IOC process, but does not allow for that IOC to gracefully shutdown. In some cases, it would be preferable to issue the 'exit()' command at the EPICS shell prior to forcefully terminating the process.

In my experience this is necessary for certain IOCs which are controlling hardware, e.g. camera hardware. I have a concrete example of a failure we experience at SNS. A camera IOC makes a connection to the SDK/API supplied as a shared library by the camera vendor (ANDOR). If the connection is not closed properly, the next attempt to connect to the camera will fail. Issuing the exit() command at the EPICS shell would allow the opportunity for the IOC to 'clean up' by closing the camera instance properly via the vendor API.

coretl commented 1 year ago

This sounds like a useful addition, I never added it because of the complexity of having to work out if the exit had succeeded and CTRL-X it if it didn't. Can you think of a way to do this? Happy to accept a PR for this behaviour.

gguyotte commented 1 year ago

My thinking is that we could have a timeout PV rather than any positive acknowledgement of exit success. If the timeout PV value is 0, the current behavior is in charge, otherwise emit exit() to the IOC shell, wait out the timeout, and then bang CTRL-X.

One thing I haven't worked out is how we can emit characters to the IOC shell from the .st file.....not sure if printf() would be the best mechanism for that, or is there something more clever.

On Mon, Dec 19, 2022 at 4:47 AM Tom C (DLS) @.***> wrote:

This sounds like a useful addition, I never added it because of the complexity of having to work out if the exit had succeeded and CTRL-X it if it didn't. Can you think of a way to do this? Happy to accept a PR for this behaviour.

— Reply to this email directly, view it on GitHub https://github.com/dls-controls/procServControl/issues/2#issuecomment-1357371886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4GYYLMNL6WIMHZ5OJ72GLWOAVLDANCNFSM6AAAAAATBIUQKE . You are receiving this because you authored the thread.Message ID: @.***>

coretl commented 1 year ago

My thinking is that we could have a timeout PV rather than any positive acknowledgement of exit success. If the timeout PV value is 0, the current behavior is in charge, otherwise emit exit() to the IOC shell, wait out the timeout, and then bang CTRL-X.

The only issue with this approach is that exit() will cause the IOC to restart if auto-restart is on, so we'd have to detect if it restarted during the timeout so we didn't double restart it

One thing I haven't worked out is how we can emit characters to the IOC shell from the .st file.....not sure if printf() would be the best mechanism for that, or is there something more clever.

You can do something like https://github.com/dls-controls/procServControl/blob/fb8423c4fc6d51f1ce3954f88aa13fe800fc8ae6/procServControlApp/src/procServControl.st#L343-L360