title: Making Mac OSX launchctl launch a process as root on startup
body: <p>My question is how to make a MacOSX daemon process using launchd start with root privileges automatically after a reboot?</p>
  
  <p>I'm writing an application for in house use that blocks access to web sites. It is written in python and modifies the /ect/hosts file to disable or enable listed urls. The main application is in django and I created a python twisted daemon that does the actual modification of the /etc/hosts file as root access privileges are required.</p>
  
  <p>I have created a plist file which works with one minor issue. After rebooting the daemon process has my normal logon privileges instead of root privileges. </p>
  
  <p>A workaround is to stop the process with my normal privileges then startup the process with sudo.</p>
  
  <pre><code>launchctl unload /Library/LaunchAgents/com.balanceinfosystems.socialshields.twisted.plist 
  sudo launchctl load /Library/LaunchAgents/com.balanceinfosystems.socialshields.twisted.plist 
  </code></pre>
  
  <p>The plist file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC -//Apple Computer//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;Label&lt;/key&gt;
      &lt;string&gt;com.balanceinfosystems.socialshields.twisted&lt;/string&gt;
      &lt;key&gt;Program&lt;/key&gt;
      &lt;string&gt;/source/social_shields/social_shields_twisted.py&lt;/string&gt;
      &lt;key&gt;KeepAlive&lt;/key&gt;
      &lt;true/&gt;
    &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>