Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
I've been wanting to know how to make an initialization script for when I boot-up linux. Just like the scripts that are executed for each run level. If anyone knows how to make these or has a resource to point me to PLEASE reply!!
To learn about them, I'd go through all my rc.* files in /etc/rc.d directory as well as anything in lilo or grub files. For instance, /etc/rc.d/rc.local will have a bunch of entries for other files to run at boot time like rc.M or rc.modules or rc.serial, etc. If you then go through them all with a text editor you should be able to see how they're structured as well as their syntax. You will be able to modify existing ones, and will be able to compare your newly created scripts to those that already exist.
If I'm wrong, someone will surely correct me or at the very least add to the list of rc.* files that you can peruse. Hope this helps.
#
# Start user defined bootup script.
#
if test -f /etc/init.d/boot.local ; then
echo "Running /etc/init.d/boot.local"
/bin/sh /etc/init.d/boot.local
rc_status -v1 -r
fi
Hey on the beyond LFS website they have a great tutorial on multiple ways of setting up boot scripts. They explain what they're for and why each line is there. They're very simple and easy to follow. Check this link out.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
Re: Creating init scrips in Linux
Quote:
Originally posted by rootking I've been wanting to know how to make an initialization script for when I boot-up linux. Just like the scripts that are executed for each run level.
In general, one of these scripts will look something like:
Code:
#!/bin/sh
start() {
echo "Starting NiftyApp (tm)..."
[ do app startup stuff ]
}
stop() {
echo "Stopping NiftyApp (tm)..."
[ do app shutdown ]
}
case "$1" in
start) start ;;
stop) stop ;;
restart) stop ; start ;;
*) echo "Dunno how to $1"
esac
Look in your SYSV init script subdirectory (/etc/rc.d/init.d in RH; same for Suse?) for some examples. You can test it without having to boot and when it's working correctly create the appropriate symbolic links in the rc0.d/rc3.d/rc5.d subdirectories.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.