Skip to content

Add a non-interactive function to use softioc in deamon mode #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

XavSPM
Copy link

@XavSPM XavSPM commented Mar 21, 2024

I propose adding the non_interactive_ioc function to allow the use of softioc in daemon mode. This mode can, for example, be used with systemd. It is compatible with asyncio and cothread.

To ensure that information is correctly logged in the journal, it is recommended to execute the Python script with the -u option or to set the environment variable PYTHONUNBUFFERED=TRUE.

Here is an example of a service:

[Unit]
Description=IOC
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/opt
ExecStart=/opt/softioc/bin/python -u /opt/example.py
Environment="PATH=/opt/softioc/bin"
Restart=always

[Install]
WantedBy=multi-user.target

And an example of a script:

# Import the basic framework components.
from softioc import softioc, builder
import cothread

# Set the record prefix
builder.SetDeviceName("MY-DEVICE-PREFIX")

# Create some records
ai = builder.aIn('AI', initial_value=5)
ao = builder.aOut('AO', initial_value=12.45, on_update=lambda v: ai.set(v))

# Boilerplate to get the IOC started
builder.LoadDatabase()
softioc.iocInit()

# Start processes required to be run after iocInit
def update():
    while True:
        ai.set(ai.get() + 1)
        print(ai.get())
        cothread.Sleep(1)

cothread.Spawn(update)

if __name__ == "__main__":
    softioc.non_interactive_ioc()

@AlexanderWells-diamond
Copy link
Collaborator

Apologies, there's another PR under discussion at the moment that will significantly change the AsyncioDispatcher: #138. It would probably be best to wait until that one is merged before thinking about this one, as it will require refactoring.

@XavSPM
Copy link
Author

XavSPM commented Mar 26, 2024

Noted. I'm waiting for merger #138.

Do you think there will be many changes to make following the merger?

@AlexanderWells-diamond
Copy link
Collaborator

The other PR has now been merged. There is a conflict that will need fixing.

device.dispatcher.wait_for_quit()
safeEpicsExit(0)
else:
print("No dispatcher found")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the end-of-file newline

@XavSPM
Copy link
Author

XavSPM commented Apr 12, 2024

Hello, @AlexanderWells-diamond

I created another pull request (#156) following merger #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants