【问题标题】:Run daemon as another user on mac os x在 mac os x 上以另一个用户身份运行守护进程
【发布时间】:2011-11-02 17:24:22
【问题描述】:

我现在正在尝试在 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

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

sudo su - jenkins -c run_jenkins.sh

得到一个错误:

su: no directory

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

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

跟随下一个错误:

su: unknown login: jenkins

一般问题:

  1. 如何为守护进程创建 _www 类用户,没有主目录,即
  2. 如何以这个新用户的身份运行脚本。

感谢您的帮助!

【问题讨论】:

  • 我们是在谈论启动类型的守护进程吗?
  • 是的,我为此提供了 plist。只想测试它是否有效。

标签: macos unix hudson daemon launchd


【解决方案1】:

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.

【讨论】:

    【解决方案2】:

    您可能需要使用run_jenkins.sh 的绝对值(假设它的/Users/jenkins/run_jenkins.sh):

    sudo su - jenkins -c /Users/jenkins/run_jenkins.sh
    

    【讨论】:

      【解决方案3】:

      su - 模拟正常登录,因此需要为常规登录设置帐户(定义 shell 和主目录等)。除非你出于某种原因需要这个,否则就让 sudo 去做吧:

      sudo -u jenkins run_jenkins.sh
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-12
        • 2013-06-14
        • 2020-04-09
        • 2012-05-17
        • 1970-01-01
        • 2016-05-25
        • 2023-03-23
        相关资源
        最近更新 更多