UBUNTU: can I run startup script only (not on shutdown)?
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
... 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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.