Koozali.org: home of the SME Server

Running a monotone server

Offline judgej

  • *
  • 375
  • +0/-0
Running a monotone server
« on: August 29, 2008, 03:19:22 AM »
This is probably a more generic Linux question than being specific to SME Server, but here goes:

I would like to run a monotone server on SME Server 7.x. The server consists of a single static-compiled executable, running as a daemon, which listens on a port (or ports) and does its thing (its thing being a change control server).

Now, what is the best way to run the daemon when the machine starts (/etc/rc.d/rc.local perhaps?) and does the SME Server have any kind of watchdog that can ensure the process remains running, restarting it if necessary?

-- Jason
-- Jason

Offline dmay

  • *
  • 450
  • +0/-0
    • http://myezserver.com
Re: Running a monotone server
« Reply #1 on: August 29, 2008, 03:52:06 AM »

Offline judgej

  • *
  • 375
  • +0/-0
Re: Running a monotone server
« Reply #2 on: August 29, 2008, 04:13:12 AM »
Brilliant, thanks. Just what I need:

http://wiki.contribs.org/SME_Server:Documentation:Developers_Manual#Process_startup.2C_supervision_and_shutdown

It was just the terminology I got wrong, hence was unable to find the [well written] developer notes. It is not a daemon I am running, it's just a process, and it is supervised rather than watched.

-- Jason
-- Jason

Offline judgej

  • *
  • 375
  • +0/-0
Re: Running a monotone server
« Reply #3 on: August 29, 2008, 06:32:53 PM »
Well, it nearly worked. The instructions are good, and the scripts are all set up so I can just start/stop the service, well, kind of.

The problem is, the monotone server command is not a proper daemon - it runs in the foreground. That means when I try to start it as a service, it just hangs there doing its thing and does not return to the service startup script. By contrast, a daemon such as httpd will fork itself, check its child[ren] is running, then return a status to the caller. monotone does not.

Is there a wrapper script or program I can use to run my "monotone serve" command, that will turn it into a proper daemon? Ultimately I would like this to be a simple contribution, combined with viewmtn to visualise the content of a monotone (http://www.monotone.ca/) database.

Is there a better forum I should be asking these questions on?

-- Jason
« Last Edit: August 29, 2008, 06:35:59 PM by judgej »
-- Jason

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Running a monotone server
« Reply #4 on: August 29, 2008, 08:30:26 PM »
Brilliant, thanks. Just what I need:

http://wiki.contribs.org/SME_Server:Documentation:Developers_Manual#Process_startup.2C_supervision_and_shutdown

It was just the terminology I got wrong, hence was unable to find the [well written] developer notes. It is not a daemon I am running, it's just a process, and it is supervised rather than watched.

All daemons are processes. And a monotone server is a daemon - it's a long running system process expected to provide a service.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Running a monotone server
« Reply #5 on: August 29, 2008, 08:36:25 PM »
The problem is, the monotone server command is not a proper daemon - it runs in the foreground. That means when I try to start it as a service, it just hangs there doing its thing and does not return to the service startup script. By contrast, a daemon such as httpd will fork itself, check its child[ren] is running, then return a status to the caller. monotone does not.

httpd in SME server doesn't fork itself into the background.

The fact that monotone server runs in the foreground is a good thing if you want to supervise it. That's exactly what it needs to do.

I think you should go and read the developer documentation again. And read some more about supervising services, e.g.

http://smarden.sunsite.dk/runit/faq.html
http://cr.yp.to/daemontools/faq.html
http://www.thedjbway.org/daemontools.html

Quote
Is there a better forum I should be asking these questions on?

The devinfo mailing list is more interactive, because it puts messages into mailboxes, and doesn't depend on people coming here to browse.
« Last Edit: August 29, 2008, 08:38:22 PM by CharlieBrady »

Offline judgej

  • *
  • 375
  • +0/-0
Re: Running a monotone server
« Reply #6 on: August 29, 2008, 11:42:46 PM »
I found the solution on the monotone IRC: when the executable is invoked, it needs to be invoked as a background process by putting '&' on the end. But the "&" needs to be quoted to prevent it being picked up at the wrong point in the init.d script.

This is in contrast to most of the services which do fork themselves. For example, httpd will fork a set of child processes, which will then detach themselves from the console (except if you run them in debug mode). If you run 'httpd' from the command line, it will start up one parent process and ten child processes. The parent will then detact from the console, taking you back to the command line. This is why the init.d script starting the http daemon does not itself attempt to run httpd in the background (i.e. with '&' on the end).

Anyway, having discovered the magic "&", I can now enable and disable the monotone server(s) through SME Server, and can be sure they will be started when the server is booted.

-- JJ
-- Jason

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Running a monotone server
« Reply #7 on: August 30, 2008, 12:37:01 AM »
I found the solution on the monotone IRC: when the executable is invoked, it needs to be invoked as a background process by putting '&' on the end. But the "&" needs to be quoted to prevent it being picked up at the wrong point in the init.d script.

No, that's all irrelevant. And putting quotes around "&" means that it will not background a process, but will be passed as a string argument to the program, which will probably not understand it.

The only init.d script that you need is e-smith-server. The script which you write and put at /var/service/monotone/run will end with a line:

exec /path/to/monotone

and you will not use & anywhere.

Quote
This is why the init.d script starting the http daemon does not itself attempt to run httpd in the background (i.e. with '&' on the end).

You are looking at an init.d script which SME server does not use. Please go and read the SME server developer documentation, and the additional documentation I've pointed you to, again. Multiple times if necessary.

Offline judgej

  • *
  • 375
  • +0/-0
Re: Running a monotone server
« Reply #8 on: August 30, 2008, 01:37:31 AM »
Quote from: CharlieBrady
You are looking at an init.d script which SME server does not use. Please go and read the SME server developer documentation, and the additional documentation I've pointed you to, again. Multiple times if necessary.

Yes, I see that now. Even though the init.d scripts are all there (part of CentOS), the SME stuff is all in the supervise folder under init.d. What was happening is that I was running the monotone script through the init.d system, which is a kind of fall-back where the SME does not have over-riding supervise scripts. I guess what led me that way is that, even though the core SME server does not use init.d scripts, there are plenty of contributions that do (e.g. hylafax, which I was basing my script on).

I've got the daemontools script working now, and that appears to have true process supervision, and is designed to run executables that are specifically *not* daemons by themselves, so is ideal for monotone.

Thanks for the pointers.

-- Jason
-- Jason