האם ניתן להוסיף שירות runit בתוסף?

סיכום מבוסס בינה מלאכותית

In a discussion about adding a runit service within a Discourse plugin, spirobel asks if it’s possible to run a long-running C++ daemon alongside Discourse with auto-restart. merefield suggests installing services via app.yml or using Rails jobs, which spirobel finds cumbersome, preferring plugin-only solutions. merefield defends app.yml as a stable, Docker-compose-like pattern, citing successful use in the Discourse Frotz plugin. pfaffman differentiates between services “next to” Discourse (best in app.yml) and those “started by” Discourse (better as jobs), mentioning long-running Ansible tasks via jobs. schleifer clarifies that runit services cannot be managed from within a plugin because the discourse user lacks container-level permissions. Instead, they recommend running the service in a separate Docker container on the same host, exposing it via a TCP port, and configuring the connection URL through the env: block in app.yml (e.g., CUSTOM_SERVICE_URL: 'localhost:5309'), which the plugin can then read via ENV["CUSTOM_SERVICE_URL"]. This approach ensures isolation, reliability, and compatibility with Discourse’s containerized architecture.

Hi, I was wondering if it is possible to add an runit service in a plugin? If thats not possible I would be glad to hear about your strategies to deal with this kind of issue: I have a long running cpp program that needs to run next to discourse. It should be restarted automatically and basically behave like a daemon. thaaanks

You can install stuff within app.yml and run system commands within rails to check and execute stuff. You could wrap a despatcher in a regular job?

this is really cumbersome. Ideally everything happens in the plugin.
thank you for your answer. :slight_smile: :+1:

The pattern seems the correct one to me as the templates are like docker composers.

I use this to clone and make dumb frotz in the Discourse Frotz plugin. It’s rock solid.

For some long running jobs in a plugin I wrote I used the jobs interface to crank up some ansible tasks that can take hours to complete.

But if it’s “next to” then a template in the app.yml seems appropriate ; if it’s “started by Discourse” then a job makes sense.

It is not. Inside the container all plugin code runs as the discourse user. That user does not have sufficient permissions (inside the container again) to control runit services.

Run the process in another Docker container on the same hardware. It should listen on a local TCP port. Export the URL to connect to the other service in the env: block in app.yaml, e.g.:

env:
    CUSTOM_SERVICE_URL: 'localhost:5309'

Have the plugin find the connection string via ENV["CUSTOM_SERVICE_URL"]