LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Startup script cant work (https://www.linuxquestions.org/questions/linux-newbie-8/startup-script-cant-work-632879/)

cghcgh 04-04-2008 12:25 AM

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

blacky_5251 04-04-2008 06:14 AM

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?

jschiwal 04-04-2008 06:19 AM

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.

cghcgh 04-05-2008 02:18 AM

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?

blacky_5251 04-05-2008 02:39 AM

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.

cghcgh 04-08-2008 10:45 PM

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

cghcgh 04-09-2008 07:14 AM

Hi any1 can help with the above?

blacky_5251 04-09-2008 07:31 AM

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.

cghcgh 04-23-2008 12:59 AM

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?

blacky_5251 04-23-2008 03:24 AM

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


All times are GMT -5. The time now is 07:49 AM.