symfony-cli / symfony-cli

The Symfony CLI tool
https://symfony.com/download
GNU Affero General Public License v3.0
521 stars 103 forks source link

Deamons no longer started #230

Open theofidry opened 1 year ago

theofidry commented 1 year ago

I am not entirely sure since which version this behaviour changed, but previously we would do something like:

bash start-app.sh

which just does something along the lines of:

stop_app {
    symfony local:server:stop
}

trap stop_crm SIGINT

symfony local:run --daemon bin/console messaging:consumer commands || true
symfony local:run --daemon bin/console messaging:consumer events || true
...
symfony local:server:start

The idea being we start the webserver on the foreground whilst starting the consumers in the background, and if we quit the main process in which the web-server started, it would stops the consumers too.

However as of 5.4.19 at the very least, the deamons will not be started before the local server is started. You will get the message Stream the logs via symfony server:log but no process will have been spawned.

If this is the expected behaviour I think an error message would be welcomed when starting the webserver, but at least from a user PoV I don't see how this would be the desired behaviour.

tucksaun commented 1 year ago

IIRC the --daemon flag will actually wait and only detach if the process starts successfully, the idea being that if the process fails immediately, the feedback will be provided to the user directly in the terminal. So my guess will be that because of the || true, your script just continue while the command failed to start.

theofidry commented 1 year ago

🤔 not sure if that's all there is to it. The || true was just in case it was not previously interrupted to not fail the whole thing (since we only cart that it's started, if it's already started it's good from our PoV).

I'll elaborate a bit more on the usage:

stop_app() {
    make stop
}

trap stop_app SIGINT

make _start
start: <a few pre-requisites to ensure e.g. docker is started and that the db is up to date>
    bash start-app.sh

_start: _start_deamons _start_webserver

_start_deamons:
    symfony local:run --daemon bin/console messaging:consumer commands || true
    symfony local:run --daemon bin/console messaging:consumer events || true

_start_webserver:
    symfony local:server:start

stop:
    local:server:stop

If I do:

$ make start
- checks the pre-requisites
- execute the bash script start-app.sh
  - register the trap
  - calls `make _start`
    - starts the deamons
    - starts the webserver

And then interrupting the process stops all servers.

This worked fine, but now at least, the deamons are no longer spawned. It's very noticeable because if I do:

$ mark start
# in another shell
$ make _start_deamons # <- actually spawns the deamons now!
# run again
$ make _start_deamons # <- if || true is removed, fails here because the command is already running