Skip to content

Create daemons on initial site provisioning #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025

Conversation

prashank25
Copy link
Contributor

@prashank25 prashank25 commented Feb 17, 2025

This PR allows creating daemons on forge when provisioning a new site.

You can create a single or multiple daemons the same way as queue workers. The user and directory is set to the same ones used on the site, a reasonable default I think.

env:
  FORGE_DAEMONS: php artisan horizon

or

env:
  FORGE_DAEMONS: |
    php artisan horizon
    php artisan pulse:check
    custom.sh --directory=/path/to/script --user=forge --processes=1 --startsecs=10 --stopwaitsecs=60 --stopsignal=SIGTERM

If the command you need to run has arguments of its own, you can single or double-quote the entire command.

env:
  FORGE_DAEMONS: "something-to-run --argument=value" --directory=/path/to/script --user=forge

Handling of teardown process.

When in user isolation mode, daemon removal happens by deleting all daemons that are running as the user used for the site.

In all cases, daemons are deleted if their directory falls within the site currently being teardown-ed.

After all that, any remaining daemons are deleted based on the env variable set by the user. So it is recommended to add the same env value for FORGE_DAEMONS for teardown workflow as well. Would ask you to review the code for teardown carefully. Thanks.


And finally some concerns

The inertia pipeline steps seem redundant for the most part and can simply be replaced with php artisan inertia:start-ssr in the FORGE_DAEMONS. Additionally, it adds inertia:stop-ssr to the deployment script, which seems out of scope to do automatically. The user still needs to write their deployment script anyway, and they should add the daemon-killing command to their script, as suggested by the documentation for those libraries.

That being said, I have not made any changes to inertia as that would be a breaking change.

I will be submitting another PR to fix the handling of user isolation in the scheduler job and inertia daemon creation. Since at the moment it's hard coded to forge.

Apologies for the wall of text 😞

Copy link
Owner

@mehrancodes mehrancodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prashank25, everything looks great - just one small issue when tearing down the site.

…rectory set

Signed-off-by: Prashank Abhishek <prashank@codesm.com>
Copy link
Owner

@mehrancodes mehrancodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here, @prashank25! Thank you!

@mehrancodes mehrancodes merged commit 40560cd into mehrancodes:main Feb 28, 2025
1 check passed
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.

2 participants