Arc Forumnew | comments | leaders | submitlogin
1 point by user2 5457 days ago | link | parent

OK I read the document on unix commandline still no luck.

I created the following arc command script:

[script start]

#! /bin/sh ## arc: launcher for Arc. Put this file in your $PATH and chmod +x it.

ARC_DIR="/home/user/arc3/" # change this, obviously

rlwrap mzscheme -qr ${ARC_DIR}as.scm $@ # $@ holds the list of cmdline args

# notice the mzscheme switch is "-qr" and not "-f" here

[script end]

I then created the following run-hacker-news.arc:

[script start]

#!/usr/bin/env arc

(load "news.arc")

(nsv)

[script end]

I then run this by:

./run-hacker-news.arc

I get the arc prompt, but nothing about the webserver listening on 8080. What am I doing wrong?



1 point by palsecam 5456 days ago | link

Did you also apply the patch? (http://arclanguage.org/item?id=10345)

Because I just tried, and something like:

  [script launch-asv.arc]
  #!/usr/bin/env arc
  (asv)
  [script end] 

  $ chmod +x launch-asv.arc && ./launch-asv.arc &
  [1] 2439
  $  # there is no "serving on 8080" message, but...
... go to http://localhost:8080/: "it's alive". So it's OK.

Anyway yes, Lisp is special, and the use of `screen' or the like may be better.

(n.b: if you don't launch the script in the background (no '&'), you see the message, and get no prompt. But you need to keep the terminal open.)

-----

1 point by user2 5456 days ago | link

No I hadn't applied the patch. I did the following:

[cmdline start]

linuxbox arc3 # patch -p1 < ../arc-unix.patch (Stripping trailing CRs from patch.) patching file ac.scm Hunk #1 succeeded at 1112 (offset -15 lines). (Stripping trailing CRs from patch.) patching file as.scm [cmdline end]

The patch did seem to apply but not perfectly.

Now I get:

[cmdline start]

linuxbox arc3 # ./run-hacker-news.arc reference to undefined identifier: empty?

[cmdline end]

which has (asv) in it just like your example script. If I call arc command script I get the same error. This is arc3.1.tar from ycombinator.com

Also what does (asv) do instead of (load "news.arc") (nsv)? I don't know lisp but will surely learn if I can get this running for starters.

How are generally other people running it detached? I didn't think it would require this many steps.

-----

1 point by palsecam 5456 days ago | link

> reference to undefined identifier: empty?

Strange, which version of mzscheme do you use (`mzscheme -v')? 'empty? is in the MzScheme base "scheme" module for me (MzScheme 4.2.1)!

Anyway, 'empty? is called only in as.scm, and you can actually leave this file unchanged for your case (I think). Just patch ac.scm.

> Also what does (asv) do instead of (load "news.arc") (nsv)?

'asv is used to start the "Appplication server" defined in "app.arc". App.arc is generic, and news.arc use/require it. I use it in the example to see if maybe it was a problem w/ news.arc specifically (and because I feel lazy about typing "(load ...)": app.arc is in the Arc "stdlib" (see the file "libs.arc"), and so is loaded by default).

'nsv is defined like this, in "news.arc":

   (def nsv ((o port 8080))
     [...]        ; do news-specific init stuff...
     (asv port))  ; relay to 'asv, which itself relays to 'serve (defined in srv.arc)
The "sv" in "asv" / "nsv" is for "serve".

> How are generally other people running it detached?

They don't: Arc is different :-D

---

Ah also, to start the news server in the background, no need of a script, you could use:

  $ echo '(nsv)' | arc news.arc - &
But assuming you use a slightly improved version of the (full) patch this time:

  in as.scm:

  -      (for-each (lambda (f) (aload f)) args)  ; ...execute them!
  +	 (for-each (lambda (f) (if (string=? f "-") (tl) (aload f))) args)
But you still need to leave the terminal opened. To fix that, I don't know you may use some Unix daemon-ization magic. It becomes specific to your needs. Are you trying to use the news.arc forum on a (distant) server?

Once again, consider `screen'. Arc has no Unix signal handling for instance, so an "Arc daemon" would not be "powerful". The only possible interaction would be to kill it (via `kill'). Better keep an eye on it, i.e: keep a REPL opened to manage your forum.

---

Have a look at http://arclanguage.org/formatdoc

-----

2 points by user2 5456 days ago | link

Thanks for the info.

I am using mzscheme 372 as described here: http://arclanguage.org/install

I tried:

  $ echo '(nsv)' | arc news.arc - &
I got repetitively:

  arc> Error: "Bad object in expression #<eof>"
  arc> Error: "Bad object in expression #<eof>"
  ...
I am using a remote vps, hence I would like to start the service and quit the server. To be honest, a web service without daemonizing does not sound very intuitive. When I say I need to stay connected to the server to keep the service alive, forums users say "Ah man, what kind of a computer engineer are you?" ;-) I think something like this must be done: http://www.itp.uzh.ch/~dpotter/howto/daemonize

