VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: [SOLVED] How to autostart a daemon before login?  (Read 3043 times)

wcs

  • Packager
  • Vectorian
  • ****
  • Posts: 1144
[SOLVED] How to autostart a daemon before login?
« on: August 08, 2007, 06:54:00 pm »

Hello, all.

I'm trying to autostart this music server when I boot the computer.

It works fine when I put it in "Autostarted Applications" in xfce.
However, I would like this to start automatically for all users, and preferably before a user even logs in, so that nothing is required for the server to run except pressing the power button.

I tried putting the executable at the end of /etc/rc.d/rc.local but the process does not start. I think the reason is that the daemon doesn't allow me to run it as root.

Is there a way out of this? Some way of running it as a normal user, but before any user logs in?  ???
« Last Edit: August 09, 2007, 07:56:09 am by wcs »
Logged

lagagnon

  • Global Moderator
  • Vectorian
  • *****
  • Posts: 1922
Re: How to autostart a daemon before login?
« Reply #1 on: August 08, 2007, 07:41:51 pm »

Can you launch the daemon as root in a terminal? If not, what error messages do you get?
Does the daemon require X? If so, then it can't be launched from /etc/rc.d/rc.local but would have to be launched from the appropriate xinitrc file.
Logged
"As people become more intelligent they care less for preachers and more for teachers". Robert G. Ingersoll

wcs

  • Packager
  • Vectorian
  • ****
  • Posts: 1144
Re: How to autostart a daemon before login?
« Reply #2 on: August 09, 2007, 05:03:18 am »

Quote
Can you launch the daemon as root in a terminal? If not, what error messages do you get?

It actually launches and gives me the appropriate output, but the process dies a few seconds later with the following message:
Code: [Select]
* Error: SlimServer must not be run as root! Exiting! *
Quote
Does the daemon require X? If so, then it can't be launched from /etc/rc.d/rc.local but would have to be launched from the appropriate xinitrc file.

Good point. But it doesn't require X.

I think I'm looking for a way to launch the daemon before login "as if" it was initiated by a non-root user.
Interesting conundrum...

Thanks for the answer.
Logged

rbistolfi

  • Packager
  • Vectorian
  • ****
  • Posts: 2318
Re: How to autostart a daemon before login?
« Reply #3 on: August 09, 2007, 05:28:13 am »

hi wcs, I think you can use:

Code: [Select]
#sudo -u <username> </path/.../your_bin>
to run a bin as another user. Try it as root and if it works you can add it to the rc.local
Logged
"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!

retired1af

  • Administrator
  • Vectorian
  • *****
  • Posts: 1331
Re: How to autostart a daemon before login?
« Reply #4 on: August 09, 2007, 05:32:22 am »

I think he wants the username passed to the command. I just don't know the variable name to use that would do that. And that defeats the purpose of starting the daemon prior to login.

However, I would imagine that a script could be created that is part of the startup after login while the system is finalizing the bootup process.
« Last Edit: August 09, 2007, 05:34:50 am by retired1af »
Logged
ASUS K73 Intel i3 Dual Core 2.3GHz

rbistolfi

  • Packager
  • Vectorian
  • ****
  • Posts: 2318
Re: How to autostart a daemon before login?
« Reply #5 on: August 09, 2007, 05:55:28 am »

je je, that sounds probably, I am not at my linux box to test it. I thought since sudo -u is issued by root a password will not requested, it has the permissions anyway.

Anyway, I went to the slim devices site and the command has an option to run as user, ./slimserver.pl -user <username> will do it, the complete usage appears with ./slimserver.pl --help.

Quote
--user => Specify the user that server should run as.
                        Only usable if server is started as root.
                        This may only work on Unix-like systems.

There is also some init scripts for debian if you want to check here. May be they can be adapted to VL.
BTW, Nice stuff, enjoy the music   :P (hey, there is no rock n´roll smiley!)
« Last Edit: August 09, 2007, 05:59:19 am by rbistolfi »
Logged
"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!

wcs

  • Packager
  • Vectorian
  • ****
  • Posts: 1144
Re: How to autostart a daemon before login?
« Reply #6 on: August 09, 2007, 07:55:38 am »

Quote
Anyway, I went to the slim devices site and the command has an option to run as user, ./slimserver.pl -user <username> will do it, the complete usage appears with ./slimserver.pl --help.

Of course! First thing to do should be checking the command options.  ::)

That did it, although because the daemon was still looking for the preferences file inside /root, it required an additional option:
Code: [Select]
/opt/SlimServer_6.5_v2007-07-11/slimserver.pl --user <username> --prefsfile /home/<username>/slimserver.pref --daemon
I put that at the end of /etc/rc.d/rc.local and it works like a charm... Now I can simply press the power button and while going downstairs to brew some coffee I'm ready to enjoy some music. Doesn't sound like much, but it saves me about a minute each day.  ;)

Thank you all for the replies.
Logged

MikeCindi

  • Tester
  • Vectorian
  • ****
  • Posts: 1075
Re: How to autostart a daemon before login?
« Reply #7 on: August 09, 2007, 10:33:18 am »

Doesn't sound like much, but it saves me about a minute each day.  ;)

That minute spent watching your PC boot up then inputing some commands every time that you KNOW can be automated can be some of the worst time spent. Especially when you could be getting coffee!  :o
Logged
The plans of the diligent lead to profit...Pro. 21:5
 VL64 7.1                                     RLU 486143