I created a pkg package to create a LaunchAgent to start a daemon, and in the post-install script file used this way to start the daemon:
launchctl load -s /Library/LaunchAgent/file-name.plist
It worked well.
However there is a problem: the first time the daemon started, while killing this daemon and re-installing LauchAgent, it could not start or kill the daemon. It will say this in the terminal:
file-name.plist: Already loaded
If I reboot or logout, it can start correctly. How can I fix this?
Modifying my y post-install script file to:
sudo -u $USER /bin/launchctl unload -S Aqua /Library/LauchAgent/file-name.plist sudo -u $USER /bin/launchctl load -S Aqua /Library/LauchAgent/file-name.plist
as per @Daniel’s comment did fix the previous problem. That worked well on Mac OS X 10.6 and 10.7, but on 10.5, the daemon could not start this way. I tried the script file in the terminal after installation. Here is some information:
launchctl:Error unloading: file-name.plist launch_msg():Socket is not connected