我创建了一个 LaunchDaemon 脚本来为我们的 git repos 运行备份。我想以特定用户的身份运行该进程(git
),并将 Std 和 Err 日志输出到/var/log
当 launchd 尝试创建日志时,我得到的权限被拒绝。
Aug 18 10:15:00 server com.apple.launchd[1] (com.gitlab.backup[40752]): open("/var/log/gitlab_backup.log", ...): 13: Permission denied
Aug 18 10:15:00 server com.apple.launchd[1] (com.gitlab.backup[40752]): open("/var/log/gitlab_backup_err.log", ...): 13: Permission denied
我原本希望 launchd 能够创建日志,并将 chown 分配给密钥中指定的用户UserName
唯一的选项是登录到用户具有写权限的文件夹吗?
<?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.stardotstar.gitlab.backup</string>
<key>UserName</key>
<string>git</string>
<key>WorkingDirectory</key>
<string>/Users/git/gitlab</string>
<key>EnvironmentVariables</key>
<dict>
<key>RAILS_ENV</key>
<string>production</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>bundle</string>
<string>exec</string>
<string>rake</string>
<string>gitlab:backup:create</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>10</integer>
<key>Minute</key>
<integer>20</integer>
</dict>
<key>StandardOutPath</key>
<string>/var/log/gitlab/gitlab_backup.log</string>
<key>StandardErrorPath</key>
<string>/var/log/gitlab/gitlab_backup_err.log</string>
</dict>
</plist>