Starting an app on startup without root privledges

redarrow

Expert Member
Joined
Dec 30, 2005
Messages
2,374
This is really giving me a headache.. :(

I have a simple linux box which I'm using as a server.
It's running Fedora 8 and does not use X, basically I just log in with ssh to make any system changes I need.

Now my big problem:
I'm trying to use it to run a Dc++ client like a server, I'm using "microdc2".

I need microdc2 to be automatically started when the system boots up, but I also want to be able to work on the microdc2 command line if I log in with ssh.

Here's what I want to do:
The system once booted, should start an instance of "screen" and within screen call microdc2. Screen must be run with my normal user privledges and not as root user.

I have tried adding "screen" to /etc/rc.d/rc.local
Basically I can get "screen" to run on startup as root user with no problems.
i.e., as an example adding "screen -d -m vim" to /etc/rc.d/rc.local will start an instance of screen and launch vim within this screen. I can then log in via ssh and access vim. But it's all as root user.

What I cannot seem to get right is to get screen to startup as a normal user.. I've tried "sudo -u <user> screen" and "su <user> -c screen" and even "screen sudo -u <user> screen" (running screen within screen).

Any help/ideas appreaciated..
Thanks :)
 

sn3rd

Expert Member
Joined
Jan 18, 2008
Messages
4,305
This is really giving me a headache.. :(

I have a simple linux box which I'm using as a server.
It's running Fedora 8 and does not use X, basically I just log in with ssh to make any system changes I need.

Now my big problem:
I'm trying to use it to run a Dc++ client like a server, I'm using "microdc2".

I need microdc2 to be automatically started when the system boots up, but I also want to be able to work on the microdc2 command line if I log in with ssh.

Here's what I want to do:
The system once booted, should start an instance of "screen" and within screen call microdc2. Screen must be run with my normal user privledges and not as root user.

I have tried adding "screen" to /etc/rc.d/rc.local
Basically I can get "screen" to run on startup as root user with no problems.
i.e., as an example adding "screen -d -m vim" to /etc/rc.d/rc.local will start an instance of screen and launch vim within this screen. I can then log in via ssh and access vim. But it's all as root user.

What I cannot seem to get right is to get screen to startup as a normal user.. I've tried "sudo -u <user> screen" and "su <user> -c screen" and even "screen sudo -u <user> screen" (running screen within screen).

Any help/ideas appreaciated..
Thanks :)

I might be wrong, but you might get the desired results if you put the commands you want to run inside a bash script (no matter how few commands, as in this case: one). Then run that script from /etc/rc.local

e.g.
/home/username/bin/startup
Code:
#!/bin/bash
su <user> -c screen

Then add
Code:
/home/username/bin/startup
to your rc.local

That's how I run some of my scripts, and it works, but it doesn't work if I add the command directly to my rc.local

Let me know if it works :eek:

Edit:
Hmmm, seems also the ownership of the file determines what user the file is executed as. You could check that out too; might provide some insight
 
Last edited:

redarrow

Expert Member
Joined
Dec 30, 2005
Messages
2,374
I might be wrong, but you might get the desired results if you put the commands you want to run inside a bash script (no matter how few commands, as in this case: one). Then run that script from /etc/rc.local
Hmm, I have actually been doing it just like that, putting the stuff in a bash script and just calling the script from rc.local.. :(

Edit:
Hmmm, seems also the ownership of the file determines what user the file is executed as. You could check that out too; might provide some insight
However I never thought that this might have any effect on it.. The script I've been calling is owned by the root user.. :eek:

I'll try changing that and see what happens.. :)
 

MyWorld

Executive Member
Joined
Mar 24, 2004
Messages
5,001
Hmmmm, not sure how Fedora handles it's startup, but on Gentoo we have:
/etc/conf.d/local

In there you can place complete scripts to start up at boot, make it a bit easier to maintain.

Code:
cat /etc/conf.d/local

# Here is where you can put anything you need to start
# that there is not an init script for.

local_start() {
        # This is a good place to load any misc programs
        # on startup (use &>/dev/null to hide output)

        # We should always return 0
        return 0
}

local_stop() {
        # This is a good place to unload any misc.
        # programs you started above.

        # We should always return 0
        return 0
}

Regarding user permission, I might be wrong but this just came to me while typing this out, but everything stated at init level is started as root and there is no way to start it as a normal user.

What I would do to get around this is to have a user auto login after start-up, then run the screen and dc++ command. Let me have a bit of a search and see what I can find.

How to set up autologin:
http://www.linuxjournal.com/article/3121

From there I'm sure you can figure out how to make the script run once autologin is completed.
 
Last edited:

redarrow

Expert Member
Joined
Dec 30, 2005
Messages
2,374
I just got it to work! :D

sn3rd was right! - Thanks a ton man! I'll remember you if ever I become a billionaire! ;)

Basically what I have now is an entry in /etc/rc.d/rc.local:
Code:
/home/<user>/start-microdc.sh

and start-microdc.sh looking like this:
Code:
#!/bin/bash
su <user> -c "screen -d -m /usr/local/bin/microdc2"


This works as desired, the system boots and starts "microdc2" within a "screen" I can ssh login to the box and assume control of microdc2 simply by grabbing the screen back with "screen -x".


MyWorld: On Fedora the rc.local script would probably be the parallel to "local" on Gentoo.. It's also meant for starting stuff without the complexities of writing full system init scripts. The only difference I think, is that it doesn't have a "start" "stop" function.. ;)

I did think of an autologin too.. but I had no idea how to set it up.. thanks for the link - I shall file it for future reference. :) EDIT: Hey, where did it go? :confused:
 
Last edited:

MyWorld

Executive Member
Joined
Mar 24, 2004
Messages
5,001
HUH? Someone deleted it???

Anyway, here it is again:
http://www.linuxjournal.com/article/3121

I also just came onto the same answer, but using sudo:
Code:
sudo -u <username> [command to be executed]

So in my case:
Code:
local_start() {
        sudo -u myworld screen && /usr/local/bin/microdc2
        return 0
}
 
Top