LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   UBUNTU: can I run startup script only (not on shutdown)? (https://www.linuxquestions.org/questions/linux-software-2/ubuntu-can-i-run-startup-script-only-not-on-shutdown-813147/)

fopetesl 06-09-2010 09:30 AM

UBUNTU: can I run startup script only (not on shutdown)?
 
I'm trying (& failing) to write a script in /etc/init.d that only operates on boot up but NOT on shutdown.
The program I want to run does not accept any parameters.
This works
Code:

#!/bin/bash

test -f /var/www/html/moveit || exit 0

. /var/www/html/moveit

exit 0

but on shutdown and startup.

This doesn't
Code:

#!/bin/bash

test -f /var/www/html/moveit || exit 0

case "$1"
 start)
. /var/www/html/moveit
  ;;
  stop)
  ;;
  *)
esac

exit 0

either at startup or shutdown.

Obviously my newb systax but I can't see what is wrong :(

EricTRA 06-09-2010 09:39 AM

Hello,

As far as I know starting and stopping programs/scripts at startup/shutdown is not handled by /etc/init.d/ but by linking them in the appropriate (runlevel directory(ies)) in /etc/rcX.d where the X is the runlevel. Scripts to start begin with the letter S followed by a number that indicates in what order processes will be started. Scripts to stop begin with a K and a number that indicates in what order processes will be stopped (killed).

In Debian based you can create those links to your script with the update-rc.d command.
Code:

update-rc.d /path/to/script defaults
look into the man page for more configuration options:
Code:

man update-rc.d
Take for example /etc/init.d/sshd which is the SSH server. Look in the respective /etc/rcX.d directory for the scripts and see when they start (runlevel) and when they get killed.

Kind regards,

Eric

fopetesl 06-09-2010 11:54 AM

I overlooked something!
 
Thanks, EricTRA but I'd already been through that loop.
That's how I new it would run at shutdown.

I said it was running at startup also and in one way I was correct but "moveit" wasn't getting any response.

"moveit" requires the LAN to be up and running, specifically eth0 with a static IP.

It appears that by trying to run "moveit" at startup is prior to LAN initialisation.

So now I need to dig out where to put "moveit" knowing the LAN has been initialised.

EricTRA 06-09-2010 12:25 PM

Hi,

Then put the startup sequence number at the end in the runlevel directory, like this:
Code:

S99yourscript
The higher the number (max 100 I believe), the later your script will run, after you're network is up.

Kind regards,

Eric

fopetesl 06-09-2010 12:53 PM

Thanks agin.
But I'd done that too :(
I put it at 90 with update-rc.d -f movitaction start 90 2 3 4 5 . so It's still too early.

When does the NIC actually get initialised?

EricTRA 06-09-2010 12:58 PM

Hi,

I'm not sure but are you running a graphical interface with Ubuntu (like Gnome) or only console? I think that if you're using a graphical interface that network is managed by the network manager and thus started after the init routine.

Kind regards,

Eric

fopetesl 06-10-2010 02:15 AM

Quote:

Originally Posted by EricTRA (Post 3998089)
.... if you're using a graphical interface that network is managed by the network manager and thus started after the init routine.

Thanks again, Eric.
I'm still running Breezy, (OK, old but still works :) ), in 'kiosk' mode.

And of course you're right since if I (manually) wait until the GUI is loaded I can issue "moveit" command without a problem.

What I need is a script which waits until the network is started.

I tried in ~/.xinitrc but that doesn't work either :(

EricTRA 06-10-2010 02:33 AM

Hello,

You could always put an 'if' statement in your script to check if the NIC is up or not and act accordingly (sleep for x seconds and then try again). That way your script will go into a loop until the NIC is up and only then execute.

Kind regards,

Eric

fopetesl 06-10-2010 03:16 AM

Quote:

Originally Posted by EricTRA (Post 3998619)
... You could always put an 'if' statement in your script to check if the NIC is up .... your script will go into a loop until the NIC is up and only then execute.

Aye! There's the rub...
If I put the script in /init.d will it not hold up the boot process even if I give it a 99 priority?

Is the NIC initialised concurrently or after all the init.d scripts have completed?

Will ~/.xinitrc accept bash script? OK, OK, I'll look around... :)


All times are GMT -5. The time now is 11:35 PM.