Yrlec
Yrlec

Reputation: 3458

Start service as root with install4j

I'm creating a OS X installer for our Java app using Install4j. The installer is set to install a service and then launch it. It does this but it runs the service as the current user instead of root. After rebooting the service will run as root (since it's installed as a LaunchDaemon). How can I set it to run as root when the installer launches it for the first time?

Update 1: After adding the "Start a service" action after "Install a service" I get the following info from the logs:

> [INFO]
> com.install4j.runtime.beans.actions.services.InstallServiceAction [ID
> 67]: Execute action
>        Property description: 
>        Property installedServices: []
>        Property serviceName: null
>        Property executable: null
>        Property launcherId: 57
>        Property accountNameOrSid: 
>        Property macosIdentifier: com.degoo.backgroundService
>        Property password: [logging of password is disabled]
>        Property serviceAccount: Local System
>        Property windowsArguments: 
>        Property windowsDependencies: 
>        Property windowsPriority: Normal
>        Property autoStart: true
>        Property interactive: false
>        Property keepCurrentAccount: false
>        Property restartOnFailure: true
>        Property persistentProperties: {}
>        Property rollbackSupported: true
>        Execute action successful after 21 ms [INFO] com.install4j.runtime.beans.actions.services.StartServiceAction [ID
> 223]: Execute action
>        Property autostartOnly: false
>        Property serviceName: null
>        Property executable: null
>        Property launcherId: 57
>        Property rollbackSupported: true
>        usedExecutable: /Applications/Degoo/DegooBackgroundService
>        SUID elevation: true, true
> 
> ERROR] com.install4j.runtime.installer.helper.launching.LaunchHelper:
> return value is 126 [ERROR]
> com.install4j.runtime.beans.actions.services.StartServiceAction [ID
> 223]: Execute action not successful after 519 ms [INFO]
> com.install4j.runtime.beans.screens.InstallationScreen [ID 8]:
> Rollback barrier reached
>        command: move 1 screens, executing actions, checking condition [INFO] com.install4j.runtime.beans.screens.FinishedScreen [ID 12]:
> Show screen [INFO] com.install4j.runtime.beans.screens.FinishedScreen
> [ID 12]: command: finish
>        cleaning up
>        Finished

Upvotes: 2

Views: 1571

Answers (2)

Yrlec
Yrlec

Reputation: 3458

I found the problem. I had the "Start Service" action below "Installation" in the action tree. After moving it below "Finished" instead it executed successfully as root.

Upvotes: 2

Ingo Kegel
Ingo Kegel

Reputation: 48005

Use the "Start a service" action after the "Install a service" action instead of executing the launcher directly.

Upvotes: 3

Related Questions