Skip to content

fix: load packages whose run hook is a run file in the package root - #103

Merged
tas50 merged 1 commit into
mainfrom
fix/run-hook-in-package-root
Aug 30, 2026
Merged

tas50 merged 1 commit into
mainfrom
fix/run-hook-in-package-root

Conversation

@tas50

@tas50 tas50 commented Aug 30, 2026

Copy link
Copy Markdown
Member

The integration suites from #99 went green on library-package and red on default and user-toml, both of which load core/redis. The converge exited 0, and then the verifier found this:

ok: hab CLI installed: hab 1.6.1245/20250905140900
ok: hab-sup systemd unit written
ok: hab-sup service is running
ok: supervisor answers hab svc status
FAIL: core/redis was not loaded
--- hab svc status ---
No services loaded.

hab pkg install core/redis had succeeded a fraction of a second earlier. The load was never attempted.

Why

run_command gates the load on this:

if [ -f "$(sudo hab pkg path core/redis)/hooks/run" ]

The supervisor accepts a run hook in either of two places — hooks/run, written from a hook template, or a run file in the package root, which is what pkg_svc_run in a plan produces. We only ever checked the first.

core/redis is built the second way:

$ tar -tf core-redis-4.0.14-20240106065001-x86_64-linux.hart | grep -E '/(run|hooks/)'
hab/pkgs/core/redis/4.0.14/20240106065001/run

So for every package written that way — and pkg_svc_run is the older, simpler, still very common style, including the core/redis example in our own README — the provisioner installed the package, skipped the entire load branch, and reported success. No error, no warning, nothing in the output to suggest the service you asked for was never started.

The fix

Both platform paths now resolve the package path once and check both locations:

pkg_path="$(sudo hab pkg path core/redis)"
if [ -f "$pkg_path/hooks/run" ] || [ -f "$pkg_path/run" ]
$PkgPath = hab pkg path core/redis
if (@("hooks\run", "hooks\run.ps1", "run", "run.ps1") | Where-Object { Test-Path -Path (Join-Path $PkgPath $_) }) {

The Windows side also checks the .ps1 form of each, which is how a Windows plan spells the same two hooks.

library-package (core/jq-static, no run hook of either kind) keeps passing, so the negative branch is still covered — a library or build-time dependency still converges without a service being started.

Verification

$ bundle exec cookstyle --chefstyle
5 files inspected, no offenses detected

$ bundle exec rake test
152 examples, 0 failures
Line Coverage: 100.0% (226 / 226)
Branch Coverage: 92.74% (115 / 124)

The real check is this PR's own default and user-toml integration jobs, which should now go green.

run_command decided whether to `hab svc load` by testing for
`hooks/run` inside the installed package. The supervisor accepts a run
hook in either of two places: `hooks/run`, written from a hook
template, or a `run` file in the package root, which is what
`pkg_svc_run` in a plan produces.

Packages built the second way -- core/redis is one, and it is the
example in our own README -- were installed by the converge and then
silently never loaded. `hab svc status` said "No services loaded" and
Test Kitchen reported the converge as a success, because the whole
`hab svc load` branch was skipped rather than failing.

Both platform paths now resolve the package path once and check both
locations, and the Windows path also checks the .ps1 form of each.

Found by the integration suites added in #99, which is what the default
and user-toml suites are currently failing on.

Signed-off-by: Tim Smith <tim@mondoo.com>
@tas50
tas50 merged commit aac0970 into main Aug 30, 2026
3 checks passed
@tas50
tas50 deleted the fix/run-hook-in-package-root branch August 30, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant