launchctl unload say: Could not find specified service

I'm trying to make a plist file in order to start nginx on boot. When starting nginx with launchctl it starts the service. But it cannot unload it, and print "Could not find specified service".

$ ps aux | grep nginx
me (...) grep nginx

$ sudo launchctl load /System/Library/LaunchDaemons/nginx.plist 
(no output)

$ ps aux | grep nginx
me (...) grep nginx
nobody (...) nginx: worker process
root (...) nginx: master process /opt/nginx/sbin/nginx

$ sudo launchctl unload /System/Library/LaunchDaemons/nginx.plist 
/System/Library/LaunchDaemons/nginx.plist: Could not find specified service

This is the content of /System/Library/LaunchDaemons/nginx.plist

$ cat /System/Library/LaunchDaemons/nginx.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
                       "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key><string>nginx</string>
    <key>Program</key><string>/opt/nginx/sbin/nginx</string>
    <key>KeepAlive</key><true/>
    <key>NetworkState</key><true/>
    <key>StandardErrorPath</key><string>/opt/nginx/logs/system.log</string>
    <key>LaunchOnlyOnce</key><true/>
  </dict>
</plist>

Any help appreciated. Cheers


Solution 1:

Try removing the sudo and just run:

launchctl unload /System/Library/LaunchDaemons/nginx.plist

When attempting to unload some LaunchDaemons, it will return "Could not find specified service" if using sudo.