Search code examples
macosunixhudsondaemonlaunchd

Run daemon as another user on mac os x


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

And the I try to run jenkins as jenkins user:

sudo su - jenkins -c run_jenkins.sh

and got an error:

su: no directory

after I created directory for jenkins user:

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

followed next error:

su: unknown login: jenkins

General quiestion:

  1. How can I create an _www like user for a daemon, without home directory i.e.
  2. How can I run a script as this new user.

Thanks for help!


Solution

  • 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.