Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to create a simple startup script on Ubuntu 12.04:

myscript.sh

#!/bin/sh
sudo /etc/init.d/nginx start
cd ~/app/current
god -c config/resque.god
sudo /etc/init.d/redis-server start
echo "SCRIPT RUN"

I have it at /etc/init.d/myscript.sh

When I do

sudo chkconfig --level 2345 myscript.sh

I get myscript.sh 2345

When I do

 sudo chkconfig --add myscript.sh

I get

insserv: warning: script 'K01myscript.sh' missing LSB tags and overrides
insserv: warning: script 'myscript.sh' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'dbus' missing LSB tags and overrides
....
myscript.sh               0:off  1:off  2:on   3:on   4:on   5:on   6:off

** EDIT::

I checked the boot.log and it turns out that the script is run, but the problem is that god is not loaded yet when the script is executed. Apparently I want to load this script as the very last thing at startup (or somehow check if god is loaded and then start the script).

share|improve this question

2 Answers 2

You will also, probably, have problems with the cd ~/app/current line. ~ means the current user's home directory. I don't know what user scripts in init.d are run as, root I would imagine, but I guess you are referring to your own $HOME not root's. In that case, you should use absolute paths.

If I understand the chkconfig line correctly, you are telling the system to run your scripts at init levels 2 through 5. Since it is a high level script that depends on other modules being loaded etc, you should only run it a later runlevels. Have a look at this page for more info on runlevels.

Based on the chkconfig man page, it looks like what you want is:

sudo chkconfig myscript.sh 35
share|improve this answer

The error message you are getting is because you are missing LSB tags. To a purist, your init.d script is horrible because it contains no comments about what it is trying to achieve, does not have start/stop functions, and generally does not behave like an init.d script. However for your purposes that doesn't matter too much unless you are working on a shared system. I would suggest putting comments in every single script you ever write about the purpose, when it was written and by who - it is just good practice.

http://wiki.debian.org/LSBInitScripts

Have a look at the man page (http://linux.die.net/man/8/chkconfig) specifically this section:

# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
#              higher quality random number generation.

Or LSB style stanzas:

### BEGIN INIT INFO
# Provides: foo
# Required-Start: bar
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Foo init script
### END INIT INFO

Which are "better". There is no point re-writing the manpage here - take the time to understand what an init.d script should do by reading the docs.

I think you want something like:

# chkconfig: 2345 99 1

You can double check by doing /etc/rc2.d/*myscript* to see the S and K levels that it has been set to.

share|improve this answer

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.