0

I'm currently in the process of creating an installer for a Java application that I am porting to OS X. I'd love to be able to keep it as simple .dmg with a .app inside because I'd rather avoid the wizard that .pkg installers open.

However, there are some things that I must do in addition to just copying the binaries to /Applications. More precisely I want to install a background daemon that should run as root and auto-start whenever the system starts. Is this possible to achieve with an .app and if so how?

I should also add that the background daemon and the app visible to the user are two different binaries. Is that possible to have within an .app or does it only support one binary? From what I understand it's just a directory so it should be possible to keep the background daemon in the .app as well.

Yrlec
  • 3,401
  • 6
  • 39
  • 75
  • Consider using an installer-generator like [install4j](http://www.ej-technologies.com/products/install4j/overview.html). Will simplify your life immensely. – Hollis Waite Sep 14 '13 at 16:25

1 Answers1

1

You have to add to your main program (the one that is lauched when the user dbl click the app bundle), at startup, a one time initialization function that do everything needed to register your background daemon something like :

public static void main(String[] args) {
  boolean firstStartup = aFunctionToDetectIfFirstStartup();
  if (firstStartup) {
    doAllTheFirstStartupInit();
    markFirstStartupAsDone();
  }
  doTheRealJobNow();
}
superbob
  • 1,628
  • 13
  • 24
  • That's a good idea! However, I'm assuming that the program must be running as root in order for it have the permission to do the init. How do I configure the app to request root permissions the first time it starts? – Yrlec Sep 14 '13 at 15:15
  • I'm not an expert in OS X application startup, but there may be a way to do what you need with users privileges. If you need root privileges, you must bring up the "enter admin password" ui popup, but I don't know how to do this (especially from java code) – superbob Sep 14 '13 at 16:16