不同HTTP端口上的多个Jenkins守护程序(Mac OS X)

时间:2012-08-16 09:51:51

标签: macos continuous-integration jenkins

如何在Mac OS X系统上的不同HTTP端口(即7070和7071)上运行两个Jenkins守护进程。

1)我为每个dameon创建了两个帐户,包含Jenkins主目录:jeankins1,jenkins2

2)我复制了默认的dameon配置文件

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)我修改了dameon配置文件

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

jenkins-dameon-1.plist文件的内容:

<?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

jenkins-dameon-2.plist文件的内容:

<?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)我启动了两个Jenkins守护进程

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

我传递httpPort参数的方式似乎不正确,怎么办?

此解决方案仅适用于一个实例:Configure Jenkins Mac OS X native package to run in a different port

2 个答案:

答案 0 :(得分:2)

在我的PLIST文件中,我不再使用jenkins-runner.sh脚本,而是使用java可执行文件。

jenkins-dameon-1.plist文件的内容:

<?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>

jenkins-dameon-2.plist文件的内容:

<?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>

答案 1 :(得分:1)

作为OSX安装的一部分,有3个文件用于启动:

  1. /Library/Preferences/org.jenkins-ci.plist
  2. / Library / Application \ Support / Jenkins / jenkins-runner.sh
  3. /Library/LaunchDaemons/org.jenkins-ci.plist
  4. 要正确执行此操作,您需要复制所有3个文件并进行编辑。

    您可以在文件1中设置端口。为此,您需要使用此处所述的defaults命令(将文件名更改为您的副本):https://wiki.jenkins-ci.org/display/JENKINS/Thanks+for+using+OSX+Installer

    文件2是用于启动Jenkins并读取默认值的shell脚本。编辑您的文件副本,使其指向defaults =行中的文件1副本(减去.plist扩展名)。

    文件1控制守护程序的启动。您可以将其编辑为:

    • 指向您的文件2副本而不是原始shell脚本
    • 指向标准输出的其他日志目录(如果需要)
    • 指向标准错误的不同日志目录(如果需要)
    • 指向不同的JENKINS_HOME目录
    • 更改标签以反映您的新文件名
    • 如果需要,指定其他用户

    然后,您应该拥有在不同端口上启动2个不同守护进程所需的一切。