Skip to content

Commit

Permalink
Merge pull request #1240 from habitat-sh/jtimberman/always-chpst
Browse files Browse the repository at this point in the history
Always render run script with chpst
  • Loading branch information
reset authored Sep 15, 2016
2 parents 7d2dccb + d206fc5 commit 2553bea
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion components/builder-admin/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_bin_dirs=(bin)
pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/libarchive)
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
bin="bldr-admin"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
4 changes: 0 additions & 4 deletions components/builder-api-proxy/hooks/run

This file was deleted.

12 changes: 9 additions & 3 deletions components/builder-api-proxy/plan.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
pkg_origin=core
pkg_name=builder-api-proxy
pkg_description="HTTP Proxy service fronting the Habitat Builder API service"
pkg_version=0.1.0
pkg_version=$(cat "${PLAN_CONTEXT}/../../VERSION")
pkg_maintainer="The Habitat Maintainers <[email protected]"
pkg_source=nosuchfile.tar.xz
pkg_license=("apache2")
pkg_deps=(core/nginx core/curl)
pkg_license=("Apache-2.0")

# we depend on a specific version of nginx until we can build this
# with a released version of hab that fixes the dependency version
# sorting bug: https://github.com/habitat-sh/habitat/pull/1221
pkg_deps=(core/nginx/1.10.1 core/curl)
pkg_svc_run="nginx -c ${pkg_svc_config_path}/nginx.conf"
# nginx is configured to drop privileges to hab:hab
pkg_svc_user="root"
pkg_svc_group="root"

Expand Down
4 changes: 1 addition & 3 deletions components/builder-api/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ pkg_deps=(core/glibc core/openssl core/coreutils core/gcc-libs core/zeromq core/
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config core/node core/phantomjs)
pkg_expose=(9636)
bin="bldr-api"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_user="root"
pkg_svc_group="root"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
rm -Rdf $HAB_CACHE_SRC_PATH/ui-$pkg_name-$pkg_version
Expand Down
2 changes: 1 addition & 1 deletion components/builder-depot/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_deps=(core/glibc core/gcc-libs core/libarchive core/libsodium core/openssl c
pkg_build_deps=(core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
pkg_bin_dirs=(bin)
bin="$pkg_name"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
2 changes: 1 addition & 1 deletion components/builder-jobsrv/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
pkg_expose=(5566 5567)
bin="bldr-job-srv"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
2 changes: 1 addition & 1 deletion components/builder-router/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
pkg_expose=(5562 5563)
bin="bldr-router"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
2 changes: 1 addition & 1 deletion components/builder-sessionsrv/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_bin_dirs=(bin)
pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/libarchive)
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
bin="bldr-session-srv"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
2 changes: 1 addition & 1 deletion components/builder-vault/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_bin_dirs=(bin)
pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/libarchive)
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
bin="bldr-vault"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
2 changes: 1 addition & 1 deletion components/builder-worker/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_bin_dirs=(bin)
pkg_deps=(core/glibc core/openssl core/gcc-libs core/zeromq core/libsodium core/libarchive)
pkg_build_deps=(core/protobuf core/protobuf-rust core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc core/pkg-config)
bin="bldr-worker"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
4 changes: 2 additions & 2 deletions components/director/habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pkg_deps=(core/glibc core/gcc-libs core/libarchive core/libsodium core/openssl)
pkg_build_deps=(core/coreutils core/cacerts core/cargo-nightly core/rust core/gcc)
pkg_bin_dirs=(bin)
bin="hab-director"
pkg_svc_run="bin/$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_user=root
pkg_svc_run="$bin start -c ${pkg_svc_path}/config.toml"
pkg_svc_user="root"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
Expand Down
36 changes: 17 additions & 19 deletions components/plan-build/bin/hab-plan-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1993,11 +1993,14 @@ do_default_build_config() {
return 0
}

# Write out the `$pkg_prefix/run` file. If a file named `hooks/run` exists, we
# skip this step. Otherwise, we look for `$pkg_svc_run`, and use that.
# Write out the `$pkg_prefix/run` file. If a file named `hooks/run`
# exists, we skip this step. Otherwise, we look for `$pkg_svc_run`,
# and use that. We assume that the binary used in the `$pkg_svc_run`
# command is set in the $PATH.
#
# If the `$pkg_svc_user` is set to a value that is not `root`, we change
# the service to be run under that user before we start it.
# This will write a `run` script that uses `chpst` to run the command
# as the `$pkg_svc_user` and `$pkg_svc_group`. These are `hab` by
# default.
#
# Delegates most of the implementation to the `do_default_build_server()`
# function.
Expand All @@ -2009,32 +2012,27 @@ do_build_service() {
# Default implementation of the `do_build_service()` phase.
do_default_build_service() {
build_line "Writing service management scripts"
if [[ -f "$PLAN_CONTEXT/hooks/run" ]]; then
if [[ -f "${PLAN_CONTEXT}/hooks/run" ]]; then
build_line "Using run hook ${PLAN_CONTEXT}/hooks/run"
return 0
else
if [[ -n "${pkg_svc_run}" ]]; then
if [[ -n "$pkg_svc_user" && "${pkg_svc_user}" != "root" ]]; then
cat <<EOT >> $pkg_prefix/run
# We use chpst to ensure that the script works outside `hab-sup`
# for debugging purposes, or under a `hab-director`.
build_line "Writing ${pkg_prefix}/run script to run ${pkg_svc_run} as ${pkg_svc_user}:${pkg_svc_group}"
cat <<EOT >> $pkg_prefix/run
#!/bin/sh
cd $pkg_svc_path
if [ "\$(whoami)" = "root" ]; then
exec chpst \\
-U ${pkg_svc_user}:$pkg_svc_group \\
-u ${pkg_svc_user}:$pkg_svc_group \\
$pkg_prefix/$pkg_svc_run 2>&1
-U ${pkg_svc_user}:${pkg_svc_group} \\
-u ${pkg_svc_user}:${pkg_svc_group} \\
${pkg_svc_run} 2>&1
else
exec $pkg_prefix/$pkg_svc_run 2>&1
exec ${pkg_svc_run} 2>&1
fi
EOT
else
cat <<EOT >> $pkg_prefix/run
#!/bin/sh
cd $pkg_svc_path
exec $pkg_prefix/$pkg_svc_run 2>&1
EOT
fi
fi
fi
return 0
Expand Down
2 changes: 1 addition & 1 deletion www/source/docs/create-plans.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pkg_build_deps=(core/patch core/make core/gcc)
pkg_bin_dirs=(bin)
pkg_lib_dirs=(lib)
pkg_expose=(80 443)
pkg_svc_run="bin/httpd -DFOREGROUND -f $pkg_svc_config_path/httpd.conf"
pkg_svc_run="httpd -DFOREGROUND -f $pkg_svc_config_path/httpd.conf"
pkg_svc_user="root"

do_build() {
Expand Down

0 comments on commit 2553bea

Please sign in to comment.