Nikos Chantziaras <realnc RemoveThis @arcor.de> wrote:
> Hello group.
>
> What's the best way to start a server program that runs in the
> background at system boot from a normal (non-root) user account on our
> Gentoo server?
>
> Right now, my crontab looks like this:
cron is the wrong way to do it.
The most compatible way would be to set up a script in /etc/init.d/ that
starts the service, and changes the user to the one who should run it. Look
at the existing scripts in /etc/init.d/, and copy/modify one of them for
your own use. To start the command as a different user, either use
su - username -c "/path/to/command arguments"
or, if the service should *always* start as one particular user, simply suid
the server process to the user who should run it:
chown username /path/to/command
chmod u+s /path/to/command
After doing this, the app will always run as "username". (You might want to
combine the above with group changes too, with chgrp and chmod g+s.)
If adding a script in /etc/init.d/, don't forget to add it to the runlevel
where you want it started, e.g. "rc-update add yourscript default".
Alternatively, you can start the service from init directly, by editing
/etc/inittab, but then you can't set dependencies preventing the service
from starting "too early", i.e. before other services it might depend on
(like networking).
Or, if this is an internet service, you can have it start upon first access,
by editing /etc/inetd.conf (presuming the inetd super daemon is installed
and running). There's facilities in inetd.conf for starting a service as
the user of choice -- see the man page for details.
> What's the best way to start those with cron, and are there any
> implications?
You're hammering in nails with a wooden clog. I suggest using a hammer
instead.
Regards,
--
*Art