Do you think if I get the latest version of mzscheme your patch it will work? What about the 15 lines offset hunk? Patch didn't seem to apply perfectly.

-----

2 points by palsecam 5456 days ago | link

Yes, try the latest version of MzScheme. Seeing "bad object in expression #<eof>", I'm not even sure ac.scm is patched correctly.

http://arclanguage.org/install has not been updated, but the big feature of the 3.1 version is that it can runs on recent (> 4.1) MzScheme. See http://arclanguage.org/item?id=10254.

Edit: oh yes, maybe you use Arc 3! The current version is Arc 3.1: see the previous link. Direct download: http://ycombinator.com/arc/arc3.1.tar. The patch is to be used with the 3.1!

> To be honest, a web service without daemonizing does not sound very intuitive. When I say I need to stay connected to the server to keep the service alive, forums users say "Ah man, what kind of a computer engineer are you?"

I agree it's not intuitive, but the use of `screen' + long-lived REPL to manage the forum can actually be seen as quite smart:

  $ screen arc
  arc> (load "news.arc")
  arc> (thread:nsv)   ; start it in a new thread, to not block the REPL
  arc> ^A d  ; CTRL-A d, to detach the `screen'
  [detached]
Your forum is started and your screen session detached. You can safely logout and exit your SSH session at this point.

At any time, you can login back to the server and do:

  $ screen -r   # resume
  arc> ; you're in front of the forum REPL
  arc> requests*  ; ultra basic analytics: show the number of requests served
  161803
  arc> (change-some-settings)  ; you get the idea
And if you need to stop the server and exit Arc:

  arc> (exit)  ; or just ^D if you have applied the patch
  [screen is terminating]
  $ 
One thing that is missing is there is no watchdog, no automatic restart in case of failure (I mean big failure, like: the Arc process died). Sure, it's not as solid as the daemontools (http://cr.yp.to/daemontools.html), but it should suffice. srv.arc has some kind of protection against flood, handler threads that would get mad, etc.

If you really want to just echo '(nsv)' | arc news.arc -, then use version 3.1, the patch and a small shell or Perl wrapper script to daemonize the Arc process. Some fork + redirect standard ports + setsid magic, then exec the Arc process.

In Perl, from `perldoc perlipc':

      use POSIX 'setsid';

      sub daemonize {
          # chdir '/'               or die "Can't chdir to /: $!";
          open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
          open STDOUT, '>/dev/null'
                                  or die "Can't write to /dev/null: $!";
          defined(my $pid = fork) or die "Can't fork: $!";
          exit if $pid;
          setsid                  or die "Can't start a new session: $!";
          open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
      }
Or play it hardcore and use the daemontools :-P!

-----

1 point by user2 5452 days ago | link

Thanks, I got it working. For reference, particularly your screen trick worked very well over ssh. -L option also helps if screen dies on you, it creates a log file in the current dir that you can check and see what went wrong.

Next, I believe I need to learn a bit of arc to see how I can make changes on the website.

-----

1 point by user2 5456 days ago | link

OK thanks, let me try these.

By the way, somehow I managed to log out and the server still seems to be up. I didn't use screen or anything. I will investigate how it worked.

-----

1 point by akkartik 5456 days ago | link

Sometimes interactive processes will 'go rogue' when you ctrl-c them. Run ps and kill to get rid of it.

-----

1 point by thaddeus 5456 days ago | link

Maybe just put:

  (load "news.arc")
  (nsv)
at the bottom of your as.scm file (since this file loads successfully).

-----