Subject: Re: Correct way to start a server as a user in rc.local?
To: Manuel Bouyer <bouyer@antioche.lip6.fr>
From: Laine Stump <lainestump@rcn.com>
List: netbsd-help
Date: 12/10/2001 12:48:19
Manuel Bouyer <bouyer@antioche.lip6.fr> writes:

> On Mon, Dec 10, 2001 at 07:33:18AM -0500, Clint (cpctc) wrote:
> > 
> > I want to run a tcl server via rc.local.  When I'm at my shell prompt, I
> > start it with:
> > 
> > # /usr/pkg/bin/tclsh myserver.tcl
> > 
> > .. and it logs to stdout and /var/log/messages via 'logger'/syslog.
> > 
> > I want to have the thing start up at boot in rc.local, and for it to run as
> > user "myuser".
> > 
> > Because it logs to syslog, I'd like to redirect stdout and stderr to
> > /dev/null.
> > 
> > I'm sure there's a few ways to do this.. can anyone suggest the preferred
> > method?
> 
> I would do:
> 
> su myuser -c "/usr/pkg/bin/tclsh myserver.tcl" > /dev/null 2>&1

Another way of doing it would be to put an entry in "myuser"'s crontab:

  @reboot /usr/pkg/bin/tclsh myserver.tcl >/dev/null 2>&1

(don't forget the path for myserver.tcl ;-)

If it is a server that really is managed by an actual user named
"myuser", this will give them control over reconfiguring it, rather
than needing to bother the sysadmin every time they want to change a
commandline option or something.

The downside of this is that you can't really control the exact timing
of when it will startup - it will happen sometime shortly after cron
starts.

I do this, for example, to start up a VNC session for my uid every
time the system boots.