LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-04-2008, 01:25 AM   #1
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Rep: Reputation: 15
Startup script cant work


Hi,

I have a startup script that i put in /etc/init.d
i have a symbolic link in r3.d
When i reboot the system, the process generated by the script are not running.
i can execute the script at /etc/init.d
Pls kindly assist
 
Old 04-04-2008, 07:14 AM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
What is the default runlevel for your system? Look in /etc/inittab for the line like "id:5:initdefault:". Mine here is set to boot to runlevel 5. If it isn't 3, then you might not be running your script. In my case, scripts on rc5.d will be run, but not rc3.d.

Check the man page for chkconfig to see who you can use it to control the execution of scripts in /etc/init.d.

What platform are you using?
 
Old 04-04-2008, 07:19 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Read the manpages for chkconfig (if your system has it) and insserv. Also look for a skeleton script. The comments at the beginning of startup scripts are important and contain info on which runlevels the stript should start in and which services need to be running before the script.
 
Old 04-05-2008, 03:18 AM   #4
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
Hi,

I have checked the inittab. It has
id:3:initdefault:

I have similar scripts in another linux server. No specific things in the script but that works.(it's not written by me though)

i did a
[root@sins476036 etc]# chkconfig --level 3 p2psinit on
service p2psinit does not support chkconfig

but the msg indicate that i cant use the chkconfig.

Any idea guys?
 
Old 04-05-2008, 03:39 AM   #5
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
The script needs a line at toward the start, that tells chkconfig how the script should be started - i.e. in which runlevels, and at what priority it should be started and stopped. This can look like this:-
Code:
# chkconfig:   2345 99 00
From the man-page for chkconfig:-
Code:
RUNLEVEL FILES
       Each  service which should be manageable by chkconfig needs two or more commented lines added to its init.d script. The
       first line tells chkconfig what runlevels the service should be started in by default, as well as the  start  and  stop
       priority levels. If the service should not, by default, be started in any runlevels, a - should be used in place of the
       runlevels list.  The second line contains a description for the service, and may be extended across multiple lines with
       backslash continuation.

       For example, random.init has these three lines:
       # chkconfig: 2345 20 80
       # description: Saves and restores system entropy pool for \
       #              higher quality random number generation.
       This  says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 20, and
       that its stop priority should be 80.  You should be able to figure out what the description says; the \ causes the line
       to be continued.  The extra space in front of the line is ignored.
I suggest you consider when you want the script to start and stop, add the appropriate line to it, and run chkconfig again to ensure it will run at boot time.

Now, assuming that the script is starting and stopping correctly, and it still isn't working, add some debugging statements (e.g. "echo I'm about to start the process >> /var/log/script.log", and "echo "The process should now be started >> /var/log/script.log") to the script so that you can see what it is doing when it is called during startup and shutdown.
 
Old 04-08-2008, 11:45 PM   #6
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
Hi,

I have found what's the issue for the startup script. I have a variable in my .bashrc (i'm using root) which is $RMDS_SW= /software/rmds
when i startup the system, it doesnt seems to export this variable and therefore my startup script couldnt navigate to the correct path to run the command.

How do i set this in the system environment? Thanks.

BTW, what's the different in putting under .bashrc and .bash_profile?
appreciate any help
 
Old 04-09-2008, 08:14 AM   #7
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
Hi any1 can help with the above?
 
Old 04-09-2008, 08:31 AM   #8
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
Add this near the top of your script in init.d:-
Code:
if [ -z "$RMDS_SW" ]; then
  RMDS_SW=/software/rmds
fi
This will check to see if the variable RMDS_SW is a null string or not, and if it is, will assign it a value. You script is then always sure of having a value for $RMDS_SW.
 
Old 04-23-2008, 01:59 AM   #9
cghcgh
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
i guess i found the issue. It will run the script first before loading the root's .bashrc profile. Therefore what i did was do a source of that profile in the script. Is that the right way to do it?
 
Old 04-23-2008, 04:24 AM   #10
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
Setting the environment in your script is the key. If using the root user's .bashrc does that for you, then that is fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script doesn't work during startup of the pc shipon_97 Linux - Enterprise 3 04-30-2007 01:38 PM
Startup Script Doesn't Work. jonwatson Linux - Newbie 2 03-24-2006 09:55 AM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 03:53 AM
Why won’t this init.d startup script work? dholingw Linux - Software 2 06-08-2004 03:40 PM
FALCONS EYE (nethack) FAILS ON STARTUP, use to work, wont work even after reinstall roorings Linux - Software 0 10-08-2003 11:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:22 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration