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:
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.
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.
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: $!";
}
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.
> It runs well, so far so good, but I have the interactive interpreter. As soon as I shut down, the service disappears.
This is where 'screen' comes in handy. Screen is a threaded model: it assigns a single thread for each 'screen' used. It also has a built in command to detach from your screen session (CNTRL+a d). After detaching you can then close the terminal window and arc will still be running as a silent thread. To get back just launch screen with the option to re-attach ($ screen -x).