Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to understand the init process.

I have a script which launches 3 background processes (2 shell scripts and a java app). It works just fine from the command line.

I'd like to execute that script at startup.

/etc/init.d/skeleton didn't make sense to me because it was looking for a single process it seemed. And most init scripts seems so complex I'm getting sort of lost.

All I really want to do is:

#!/bin/bash
/opt/myapp/bin/my_start_script

If that just happened at startup I'd be very happy.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can add your link to the Startup Applications application in Ubuntu if you want to use the GUI. The downside of this is that it will only execute when you log in to the GUI (i.e. not for other users, and not if you don't log in to the Ubuntu Desktop environment).

Using the command line, you can cause a script to run before the Ubuntu Desktop loads.

To do this, make your script executable, copy it to /etc/init.d and create a symbolic link to the script in /etc/rc2.d if you want it executed in the default multi-user runlevel (runlevel 2). You should rename it with an S followed by the order you want it executed in, respective to the other links in there.

  1. Make script executable:

    sudo chmod u+x myscript.sh

  2. Copy it to /etc/init.d:

    sudo cp myscript /etc/init.d

  3. Create a symlink in rc2.d:

    cd /etc/rc2.d

    sudo ln -s /etc/init.d/myscript.sh

  4. Rename it according to the naming scheme:

    sudo mv myscript.sh S70myscript.sh

For more information, see the README files in /etc/init.d and /etc/rc2.d.

share|improve this answer

Use Upstart as the System V Init scripts are being deprecated and its simpler.

Simply place this file my_script.conf into /etc/init

# Start when pc starts up
start on runlevel [2345]
# Stop when pc shuts down 
stop on runlevel [016]

# Start Script 
exec my_start_script
# Stop Script 
pre-stop my_stop_script

The Pre Stop will script contain code to kill your 3 process and is optional, when the service is stopped sigterm will be sent to the my_start_script process but depending on your script it may already have exited.

You can test your new service by running sudo service my_script start and sudo service my_script stop

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.