2

What is the easiest way to have an application launch at startup on Ubuntu server as daemon? This is a java application (java com.run.run.Run) etc.

How would I have it launch as a user and possibly have access to write to some log file where the user has permissions to write?

And if I don't end up doing that, how would I launch the application as the root user at startup.

Edited: It is a headless server, I don't have access to the desktop applications.

Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
  • this might be not what you want to hear, but I once coded Java app that was randomly changing wallpapers at startup of OS. It was painfuly slow, initializing JVM while booting up system ... Ofcourse, maybe you have completely another thing to do – Xorty May 10 '10 at 14:54
  • it probably didn't have with loading the JVM to do, but your imaging code. – aioobe May 10 '10 at 14:56
  • @aioobe => nay, just try to build hello world and save it to jar file ... nearly same speed ... – Xorty May 10 '10 at 14:58

2 Answers2

3

As user upon login: Depends on when exactly you want it to start. Wanting to run it a a user and write files as the user seems to indicate that you want to run it at login. This can be achieved by adding it under

System -> Preferences -> Sessions -> Statup Programs 

or

System -> Preferences -> Startup applications

Depending on your version of gnome.

Or, put a call to your java program it in ~/.profile.


As root upon boot: To run it as root during boot, follow the instructions at http://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/

So you have a script of your own that you want to run at bootup, each time you boot up. This will tell you how to do that.

Write a script. put it in the /etc/init.d/ directory. Lets say you called it FOO. You then run

% update-rc.d FOO defaults

You also have to make the file you created, FOO, executable, using $chmod +x FOO

aioobe
  • 413,195
  • 112
  • 811
  • 826
0

Using Headless Mode in the Java SE Platform may give you some additional latitude, depending on what your daemon does. In addition or @aioobe's suggestions, consider SuperUser.com for questions about startup and permissions.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045