5

I have a Debian and an RPM package that requires a start/stop script to be added to the /etc/init.d directory. Recently, I was informed by a remote developer that "those in the know" know that "best practice" is to actually install the start up in the /etc/init.d directory rather than use symlinks, especially when the package could be installing on a different partition. I've always used symlinks. An "ls -la" shows a lot of packages use symlinks.

Is there a Unix/Linux guru out there can give a definitive answer as to what the best practice regarding start up scripts in the /etc/init.d directory. Is best practice symlink, hard link, actual file or does it really matter?

It would be great if you could cite a source. I have google this topic, but I'm unable to find an answer.

user2569618
  • 153
  • 1
  • 4
  • A .deb and a .rpm simultaneously? Are you using alien, perchance? – Deer Hunter Aug 31 '15 at 22:22
  • No, they're two different packages built on two different machines for two different OSs, but both use a symlink from the package's init directory to the /etc/init.d directory. – user2569618 Aug 31 '15 at 22:24
  • If your startup script isn't in /etc/init.d, then where is it? AFAIK no stock Debian package puts any symlinks in that folder. Can you give an example where you have seen this? I have never seen the setup you describe. – Zoredache Aug 31 '15 at 22:34
  • Normally it's a symlink from the runlevel folder back to the file in init.d. – hookenz Aug 31 '15 at 22:38

3 Answers3

3

The only way I have ever seen initscritps done is to have a regular file in /etc/init.d and a symlink to that file in the directory for each runlevel.

A symlink from /etc/init.d to another location could work. But it would not be normal practice. And if the link was pointing outside of the root partition, you will end up with a setup that easily breaks.

I would recommend sticking with a file in /etc/init.d like other services do.

kasperd
  • 29,894
  • 16
  • 72
  • 122
  • 1
    Exactly. Why not symlink? The link target may be on a filesystem not yet mounted. Why not hardlink? you cannot hardlink across filesystems. Thus, you are left with actual files. – Mark Wagner Aug 31 '15 at 23:55
3

The LSB standards ( https://refspecs.linuxbase.org/LSB_2.1.0/LSB-generic/LSB-generic/initsrcinstrm.html ) state that it's acceptable for /etc/init.d scripts to be symbolic links:

An init.d file is installed in /etc/init.d (which may be a symlink 
to another location) . . .

But honestly, I think I've only ever seen 3rd party vendor applications use symbolic links.

Edit: Identical verbiage in the 3.0 specifications ( https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-generic/LSB-generic/initsrcinstrm.html )

Brandon Xavier
  • 1,942
  • 13
  • 15
3

I have see issues with RHEL7 not following Symlinks to scripts in /etc/init.d/ Services were not starting on boot and some "service XXX start" commands failed.

The only way to fix it was to copy the file into the init.d directory in place of the symlink. So while it is convenient to just use a symlink copying the file directly is probably better practice.