Skip to content
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

Allow server process to start without detaching #11319

Merged
merged 1 commit into from Feb 2, 2023

Conversation

f1sherman
Copy link
Contributor

@f1sherman f1sherman commented Dec 22, 2022

Add a --no-detach option to --start-server and --restart-server. This makes it easy to run the RuboCop server process from within Docker, where detaching the process causes the container to exit.

Fixes #11188


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 31, 2022

@f1sherman I see that a bunch of CI jobs are currently failing.

@f1sherman f1sherman changed the title [Fix #11188] Allow server process to start without daemonizing Dec 31, 2022
@f1sherman
Copy link
Contributor Author

@bbatsov sorry about that! CI is fixed now. I was a little confused about the below offense since I didn't change that file, so I fixed that one in a separate commit.

lib/rubocop/cop/style/redundant_string_escape.rb:61:42: C: [Corrected] Performance/RedundantStringChars: Use [-1] instead of chars.last.
          format(MSG, char: range.source.chars.last)
                                         ^^^^^^^^^^

@koic
Copy link
Member

koic commented Dec 31, 2022

@bbatsov sorry about that! CI is fixed now. I was a little confused about the below offense since I didn't change that file, so I fixed that one in a separate commit.

No need for that the separated commit because this offense has already been resolved on the master branch:
63e8377

Can you rebase with the latest master branch?

@koic
Copy link
Member

koic commented Dec 31, 2022

I wonder whether the term "daemon" is appropriate as I remember the conversation below:
#10706 (comment)

@f1sherman
Copy link
Contributor Author

Can you rebase with the latest master branch?

Done!

@f1sherman
Copy link
Contributor Author

I wonder whether the term "daemon" is appropriate

I'm fully open to suggestions! Would --no-background be preferable?

@mculp
Copy link

mculp commented Jan 3, 2023

The code uses demonize -- at least you spelled it correctly 😂

@mculp
Copy link

mculp commented Jan 3, 2023

Thank you @f1sherman. Another use case for this: DarthSim/overmind#143

].freeze
EXCLUSIVE_OPTIONS = (SERVER_OPTIONS - %w[--server --no-server]).freeze
NO_DAEMONIZE_OPTIONS = %w[--server --start-server].freeze
Copy link

Choose a reason for hiding this comment

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

What do you think about --restart-server here? Example, if you had started it daemonized and wanted to restart it in foreground?

Also, should we consider what the output should be if it's not daemonized?

Should it be --debug output?
Should it show simple messages like "processing 5510 files" every time Rubocop is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've made an update to allow --no-daemonize to be used with --restart-server.

I don't have a very strong opinion about the process output. That said, with the new year starting I have less time to polish this PR up so I could certainly use an assist or strong point in the right direction on how to make the changes you're looking for if you'd be so kind. Thank you!

Copy link

Choose a reason for hiding this comment

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

I don't have strong opinions either, would rather just get this merged and then we can do a follow-up for the output

@mculp
Copy link

mculp commented Jan 11, 2023

@bbatsov @koic Looks like CI is passing now.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 1, 2023

I'm fully open to suggestions! Would --no-background be preferable?

I think the most common name for such an option is usually "--nodetach" or "-no-detach".

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 1, 2023

(it seems that even Docker favours this terminology)

@@ -57,6 +57,12 @@ RuboCop version incompatibility found, RuboCop server restarting...
RuboCop server starting on 127.0.0.1:60665.
```

If you would like to start the server without daemonizing the process, which can be useful when running within Docker, you can pass the `--no-daemonize` option.
Copy link
Collaborator

Choose a reason for hiding this comment

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

without daemonizing -> in the foreground

@@ -92,6 +98,9 @@ These are the command-line options for server operations:

| `--server-status`
| Show server status.

| `--no-daemonize`
| Do not daemonize the server process.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength:
def run_command(server_command)
def run_command(server_command, daemonize:)
Copy link
Collaborator

Choose a reason for hiding this comment

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

daemonize -> detach

Add a `--no-detach` option to `--start-server`. This makes it easy to
run the RuboCop server process from within Docker, where detaching the
process causes the container to exit.
@f1sherman f1sherman changed the title Allow server process to start without daemonizing Allow server process to start without detaching Feb 1, 2023
@f1sherman
Copy link
Contributor Author

@bbatsov thanks for the feedback, we should be all set once CI finishes 🤞

@bbatsov bbatsov merged commit 5230ef2 into rubocop:master Feb 2, 2023
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.

Start server without exiting (e.g. for Docker)
4 participants