Skip to content

Commit

Permalink
dev-util/buildbot-worker: Make the init script multi-instance capable
Browse files Browse the repository at this point in the history
Use the same method as the buildbot master init script for multiple instances
on the same host.
Add RUNTIME_PYTHON variable (optional) to the conf.d to specify the desired
python to run it from.

Package-Manager: Portage-2.3.6_p65, Repoman-2.3.2_p133
  • Loading branch information
dol-sen committed Aug 21, 2017
1 parent 0b5fbd1 commit 9cddfbc
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 7 deletions.
122 changes: 122 additions & 0 deletions dev-util/buildbot-worker/buildbot-worker-0.9.10-r1.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI="5"
PYTHON_COMPAT=( python2_7 python3_5 )

EGIT_REPO_URI="https://github.com/buildbot/buildbot.git"

[[ ${PV} == *9999 ]] && inherit git-r3
inherit readme.gentoo user distutils-r1

DESCRIPTION="BuildBot Worker (slave) Daemon"
HOMEPAGE="https://buildbot.net/ https://github.com/buildbot/buildbot https://pypi.python.org/pypi/buildbot-worker"

MY_PV="${PV/_p/.post}"
MY_P="${PN}-${MY_PV}"
[[ ${PV} == *9999 ]] || SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${MY_P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
if [[ ${PV} == *9999 ]]; then
KEYWORDS=""
else
KEYWORDS="~amd64"
fi
IUSE="test"

RDEPEND=">=dev-python/setuptools-21.2.1[${PYTHON_USEDEP}]
>=dev-python/twisted-17.5.0[${PYTHON_USEDEP}]
dev-python/future[${PYTHON_USEDEP}]
!<dev-util/buildbot-0.9.7
"
DEPEND="${RDEPEND}
test? (
dev-python/mock[${PYTHON_USEDEP}]
dev-python/setuptools_trial[${PYTHON_USEDEP}]
)
"

S="${WORKDIR}/${MY_P}"
[[ ${PV} == *9999 ]] && S=${S}/slave

pkg_setup() {
enewuser buildbot

DOC_CONTENTS="The \"buildbot\" user and the \"buildbot_worker\" init script has been added
to support starting buildbot_worker through Gentoo's init system. To use this,
execute \"emerge --config =${CATEGORY}/${PF}\" to create a new instance.
Set up your build worker following the documentation, make sure the
resulting directories are owned by the \"buildbot\" user and point
\"${ROOT}etc/conf.d/buildbot_worker.myinstance\" at the right location.
The scripts can run as a different user if desired."
}

python_test() {
distutils_install_for_testing

esetup.py test || die "Tests failed under ${EPYTHON}"
}

python_install_all() {
distutils-r1_python_install_all

doman docs/buildbot-worker.1

newconfd "${FILESDIR}/buildbot_worker.confd2" buildbot_worker
newinitd "${FILESDIR}/buildbot_worker.initd2" buildbot_worker

readme.gentoo_create_doc
}

pkg_postinst() {
readme.gentoo_print_elog

if [[ -n ${REPLACING_VERSIONS} ]]; then
ewarn
ewarn "Starting with buildbot-worker-0.9.10-r1, more than one instance of a buildbot_worker"
ewarn "can be run simultaneously. Note that \"BASEDIR\" in the buildbot_worker configuration file"
ewarn "is now the common base directory for all instances. If you are migrating from an older"
ewarn "version, make sure that you copy the current contents of \"BASEDIR\" to a subdirectory."
ewarn "The name of the subdirectory corresponds to the name of the buildbot_worker instance."
ewarn "In order to start the service running OpenRC-based systems need to link to the init file:"
ewarn " ln --symbolic --relative /etc/init.d/buildbot_worker /etc/init.d/buildbot_worker.myinstance"
ewarn " rc-update add buildbot_worker.myinstance default"
ewarn " /etc/init.d/buildbot_worker.myinstance start"
ewarn "Systems using systemd can do the following:"
ewarn " systemctl enable [email protected]"
ewarn " systemctl enable buildbot_worker.target"
ewarn " systemctl start buildbot_worker.target"
fi
}

pkg_config() {
local buildworker_path="/var/lib/buildbot_worker"
einfo "This will prepare a new buildbot_worker instance in ${buildworker_path}."
einfo "Press Control-C to abort."

einfo "Enter the name for the new instance: "
read instance_name
[[ -z "${instance_name}" ]] && die "Invalid instance name"

local instance_path="${buildworker_path}/${instance_name}"
if [[ -e "${instance_path}" ]]; then
eerror "The instance with the specified name already exists:"
eerror "${instance_path}"
die "Instance already exists"
fi

local buildbot="/usr/bin/buildbot"
if [[ ! -d "${buildworker_path}" ]]; then
mkdir --parents "${buildworker_path}" || die "Unable to create directory ${buildworker_path}"
fi
"${buildbot}" create-master "${instance_path}" &>/dev/null || die "Creating instance failed"
chown --recursive buildbot "${instance_path}" || die "Setting permissions for instance failed"
mv "${instance_path}/master.cfg.sample" "${instance_path}/master.cfg" \
|| die "Moving sample configuration failed"
ln --symbolic --relative "/etc/init.d/buildbot_worker" "/etc/init.d/buildbot_worker.${instance_name}" \
|| die "Unable to create link to init file"

einfo "Successfully created a buildbot_worker instance at ${instance_path}."
einfo "To change the default settings edit the buildbot.tac file in this directory."
}
60 changes: 54 additions & 6 deletions dev-util/buildbot-worker/buildbot-worker-9999.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pkg_setup() {

DOC_CONTENTS="The \"buildbot\" user and the \"buildbot_worker\" init script has been added
to support starting buildbot_worker through Gentoo's init system. To use this,
set up your build worker following the documentation, make sure the
execute \"emerge --config =${CATEGORY}/${PF}\" to create a new instance.
Set up your build worker following the documentation, make sure the
resulting directories are owned by the \"buildbot\" user and point
\"${ROOT}etc/conf.d/buildbot_worker\" at the right location. The scripts can
run as a different user if desired. If you need to run more than one
build worker, just copy the scripts."
\"${ROOT}etc/conf.d/buildbot_worker.myinstance\" at the right location.
The scripts can run as a different user if desired."
}

python_test() {
Expand All @@ -63,12 +63,60 @@ python_install_all() {

doman docs/buildbot-worker.1

newconfd "${FILESDIR}/buildbot_worker.confd" buildbot_worker
newinitd "${FILESDIR}/buildbot_worker.initd" buildbot_worker
newconfd "${FILESDIR}/buildbot_worker.confd2" buildbot_worker
newinitd "${FILESDIR}/buildbot_worker.initd2" buildbot_worker

readme.gentoo_create_doc
}

pkg_postinst() {
readme.gentoo_print_elog

if [[ -n ${REPLACING_VERSIONS} ]]; then
ewarn
ewarn "Starting with buildbot-worker-0.9.10-r1, more than one instance of a buildbot_worker"
ewarn "can be run simultaneously. Note that \"BASEDIR\" in the buildbot_worker configuration file"
ewarn "is now the common base directory for all instances. If you are migrating from an older"
ewarn "version, make sure that you copy the current contents of \"BASEDIR\" to a subdirectory."
ewarn "The name of the subdirectory corresponds to the name of the buildbot_worker instance."
ewarn "In order to start the service running OpenRC-based systems need to link to the init file:"
ewarn " ln --symbolic --relative /etc/init.d/buildbot_worker /etc/init.d/buildbot_worker.myinstance"
ewarn " rc-update add buildbot_worker.myinstance default"
ewarn " /etc/init.d/buildbot_worker.myinstance start"
ewarn "Systems using systemd can do the following:"
ewarn " systemctl enable [email protected]"
ewarn " systemctl enable buildbot_worker.target"
ewarn " systemctl start buildbot_worker.target"
fi
}

pkg_config() {
local buildworker_path="/var/lib/buildbot_worker"
einfo "This will prepare a new buildbot_worker instance in ${buildworker_path}."
einfo "Press Control-C to abort."

einfo "Enter the name for the new instance: "
read instance_name
[[ -z "${instance_name}" ]] && die "Invalid instance name"

local instance_path="${buildworker_path}/${instance_name}"
if [[ -e "${instance_path}" ]]; then
eerror "The instance with the specified name already exists:"
eerror "${instance_path}"
die "Instance already exists"
fi

local buildbot="/usr/bin/buildbot"
if [[ ! -d "${buildworker_path}" ]]; then
mkdir --parents "${buildworker_path}" || die "Unable to create directory ${buildworker_path}"
fi
"${buildbot}" create-master "${instance_path}" &>/dev/null || die "Creating instance failed"
chown --recursive buildbot "${instance_path}" || die "Setting permissions for instance failed"
mv "${instance_path}/master.cfg.sample" "${instance_path}/master.cfg" \
|| die "Moving sample configuration failed"
ln --symbolic --relative "/etc/init.d/buildbot_worker" "/etc/init.d/buildbot_worker.${instance_name}" \
|| die "Unable to create link to init file"

einfo "Successfully created a buildbot_worker instance at ${instance_path}."
einfo "To change the default settings edit the buildbot.tac file in this directory."
}
14 changes: 14 additions & 0 deletions dev-util/buildbot-worker/files/buildbot_worker.confd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Path to the build slave's basedir.
BASEDIR="/var/lib/buildbot_worker"

# User account for the buildslave.
# The basedir should be owned by this user.
USERNAME="buildbot"

# Extra options passed to twistd.
TWISTD_OPTS=""

# Optional specifiv python version to run in
# (if not the system default version)
# ie: RUNTIME_PYTHON="/usr/bin/python2.7"
RUNTIME_PYTHON=""
2 changes: 1 addition & 1 deletion dev-util/buildbot-worker/files/buildbot_worker.initd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
Expand Down
57 changes: 57 additions & 0 deletions dev-util/buildbot-worker/files/buildbot_worker.initd2
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/sbin/openrc-run
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

BUILDWORKER_NAME=${RC_SVCNAME:16}
BUILDWORKER_PATH="${BASEDIR}/${BUILDWORKER_NAME}"
depend() {
need net
}

checkconfig() {
if [ -z "${BUILDWORKER_NAME}" ]; then
eerror "Buildbot-worker name not defined. Please link buildbot_worker.foo to this file to start the buildbot_worker with the name \"foo\"."
return 1
fi
if [ -z "${BASEDIR}" ]; then
eerror "BASEDIR not set"
return 1
fi
if [ -z "${USERNAME}" ]; then
eerror "USERNAME not set"
return 1
fi
if [ ! -d "${BUILDWORKER_PATH}" ]; then
eerror "${BUILDWORKER_PATH} is not a directory"
return 1
fi
if [ ! -e "${BUILDWORKER_PATH}/buildbot.tac" ]; then
eerror "${BUILDWORKER_PATH} does not contain buildbot.tac"
return 1
fi
if [ ! -e "${RUNTIME_PYTHON}" ]; then
RUNTIME_PYTHON="/usr/bin/python"
fi
}

start() {
checkconfig || return 1
ebegin "Starting buildbot-worker in ${BUILDWORKER_PATH}"
# We set HOME here to make something valid show up in the env of child
# processes spawned by the buildbot-worker.
start-stop-daemon --start -u "${USERNAME}" \
--pidfile "${BUILDWORKER_PATH}/buildbot_worker.pid" \
--env HOME="${BUILDWORKER_PATH}" \
--exec "${RUNTIME_PYTHON}" -- /usr/bin/twistd \
--no_save \
--logfile="${BUILDWORKER_PATH}/twistd.log" \
--pidfile="${BUILDWORKER_PATH}/buildbot_worker.pid" \
--python="${BUILDWORKER_PATH}/buildbot.tac"
eend $?
}

stop() {
ebegin "Stopping buildbot-worker in ${BUILDWORKER_PATH}"
start-stop-daemon --stop --pidfile "${BUILDWORKER_PATH}/buildbot_worker.pid"
eend $?
}

0 comments on commit 9cddfbc

Please sign in to comment.