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.

What's the best way to set up a Java-based program to run an service and start on boot?

  • upstart (pre-start script and post-stop script ?)
  • plain old SysV init? (start-stop-daemon ?)

In my case I am interested in setting up Jira, which has its own Tomcat-style start and stop scripts - $JIRA_HOME/bin/startup.sh and $JIRA_HOME/bin/shutdown.sh.

share|improve this question

1 Answer 1

Most of the time you can cut out a lot of the code in those scripts and just focus on running the the main program. If you can tell it to run in the foreground instead of the background that will make things simpler. Otherwise you have to use 'expect fork' or 'expect daemon' to follow the forks that a program must do to detach from controlling terminals.

pre-start is mostly for setting things up, like creating dirs in /var/run. You can also source a config file, as the environment will be passed along to the main exec.

post-start can be helpful if you want to make sure that upstart doesn't consider the service started until a certain condition is met (like the port is answering queries).

Ultimately, the goal is to make it as simple as possible. If the startup.sh runs 'jira --daemon' and you can instead run 'jira' and it doesn't detach, then with upstart you'd just do

start on runlevel [2345]
stop on runlevel [!2345]

exec jira

As long as the process doesn't daemonize, its very easy for upstart to track what it is doing, which ultimately leads to a simpler job file and a more robust system.

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.