You could use channels (well, ASGI, it's lower-level interface) for the
interconnect:

 - Use channels for signals from the web service to the controller daemon
(maybe "service.stop" or "service.start" with the service name in the
message payload). You can trigger these from simple AJAX or GET views, no
need for websocket here.
 - Send the log continuously out to a Group as it's received, one group per
service. Then, when someone joins and wishes to tail the log, tie in their
socket to the group.

However, this does not supply log playback of lines before a client joins,
so you'd have to fill in that gap. In the end, you're probably looking at
some sort of datastore in the middle there to store logs and then replay
them into a socket as it joins.

Andrew

On Tue, Nov 15, 2016 at 2:27 PM, <psaod8fz...@gmail.com> wrote:

> Hi there,
>
> I want to develop a Django site where users have the possibility to
> interact with systemd services in realtime and to see the log output in
> realtime.
>
> I sketched up a quick draft on my idea how this could work:
> https://i.imgur.com/pd5uLtl.jpg
>
>
> One simplified use-case would be:
>
>   1. User visits Django website.
>   2. User chooses one of many systemd services. each service would be
> represented by a single webpage, eg. /services/id/1, /services/id/2...
>   3. User gets presented a realtime log, the source being either journald
> or lastlog-file on the file system.
>   4. User clicks on Stop button.
>   5. Service gets stopped.
>   6. User receives exit codes, etc. in a readable format.
>   7. User clicks on start button
>   8. User receives exit codes (started successfully/failed/etc) in a
> readable format.
>   9. User leaves Django website.
>
> I wrote a simple Controller (MyController.py) that connects to the systemd
> interface of the dbus, to controllthe systemd services and listen for
> property changes, but also to read logfiles from the file system. I inteded
> MyController to run as root and sit between Django and dbus/systemd.
>
> I would think WebSockets are the best solution to deal with the realtime
> log display in 3) and with the live interaction in 4) 5) 6) 7) and 8).
> I recently read about Django Channels and I believe this would be the
> solution to Django<----(WebSocket)----->User.
>
> But somehow Django needs to talk to my MyController.py daemon for starting
> and stopping, as well as getting the systemd exit codes across to the User
> in realtime.
> I believe I cannot use xmlrpc, because that is a pure Request<->Response
> principle. But a live log is continuous, and if you start a service, that
> could take ten seconds and I really want to have quick response times. I
> also thought about background job management, but I prefer WebSockets over
> this, so I don't have to implement multiple technologies.
>
> My question would be this: Could I somehow use Channels to connect
> MyController with Django and vice versa, similar to xmlrpc but so that both
> sides can send?
>
> I am open for all ideas at this point, but I prefer to implement only one
> kind of technology if that would be possible.
>
> Thanks in advance!
>
> psaodwhatevermynameis.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/4224be09-059f-42e5-8352-b3aad34bf5b7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4224be09-059f-42e5-8352-b3aad34bf5b7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uph7BpWtG95OsTuwKp0sr1Hw1fhdYMf8dKuuK3R9OP1jA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to