Mac 创建自启动后台服务

 

首先创建一个文件 com.gotox.startup.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>com.gotox.startup.plist</string>
    <key>KeepAlive</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/zzc/SmallSoftware/gotox/run.sh</string>
        <!-- <string>-local_addr=127.0.0.1:5000</string>
        <string>-pac_addr=127.0.0.1:5001</string>
        <string>-remote_addr=127.0.0.1:5002</string> -->
    </array>
</dict>
</plist>

com.gotox.startup.plist 放到 ~/Library/LaunchAgents 下,并用 launchctl 启动:

cp com.gotox.startup.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.gotox.startup.plist