0

I know this question has been asked several times but I simply can not get it to work.

Here are the steps I have taken to get it working:

  1. wrote script saved as collection.sh
  2. moved collection.sh to /etc/init.d
  3. executed $ sudo chmod 711 /etc/init.d/collection.sh to set permissions for executing the script
  4. executed $ ln -s /etc/init.d/collection.sh /etc/rc0.d/ to create a symbolic link in /etc/rc0.d
  5. restarted the machine with $ sudo reboot

These steps were unsuccessful in running collection.sh at startup. So can anyone point out what I did wrong?

I thought maybe I am creating a symbolic link in the wrong rc?.d folder as there are 0-6 and S rc folders. If so, which folder should it be made in?

0

3 Answers 3

1

You are doing 3 things wrong that I see.

First: You want to put your soft link in /etc/rcS.d/ to have it run when the machine enters "single user" mode (no networking available), and in /etc/rc[2-5].d/ to have it run when the machine enters "multi user" mode (Runlevels 2 thru 5). Runlevel 0 /etc/rc0.d/ is only entered when the machine is told to shutdown. Runlevel 6 is used for "Reboot". See the wikipedia page for UNIX Runlevels

Second: The name of the softlink cannot be collection.sh. It needs to be of the form S09collection where "S" means Start and "09" means Start after all of the 08 scripts have been started. See here for more details.

Third: init is used for starting daemon services, and should not be used to run collection.sh directly. You need to create an actual init script that handles the starting and stopping of the the collection.sh daemon. Study the pre-existing init scripts in /etc/init.d/ to get a feel for how they work. Alternatively have a look at the following links for more documentation on writing init scripts.

  • Here is a how to on writing LSB compliant init scripts. This is recommened for LSB compliant Linux Distributions. I noticed you tagged your question with "ubuntu", so I should mention that Ubuntu (like all Debian based distros) is LSB compliant.
  • Here is the Debian wiki guide on making init scripts LSB compliant.
  • Here is a "Quick and Dirty" how to on System V style init scripts.
  • Here is a template for a System V style init script on Github.

Also, you don't need to create the symbolic links directly in the /etc/rc?.d folders. The major distributions all have automated tools for doing that. See this article for more details.

0

Its difficult to know why this is not working without seeing your script, but the steps you took look reasonable.

Some possibilities explaining the failure could be

  • You do not have something like #!/bin/bash as the first line of the script
  • You are relying on paths to binaries which have not been configured.
  • Your script does not take into account that the startup scripts pass parameters like start, stop, reload etc.

Another method of running a script at startup (for most distros) is to simply add it to /etc/rc.local - this has the added advantage of running last, so prerequisites will be met.

0

The symbolic links need to be prefixed with a three character key consisting of 'S' for start or 'K' for kill/stop followed by a two digit order.

Most distributions include a program such as update-rc.d that will create and remove the symbolic links as desired. Try the command man -k rc.d to find the documentation.

You may have a template in your /etc/init.d directory. It may include specially formatted comments intended to provide the parameters for the rd.d update program. If you don't have a template, you likely have a simple script there that you can use as a template.

Some distributions are moving to alternate methods of performing initialization. Check your distributions documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .