2

How to run two daemons of Jenkins, on different HTTP ports (i.e. 7070 and 7071), on Mac OS X system.

1) I create an two accounts for each dameon, containing Jenkins Home directory : jeankins1, jenkins2

2) I duplicate default dameon configuration file

sudo cp /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchDaemons/jenkins-dameon-1.plist
sudo cp /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchDaemons/jenkins-dameon-2.plist

3) I modify the dameon configuration files

sudo vi /Library/LaunchDaemons/jenkins-dameon-1.plist

Content of jenkins-dameon-1.plist file :

<?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>EnvironmentVariables</key>
        <dict>
                <key>JENKINS_HOME</key>
                <string>/Users/jenkins1/Jenkins/Home</string>
        </dict>
        <key>GroupName</key>
        <string>wheel</string>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>org.jenkins-ci</string>
        <key>ProgramArguments</key>
        <array>
                <string>/bin/bash</string>
                <string>/Library/Application Support/Jenkins/jenkins-runner.sh</string>
                <string>--httpPort=7070</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>UserName</key>
        <string>jenkins1</string>
        <key>SessionCreate</key>
        <true />
</dict>

sudo vi /Library/LaunchDaemons/jenkins-dameon-2.plist

Content of jenkins-dameon-2.plist file :

<?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>EnvironmentVariables</key>
        <dict>
                <key>JENKINS_HOME</key>
                <string>/Users/jenkins2/Jenkins/Home</string>
        </dict>
        <key>GroupName</key>
        <string>wheel</string>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>org.jenkins-ci</string>
        <key>ProgramArguments</key>
        <array>
                <string>/bin/bash</string>
                <string>/Library/Application Support/Jenkins/jenkins-runner.sh</string>
                <string>--httpPort=7071</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>UserName</key>
        <string>jenkins2</string>
        <key>SessionCreate</key>
        <true />
</dict>

4) I start the two Jenkins daemons

sudo launchctl load /Library/LaunchDaemons/jenkins-dameon-1.plist
sudo launchctl load /Library/LaunchDaemons/jenkins-dameon-2.plist

The way I pass httpPort parameter dont't seem correct, how to do ?

This solultion work only for one instance : Configure Jenkins Mac OS X native package to run in a different port

Community
  • 1
  • 1
Stéphane B.
  • 3,260
  • 2
  • 30
  • 35

2 Answers2

2

In my PLIST files, I don't use anymore jenkins-runner.sh script but java executable.

Content of jenkins-dameon-1.plist file :

<?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>EnvironmentVariables</key>
    <dict>
        <key>JENKINS_HOME</key>
        <string>/Users/jenkins1/Jenkins/Home</string>
    </dict>
    <key>GroupName</key>
    <string>daemon</string>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>jenkins1</string>
    <key>ProgramArguments</key>
    <array>
                <string>/usr/bin/java</string>
                <string>-jar</string>
                <string>/Applications/Jenkins/jenkins.war</string>
                <string>--httpPort=7070</string>
                <string>--ajp13Port=-1</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>UserName</key>
    <string>jenkins1</string>
        <key>SessionCreate</key>
    <true />
</dict>
</plist>

Content of jenkins-dameon-2.plist file :

<?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>EnvironmentVariables</key>
    <dict>
        <key>JENKINS_HOME</key>
        <string>/Users/jenkins2/Jenkins/Home</string>
    </dict>
    <key>GroupName</key>
    <string>daemon</string>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>jenkins2</string>
    <key>ProgramArguments</key>
    <array>
                <string>/usr/bin/java</string>
                <string>-jar</string>
                <string>/Applications/Jenkins/jenkins.war</string>
                <string>--httpPort=7071</string>
                <string>--ajp13Port=-1</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>UserName</key>
    <string>jenkins2</string>
        <key>SessionCreate</key>
    <true />
</dict>
</plist>
Stéphane B.
  • 3,260
  • 2
  • 30
  • 35
1

There are 3 files created as part of the install for OSX for launching:

  1. /Library/Preferences/org.jenkins-ci.plist
  2. /Library/Application\ Support/Jenkins/jenkins-runner.sh
  3. /Library/LaunchDaemons/org.jenkins-ci.plist

To do this correctly you would need to make copies of all 3 of the files and edit them.

File 1 is where you can set the port. To do so you need to use the defaults command as described here (changing the file name to your copy): https://wiki.jenkins-ci.org/display/JENKINS/Thanks+for+using+OSX+Installer

File 2 is the shell script to launch Jenkins and read defaults. Edit your copy of the file to point to your copy of file 1 (minus the .plist extension) in the defaults= line.

File 1 controls the startup of the daemon. You would edit it to:

  • point to your copy of file 2 instead of the original shell script
  • point to a different log directory for standard out if desired
  • point to a different log directory for standard err if desired
  • point to a different JENKINS_HOME directory
  • change the label to reflect your new file name
  • To specify a different user if that is desired

You should then have everything necessary to launch 2 different daemons on different ports.