LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-14-2004, 01:35 PM   #1
Johnsernickle
Member
 
Registered: Aug 2002
Posts: 71

Rep: Reputation: 15
rc.local problems


Hey, I created a script that would start Folding at Home for me automaticly when i start up. My intention was to get FAH to run as user "fah" that i made just for this. Heres what my startup script which i linked to in rc.local.

#!/bin/sh
cd /home/fah/FAH1
su - fah -c ./FAH4Console-Linux.exe > /dev/null&
cd /home/fah/FAH2
su - fah -c ./FAH4Console-Linux.exe > /dev/null&

Pretty simple. But for some reason when i run top, i see the program is being run by root. Shouldnt the su command have changed its user? If anyone knows how i can get user fah to start the process that would be great. Oh, by the way, the script is in roots home directory, if that makes any diffrence.

thanks,
Petes
 
Old 07-14-2004, 02:23 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Well, I'm afraid I can't offer any onclusive explanation why it's not working. What I can do is show you how I set things up for my vnc session. Like you, I created a user for a specific application. In my case it was VNC. The command I used was:
Code:
su -l vnc_user -c "/usr/local/bin/vncserver -depth 16 -geometry 1024x768"
I never had much luck with rc.local. So I created a script and installed it in the /etc/rc.d/init.d directory. It works, and a ps -aux | grep vnc shows that vnc_user is definitely running the vnc server.

I can post steps on how I did it if you like.

One question though: why did you make rc.local point to a script rather than just putting the commands in rc.local to start with?
 
Old 07-14-2004, 04:31 PM   #3
Johnsernickle
Member
 
Registered: Aug 2002
Posts: 71

Original Poster
Rep: Reputation: 15
Thanks for the advice. I tried putting the commands in rc.local, but whenever i tried to boot up, it always came up with some error about the command not being there. I dont think ti changed directories and then executed the command i asked. Ill try this again with the "-l" switch and quotations. Hey, your saying i can put a script in /etc/rc.d/init.d director and it will start at boot? Thats way better then using rc.local. Thanks alot, ill get back to you about the progress.
 
Old 07-14-2004, 04:49 PM   #4
Johnsernickle
Member
 
Registered: Aug 2002
Posts: 71

Original Poster
Rep: Reputation: 15
No luck. I just edited my script to this

Code:
 su -fah -c "cd /home/fah/FAH1 && ./FAH4Console-Linux.exe > /dev/null&"
 su -fah -c "cd /home/fah/FAH2 && ./FAH4Console-Linux.exe > /dev/null&"
I tried the -l thing, but i couldnt find anyhting about it in the man. It is still running as root, do you think it has something to do with the script being in roots home directory? I will try and move the script to /etc/rc.d/init.d

Thanks alot,

Petes
 
Old 07-14-2004, 05:19 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Well, there are a couple more steps in addition to copying it over, but mainly it's just creation of symbolic links. Here's the contents of my vnc script:
Code:
#!/bin/bash
# description: Start or kill a vnc session for use in remote administration
#              on startup and shutdown.

. /etc/init.d/functions

# See how we were called.
case "$1" in
  start)
        # Start the session as vnc_user
        action $"Starting VNC session: " 'su -l vnc_user -c "/usr/local/bin/vncserver -depth 16 -geometry 1024x768"'
        ;;

  stop)
        # Stop the session
        action $"Killing VNC session: " 'su -l vnc_user -c "/usr/local/bin/vncserver -kill :1"'
        ;;

  *)
        echo $"Usage: $0 {start|stop}"
        exit 1
esac

exit 0
I copied that script to /etc/rc.d/init.d as a file named vnc_session, and made it executable. The script uses some bash functions provided by Red Hat (the /etc/init.d/functions business and the 'action' command).

Now comes the moderately complicated part. The complication comes solely from describing how the boot process works.

Assuming you use Red Hat:
In /etc/rc.d you should see a number of other rcX.d directories (where X = 1-6). The X represents the runlevel of your system. What you need to do is create specially named symbolic links in those directories to your script. To be safe, you probably ought to put links in rc3.d, rc4.d, and rc5.d. Go to one of those directories and get a file listing. You'll see that pretty much everything is a symbolic link to a file in /etc/rc.d/init.d, and that all the links start with either an S or a K followed by a two digit number. Create both the S and the K links for you script with something like:
Code:
ln -s ../init.d/script_name S98script_name
ln -s ../init.d/script_name K01script_name
The S tells init to execute your script with the argument "start" on the command line when the system enters the runlevel of the directory (i.e. rc3.d = runlevel 3, rc5.d = runlevel 5). The number after the S tells init what the order should be for the script. In other words, since we used 98, the script will execute next-to-last (it's ok to have multiple links with the same number). Similarly, the K link tells init to call your script with a "stop" argument on the command line, and the 01 tells init to call the script right off the bat when leaving the runlevel.

I'll double-check that, but I'm fairly certain that's the organization of those directories. If I'm fuzzy about anything, it would be when the K links are used.

As for the script being located in your root account's home directory, I doubt that's a problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
boot problems...rc.local uh-oh! ryan62580 Mandriva 5 03-11-2005 08:04 AM
Problems with apt-get and local repository.... Eux Debian 3 12-12-2004 04:04 PM
problems with /etc/rc.d/rc.local and ifconfig designguy79 Slackware 6 10-24-2004 01:37 PM
rc.local problems zehas Slackware 6 09-01-2004 04:16 PM
rc.local problems WORST Fedora 3 05-14-2004 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration