Arc Forumnew | comments | leaders | submitlogin
How to interact with a running arc instance?
1 point by SteveMorin 5116 days ago | 12 comments
Recently I have asked this question to a number of lisp folk and they have a number of strategies and lot of people default to using swank or screen.

How are people interacting with a arc instance after disconnecting your terminal? (You know bug fixes upgrades)



2 points by waterhouse 5112 days ago | link

Occasionally I have found the following method useful:

1. Have the Arc process running something like this:

  (while t
    (sleep .2)
    (awhen (car:errsafe:readfile "ARC_ORDERS")
      (pr "Input> ")
      write.it
      (prn)
      (rmfile "ARC_ORDERS")
      (write:eval it)
      (prn)))
2. When you want Arc to do something, write an Arc s-expression to the ARC_ORDERS file. (Note that you'll have to restart this pseudo-REPL if an error occurs; you could use something like 'on-err or 'after to make that happen.)

This might be a horrible hack, but it's awesome, and it presents a very easy interface--e.g. if you have a program that lets you bind keys to shell scripts, then you can have a shell script say, like, "echo '(do-this-stuff)' > ARC_ORDERS".

Obvious drawbacks: It's slow compared to, say, a function call from the Arc runtime (you wouldn't want to use this as your graphics backend), and if two or more programs try to use this interface, hell might ensue (though you could assign them their own individual ARC_ORDERS2 and so on files; you could even make the number be a process id if you wanted). But it'll work fine for certain applications, and you may find it useful.

-----

2 points by shader 5112 days ago | link

This is so similar in concept to what I'm doing with named pipes that I figured I ought to share it now:

First of all, you can create a named pipe in a directory with the command "mkfifo name".

Then, I have a shell script in mzscheme (should probably update to Racket soon) for launching arc that sets up the long running process with normal output redirected to a log file and a second repl redirected to two named pipes "in" and "out". The important part is

  (parameterize ((current-output-port (open-output-file "out" 'update))
                 (current-input-port (open-input-file "in"))
                 (current-error-port (current-output-port)))
                (file-stream-buffer-mode (current-output-port) 'none)
                (tl))
which could be written either in arc or Racket. In arc, it would probably be:

  (w/stdin (infile "in")
    (w/stdout (outfile "out")
      ($:tl)))    ;whatever method you use to get to racket and call the repl
I'm not sure if that would work as well, since as far as I know there is no method in arc for setting the filestream buffer mode to 'none. If you have any issues, just use the racket version above.

Anyway, once you have the pipes set up, you can echo and cat them like any other file. The main difference being that they are treated exactly like a normal repl, and shouldn't have the overhead of sleeping and reading/erasing a file. I use a shell script to connect to them as a repl most of the time:

  #! /bin/bash
  
  bash -c "cat <out &
  cat >in"
Pretty simple, and it gets the job done.

-----

3 points by thaddeus 5116 days ago | link

I do the same as akkartik.

There are many other options though... for example:

http://arclanguage.org/item?id=10604

-----

2 points by shader 5115 days ago | link

I've created a system with multiple named pipes that I can reconnect to if necessary, mainly because I was trying to get an fcgi interface to work with arc.

-----

4 points by akkartik 5116 days ago | link

I just don't disconnect my terminal. I run it over screen.

-----

1 point by SteveMorin 5113 days ago | link

Interesting I figured someone would have come up with a more advance solution

-----

1 point by shader 5113 days ago | link

I'm not sure exactly what you mean by "advanced solution."

What were you thinking of? How would you like to see it work? I'm sure we can figure out how to make it happen.

-----

1 point by thaddeus 5113 days ago | link

A more advanced option: http://tmux.sourceforge.net/

-----

1 point by evanrmurphy 5113 days ago | link

Nah, we're all simpletons. ;)

Have you used screen though? It's really quite an advanced solution itself IMO.

-----

2 points by SteveMorin 5107 days ago | link

I just started reading up on screen is a awesome solution. I am very surprised that I haven't heard of it before. The only thing don't like about this is that I can't then start the server with a arc equivalent of mysqld_safe which will restart it if it crashes. I would want to be able to have this for a production server. Wonder if it would be possible to scrape a script together that can do that while still dropping you into the repl, and still create a pid file. Any ideas because I usually just launch things like this in the background, which is easy to do.

-----

2 points by aw 5106 days ago | link

I wasn't quite able to tell from your description what is the missing piece for you: is it starting Arc inside of screen at server boot time, or restarting Racket/Mzscheme if it crashes?

I think what you want is for server boot to run screen, which runs a shell script that starts/restarts Arc, which writes its pid out to a pidfile. Does that sound about right? Each step in that process is pretty easy.

-----

1 point by SteveMorin 5113 days ago | link

I haven't used screen to be honest. I was thinking of something more like the swank implementation for lisp

-----