在mac os x上以另一个用户身份运行守护程序

spe*_*key 3 unix macos daemon hudson launchd

我正在尝试在Mac OS上为jenkins创建单独的用户并使用此用户运行它.我创建了一个新用户:

# 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
Run Code Online (Sandbox Code Playgroud)

而我试图像jenkins用户一样运行jenkins:

sudo su - jenkins -c run_jenkins.sh
Run Code Online (Sandbox Code Playgroud)

并得到一个错误:

su: no directory
Run Code Online (Sandbox Code Playgroud)

在为jenkins用户创建目录之后:

sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins
Run Code Online (Sandbox Code Playgroud)

接下来的错误:

su: unknown login: jenkins
Run Code Online (Sandbox Code Playgroud)

一般情况:

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

感谢帮助!

bio*_*ffe 8

男人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.
Run Code Online (Sandbox Code Playgroud)