在Mac OS X上以其他用户身份运行守护程序

问题描述:

我现在正在尝试在Mac Os上为jenkins创建单独的用户,并与该用户一起运行. 我创建了一个新用户:

I'm trying right now to create separate user for jenkins on Mac Os and run it with this user. I've created a new user:

# Create the group
sudo dscl . create /Groups/jenkins
sudo dscl . create /Groups/jenkins PrimaryGroupID 300
# Create the user
sudo dscl . create /Users/jenkins
sudo dscl . create /Users/jenkins PrimaryGroupID 300
sudo dscl . create /Users/jenkins UniqueID 300
sudo dscl . create /Users/jenkins UserShell /bin/bash
# Set the users pasword
sudo dscl . passwd /Users/jenkins 123qweASD
# Add the user to the group
sudo dscl . append /Groups/jenkins GroupMembership jenkins

然后我尝试以jenkins用户身份运行jenkins:

And the I try to run jenkins as jenkins user:

sudo su - jenkins -c run_jenkins.sh

出现错误:

su: no directory

为詹金斯用户创建目录后:

after I created directory for jenkins user:

sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins

后接下一个错误:

su: unknown login: jenkins

一般问题:

  1. 如何在没有主目录的情况下为守护程序创建一个类似_www的用户
  2. 如何以该新用户身份运行脚本.

感谢帮助!

man launchd.plist

 UserName <string>
 This optional key specifies the user to run the job as. This key is only
 applicable when launchd is running as root.

 GroupName <string>
 This optional key specifies the group to run the job as. This key is only
 applicable when launchd is running as root. If UserName is set and Group-
 Name is not, the the group will be set to the default group of the user.