Hi all,
I want to make a custodian-protected, remotely-controlled service switcher but there's something wrong with my code. The behaviour isn't reliable and it leaves traces behind filling the memory eventually. I've included the code below.
TBH, I may have a less optimal approach to it in the first place, so I'd appreciate any better suggestions. A little background: As part of Liitin (liitin.org) IoT development and dog-fooding, I've decided to make my personal A.I. project running on a remotely-controllable Liitin node as a "Iot Service". Any nodes fired up will be automagically visible on my Liitin desktop. Any A.I. node or the user node can be behind different firewalls without open ports. Neither do they need to know each other's whereabouts. One A.I. node is to work as an interactive service whereas the rest will take part in incubating higher intelligence through genetic programming. I have a simple IoT communication channel in place, but now I want a reliable means to switch the service mode remotely. I don't want any ill-behaved A.I. processes running wild either, so I want to make sure I can shut down the processes remotely when I want to, so the services will need to be sandboxed. Foremost this is an IoT dog-fooding excercise, trying to make any Liitin SW or HW node as easy and secure to use as possible for the basic users, now only taking it to one extreme.
Finally to the switcher source code... br, jukka --- ;;; tested in linux. Otherwise the test program needs to be changed #lang racket ;; The user only needs to change the target mode (define target-mode #f); #f/ "service-1"/ "service-2" (define (service-switcher) (define current-mode #f) (define reset-needed? #f); custodian-shutdown-all (define loop (lambda () (define cust (make-custodian)) (parameterize ((current-custodian cust) (current-namespace (make-base-namespace))) (thread (lambda () (current-subprocess-custodian-mode 'kill) (subprocess-group-enabled #t) (display 1) (cond ((equal? current-mode target-mode) (begin (display 2) (sleep 3) (loop))) ((and (equal? current-mode #f) (equal? target-mode "service-1")) (begin (display 3) (system "gedit") (set! current-mode "service-1") (sleep 5) (loop))) ((and (equal? current-mode #f) (equal? target-mode "service-2")) (begin (display 4) (system "gedit") (set! current-mode "service-2") (sleep 5) (loop))))))) (display 5) (sleep 10) (when (not (equal? current-mode target-mode)) (begin (display 6) (custodian-shutdown-all cust) (sleep 5) (set! current-mode #f) (loop))) (display 7)(newline) (sleep 5) (loop))) (thread (lambda () (loop))) (display "Service switcher started")(newline)) ;; testing (service-switcher) (sleep 10) (set! target-mode "service-1") (sleep 10) (set! target-mode #f) (sleep 10) (set! target-mode "service-2") (sleep 10) (set! target-mode #f) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.