How do I get my LaunchAgent to run as root?
To get a user LaunchAgent executing a script to run as root you have to do the following: 

Modify the permissions of the script. Add the script (or command) to the sudoers file in the context of the user and finally add and load a proper launch agent plist.

This approach might create severe security holes!



In the example below I use the startup.sh of eXit-db 2.2:


Create a plist:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Disabled&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.eXist_DB&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/usr/bin/sudo&lt;/string&gt;
        &lt;string&gt;/Applications/eXist-db.app/Contents/Resources/eXist-db/bin/startup.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;StandardErrorPath&lt;/key&gt;
    &lt;string&gt;/tmp/eXist_DB.err&lt;/string&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
    &lt;string&gt;/tmp/eXist_DB.out&lt;/string&gt;
    &lt;key&gt;ThrottleInterval&lt;/key&gt;
    &lt;integer&gt;10&lt;/integer&gt;
&lt;/dict&gt;
&lt;/plist&gt;


and save it as org.eXist_DB.plist in ~/Library/LaunchAgents

The last key:

    &lt;key&gt;ThrottleInterval&lt;/key&gt;
    &lt;integer&gt;10&lt;/integer&gt;


might not be necessary. In my VM it was - for unknown reasons.
Modify the permissions of startup.sh:

sudo chown root /Applications/eXist-db.app/Contents/Resources/eXist-db/bin/startup.sh
sudo chmod 4755 /Applications/eXist-db.app/Contents/Resources/eXist-db/bin/startup.sh

Modify the sudoers file:

sudo visudo

add a line to enable executing a command without the need to enter the sudo  password

# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL


->

# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
your_user_name ALL=(ALL) NOPASSWD: /Applications/eXist-db.app/Contents/Resources/eXist-db/bin/startup.sh

Finally enter:

launchctl load -w ~/Library/LaunchAgents/org.eXist_DB.plist


to load and start the launch agent