Take the 2-minute tour ×

I have no idea where to start looking. I've been reading about daemons and didn't understand the concept.

More details :

  • I've been writing a crawler which never stops and crawlers over RSS in the internet.
  • The crawler has been written in java - therefore its a jar right now.
  • I'm an administrator on a machine that has Ubuntu 11.04 .
  • There is some chances for the machine to crash , so I'd like the crawler to run every time you startup the machine.
  • Furthermore, I'd like it to keep running even when i logged out. I'm not sure this is possible, but most of the time I'm logged out, and I still want to it crawl.

Any ideas? Can someone point me in the right direction?

Just looking for the simplest solution.

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

Here's a easy way to do that using SysVInit. Instructions:


    • Start Script: /usr/local/bin/myapp-start.sh
    • Stop Script: /usr/local/bin/myapp-stop.sh

    Each one will provide the instructions to run/stop the app. For instance the myapp-start.sh content can be as simple as the following:

    java -jar myapp.jar 

    For the stop script it can be something like this:

    kill -9 $pid
  2. Create the following script (myapp) and put it on /etc/init.d.

    /etc/init.d/myscript content:

    # MyApp
    # description: bla bla
    case $1 in
            /bin/bash /usr/local/bin/myapp-start.sh
            /bin/bash /usr/local/bin/myapp-stop.sh
    exit 0

    update-rc.d myapp defaults 


share|improve this answer
add comment

Yes! It is possible. :) Upstart is the way to go to make sure the service stays running. It has five packages, all installed by default:

  • Upstart init daemon and initctl utility
  • startup-tasks provides job definition files for system startup tasks
  • system-services provides job definition files for tty services


share|improve this answer
add comment

3 quick suggestions...

  1. Create a Start script in /etc/rc3.d (multiuser console mode) with corresponding Kill scripts in /etc/rc.0 and /etc/rc6.d to kill your Java program in a controlled way when the system powers down (runevel 0) or reboots (runlevel 6) See An introduction to Runlevels.

    You might be able to start your Java app in runlevel 2 (rc2.d) but, as a crawler, it will need TCP/IP. So make sure your networking service is available/started in your runlevel 2 beforehand. Networking is definitely up in runlevel 3.

    /etc/init.d contains all the actual start/kill scripts. /etc/rcN.d directories just contain links to them, prefixed with S or K to start or kill them respectively, per runlevel N.

  2. A process run by crond should persist between logouts. Maybe add it to your crontab.

  3. A process run with nohup should also persist. See nohup: run a command even after you logout.

    $ nohup java -jar myapp.jar &

    By default, myapp.jar's standard output will go to a file named ./nohup.out, or $HOME/nohup.out if the former isn't writeable.

share|improve this answer
And when i logout , will it still run on background? –  RanZilber Jan 29 '12 at 9:59
add comment

Your Answer


