habitat-sh / habitat

Modern applications with built-in automation
https://www.habitat.sh
Apache License 2.0
2.61k stars 315 forks source link

`hab unload` followed by `hab start` does not usually result in a service restart #4807

Open stevendanna opened 6 years ago

stevendanna commented 6 years ago

Running hab unload followed by hab start does not usually result in a service restart.

This isn't necessarily a bug but a consequence of the current hab-sup implementation that might not be clear to users from the documentation alone.

If the unload and start happen inside the file_watcher timeout and if the start command produces the same spec file content that existed on disk before the unload, no change to the service will occur. A brief skimming of the code seems to indicate that the file-watcher uses a poll-based approach rather than relying on notifications from the operating system.

For example, the following test script will show that the PID does not change on almost every run (the script obviously needs to be modified to use a service that you can start:

#!/bin/bash

TEST_WAIT=5
for i in {1..100}; do
    PID_BEFORE=$(cat /hab/svc/authz-service/PID)
    hab sup unload chef/authz-service
    hab sup start chef/authz-service --channel dev --bind automate-postgresql:automate-postgresql.default
    sleep $TEST_WAIT

    PID_AFTER=$(cat /hab/svc/authz-service/PID)
    if [[ "$PID_AFTER" = "$PID_BEFORE" ]]; then
       echo "PID changed: NO ($PID_AFTER)"
    else
       echo "PID changed: YES ($PID_BEFORE -> $PID_AFTER)"
    fi
done

This might be unexpected for some users who have read the documentation which says:

https://www.habitat.sh/docs/habitat-cli/#hab-svc:

If the Supervisor is running when the service is unloaded the service will be stopped.

tashimi commented 6 years ago

Hi @stevendanna, I think what you're running into will be addressed by this: https://github.com/habitat-sh/habitat/pull/4805

reset commented 6 years ago

Not quite yet, #4805 is a predecessor for the change which will address this

stevendanna commented 6 years ago

Confirmed this is still an issue in 0.56.0, although in 0.56.0 unload is not the right command, rather you can reproduce this with stop followed by start.

reset commented 6 years ago

The scoping of #4805 was altered a bit so this will actually be resolved when https://github.com/habitat-sh/habitat/issues/1973 is closed

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stevendanna commented 4 years ago

I haven't tested this again but I'm fairly certain this is still an issue.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.