Skip to content

Instantly share code, notes, and snippets.

@emanon001
Forked from shunirr/README.md
Last active December 9, 2015 20:48
Show Gist options
  • Save emanon001/4326428 to your computer and use it in GitHub Desktop.
Save emanon001/4326428 to your computer and use it in GitHub Desktop.

Jenkins をOS X のログインユーザー権限のデーモンで自動起動しておく設定

必要なもの

うっかり jenkins.pkg を入れてしまった人はアンインストールする

sh /Library/Application\ Support/Jenkins/Uninstall.command

各ディレクトリを作る

mkdir -p ~/Library/LaunchAgents/
mkdir -p ~/.jenkins/
mkdir -p ~/bin/
mkdir -p ~/lib/java/

ファイルを配置する

mv jenkins.plist ~/Library/LaunchAgents/
mv jenkins-runner.sh ~/bin/
mv jenkins.war ~/lib/java/

jenkins.plist の ${USER} と ${HOME} を書き換える

  • ${USER} -> shunirr
  • ${HOME} -> /Users/shunirr
  • みたいな感じ

launchd に登録する

launchctl load -wF -D user  ~/Library/LaunchAgents/jenkins.plist
launchctl start jenkins
#!/bin/bash
#
# Startup script used by Jenkins launchd job.
# Mac OS X launchd process calls this script to customize
# the java process command line used to run Jenkins.
#-
# Customizable parameters are found in
# ~/Library/Preferences/jenkins.plist
#
# You can manipulate it using the "defaults" utility.
# See "man defaults" for details.
defaults="defaults read ${HOME}/Library/Preferences/jenkins"
war=`$defaults war` || war="${HOME}/lib/java/jenkins.war"
javaArgs="-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"
heapSize=`$defaults heapSize` && javaArgs="$javaArgs -Xmx${heapSize}"
home=`$defaults JENKINS_HOME` && export JENKINS_HOME="$home"
add_to_args() {
val=`$defaults $1` && args="$args --${1}=${val}"
}
args=""
add_to_args prefix
add_to_args httpPort
add_to_args httpListenAddress
add_to_args httpsPort
add_to_args httpsListenAddress
add_to_args ajp13Port
add_to_args ajp13ListenAddress
echo "JENKINS_HOME=$JENKINS_HOME"
echo "Jenkins command line for execution:"
echo /usr/bin/java $javaArgs -jar "$war" $args
exec /usr/bin/java $javaArgs -jar "$war" $args
<?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>${HOME}/.jenkins</string>
</dict>
<key>GroupName</key>
<string>staff</string>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>jenkins</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>${HOME}/bin/jenkins-runner.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>${USER}</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment