Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This should be easy, because there's a squillion questions about it, but seemingly I'm missing something. I have a script that creates some directories that I need to run at boot time. It's way too simple to bother with figuring out upstart or anything - it's not a service, it doesn't need monitoring, it just needs to run at boot time, with superuser privileges. I've tried putting the script directly in /etc/rc2.d - it ran once, at one boot, and never again. Does the system somehow remember it ran and didn't get shut down or whatever? I've also added a cron job as root and added the script as an @reboot task, still no dice. This is on an s3 Ubuntu instance - do s3 instances have some bizarre way of booting up that is causing these simple things not to work?

edit: I should mention that I need this script to run as early as possible at boot, since among other things it sets up /tmp, which is a bit important to a number of parts of the system.

share|improve this question
    
Never used S3, but couldn't you just stick it in rc.local? Be sure you're using the full path to the script as $PATH may not be initialized as you expected. –  jscott Jan 16 '13 at 2:33
    
Hm, I'm not sure that will run early enough. I want to run this script ASAP because one of the things it does is symlink /tmp so it's writable - as you can imagine, not having /tmp makes some things a little unhappy. –  cbmanica Jan 16 '13 at 2:35
    
Good to know, you should include that, and any additional requirements, in an edit to your question. –  jscott Jan 16 '13 at 2:37
    
Ok, I've done it and made this comment of sufficient length. heh. –  cbmanica Jan 16 '13 at 2:45
    
What do you mean by 'no dice' ? What shows up in your logs when no dice happens ? –  Iain Jan 16 '13 at 8:34

2 Answers 2

up vote 2 down vote accepted
  1. Place your script to /etc/rc3.d/-directory or create a symlink from other location.
  2. Name the script or link in /etc/rc3.d/ to S50myscript. (The number influences on the start order, capital S is required.)
  3. Make sure that the script has the execute bit in place (chmod +x script.sh)
  4. Make sure your script includes the interpreter at start, like #!/bin/sh if it is a shell script.
  5. If needed, you can debug it by placing needed echos to the script, like echo "step1" >/script.log, echo "step2" >>/script.log etc.

Hopefully this helps :-)

share|improve this answer
    
That worked - the number/start order thing sounds dimly familiar but I had clearly forgotten it years ago. Thanks. –  cbmanica Jan 16 '13 at 17:57

A simple solution if is to add your code to /etc/rc.local. Then it is executed as last script.

The rc.local is an old BSD style startup script that is honoured on most of the linux flavours I know.

If you want a more control other the invocation time in the boot procedure, please have a look at man update-rc.d for managing the correct set of symlinks from the technical /etc/rc?.d/ directories to the /etc/init.d/ directory of your startup scripts. Here you can define the order of the script invocation in the boot process.

PS: My advice for portable logging in a startup script is to use the logger command. This gives your shell script the ability to send messages to the syslog daemon.

PS: missing LSB informations

An example of the LSB information for update-rc.d is a comment section like this:

  ### BEGIN INIT INFO
  # Provides:          tomcat7
  # Required-Start:    $local_fs $remote_fs $network
  # Required-Stop:     $local_fs $remote_fs $network
  # Should-Start:      $named
  # Should-Stop:       $named
  # Default-Start:     2 3 4 5
  # Default-Stop:      0 1 6
  # Short-Description: Start Tomcat (c42Cfg user instance)
  # Description:       Start the Tomcat servlet engine (c42Cfg user instance).
  ### END INIT INFO
share|improve this answer
    
Also, update-rc.d seems to be ill-tempered in ways I don't understand: update-rc.d -f create_mounts.sh start 2 tells me the script doesn't have LSB information. I don't want to know what LSB information is - it's just a super simple script, remember. –  cbmanica Jan 16 '13 at 17:45
    
I would also point out that per my original question, rc.local isn't early enough in the boot process in this case. –  cbmanica Jan 16 '13 at 17:58
    
For the LSB information see new PS section above. –  H.-Dirk Schmitt Jan 17 '13 at 9:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.