LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-09-2010, 10:30 AM   #1
fopetesl
Member
 
Registered: Jan 2005
Location: Yorkshire Dales, UK
Distribution: Ubuntu 5.10; Mandriva 2007; Debian Lenny
Posts: 147

Rep: Reputation: 15
Question 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
 
Old 06-09-2010, 10:39 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
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
 
Old 06-09-2010, 12:54 PM   #3
fopetesl
Member
 
Registered: Jan 2005
Location: Yorkshire Dales, UK
Distribution: Ubuntu 5.10; Mandriva 2007; Debian Lenny
Posts: 147

Original Poster
Rep: Reputation: 15
Unhappy 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.
 
Old 06-09-2010, 01:25 PM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
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
 
Old 06-09-2010, 01:53 PM   #5
fopetesl
Member
 
Registered: Jan 2005
Location: Yorkshire Dales, UK
Distribution: Ubuntu 5.10; Mandriva 2007; Debian Lenny
Posts: 147

Original Poster
Rep: Reputation: 15
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?
 
Old 06-09-2010, 01:58 PM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
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
 
Old 06-10-2010, 03:15 AM   #7
fopetesl
Member
 
Registered: Jan 2005
Location: Yorkshire Dales, UK
Distribution: Ubuntu 5.10; Mandriva 2007; Debian Lenny
Posts: 147

Original Poster
Rep: Reputation: 15
Question

Quote:
Originally Posted by EricTRA View Post
.... 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
 
Old 06-10-2010, 03:33 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
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
 
Old 06-10-2010, 04:16 AM   #9
fopetesl
Member
 
Registered: Jan 2005
Location: Yorkshire Dales, UK
Distribution: Ubuntu 5.10; Mandriva 2007; Debian Lenny
Posts: 147

Original Poster
Rep: Reputation: 15
Question

Quote:
Originally Posted by EricTRA View Post
... 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...
 
  


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
Getting an /etc/init.d script to run at system shutdown forrie Linux - Server 6 05-05-2010 02:19 PM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 02:34 PM
how to: boot w/out log-in, run firefox@startup&shutdown w/ password after 10hours newATSlnx Linux - Newbie 3 04-21-2008 05:00 PM
How to run a script at startup after a shutdown? kklein9 Linux - Software 3 01-27-2006 04:32 PM
startup and shutdown script android6011 Slackware 3 11-03-2005 05:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:54 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