Friday, November 9, 2007

Editing Startup Scripts on Solaris - Part 1 - The Nice Part

A Good Friday to you :)

Today I thought I'd go on a little about editing startup scripts.

It's generally accepted that the correct form for creating an init (or rc) script on Solaris is to create that actionable script in /etc/init.d and then create links to it (soft or hard) in the proper "run level" directories (/etc/rc2.d for run level 2). These files are also standardly named beginning with a capital S (to instruct /sbin/rc to run the script with the "start" option) or K (to instruct /sbin/rc to run the script with the "stop" option).

A lot of times, folks will simply create scripts in the various "run level" directories (like /etc/rc3.d for run level 3), which works perfectly well, but might cause some confusion down the road. For instance; if you create /etc/rc2.d/S88sendmail and replace the linked version that pointed back to the /etc/init.d/sendmail script, any changes made to the the source version in /etc/init.d will never be reflected in your version (sitting in /etc/rc2.d) and - should you expect your changes to work - you'll find that they never seem to stick on reboot.

I suppose that the best argument for doing things the "standard" way is that it can save you a lot of time and probably more than a few headaches. Consider that, by doing things by-the-book, you need only edit one script to affect however many run levels its linked to. Also, confusion over "what is actually where" is removed.

When it comes to the back-links in the "run level" directories, I prefer to use symbolic links (created by "ln -s") rather than hard links (created using "ln" straight up). The reasons for this are threefold.

1. Symbolic links are easy to see. I don't consider myself simple or anything like that, but I do like to be able to run "ls -l" in /etc/rc3.d and see something like this (clipped output to keep the output line short enough to not word-wrap):[/etc/rc3.d] # ls -l
lrwxrwxrwx 1 root other S90prog -> /etc/init.d/prog

Just seeing that, I know that this script is actually in /etc/init.d and, if I want to make changes to it, that's where the source is. Which brings me to point two.

2. Symbolic links are just as easy to use as hard links. Now that I'm feeling confident that I'm editing the correct file, I don't need to edit the /etc/init.d/prog file, because the symbolic link "/etc/rc3.d/S90prog" is just a pointer to it and, by editing it, I'm actually editing the script in /etc/init.d.

3. And thirdly, I like the fact that symbolic links are merely symbolic. The difference between a hard link and a symbolic link can be gigantic depending on what kind of change you're making!

And that, we'll talk about tomorrow, because it's a topic that will eat up some real estate, I've taken up enough space for today :)

, Mike