Skip to content

Restore nchan_stub_status function#2109

Merged
limetech merged 2 commits into
unraid:masterfrom
bergware:master
Apr 2, 2025
Merged

Restore nchan_stub_status function#2109
limetech merged 2 commits into
unraid:masterfrom
bergware:master

Conversation

@bergware

@bergware bergware commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Introduced a new endpoint that provides real-time status information for the Nchan module, enhancing the server's monitoring capabilities.
    • Added a new method to cleanly terminate Nchan processes via a "kill" command.
  • Bug Fixes
    • Updated the stopping mechanism for Nchan publishers to improve reliability during forced stops.

@coderabbitai

coderabbitai Bot commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new location block for /nchan_stub_status is added within the build_locations function in the etc/rc.d/rc.nginx script. This update enables Nginx to process requests to the /nchan_stub_status endpoint and return status information about the Nchan module. Additionally, the method for stopping Nchan publishers has been modified to use a different command during forced stops.

Changes

File Change Summary
etc/rc.d/rc.nginx Added new location directive for /nchan_stub_status in build_locations; updated command in nginx_stop_forced from monitor_nchan stop remove to monitor_nchan kill
sbin/monitor_nchan Introduced logic to handle "kill" argument for stopping nchan processes; modified "stop" logic to not remove files unless explicitly handled

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant N as Nginx
    participant M as Nchan Module
    C->>N: Request `/nchan_stub_status`
    N->>M: Process Nchan status request
    M-->>N: Return status information
    N-->>C: Deliver response
Loading

Possibly related PRs

  • rc.nginx: include path to monitor_nchan #2107: The changes in the main PR modify the command used in the nginx_stop_forced function to stop Nchan publishers, while the retrieved PR updates the path for calling the monitor_nchan function in various locations, indicating a direct relationship in the context of stopping Nchan processes.
  • More refinements #2102: The changes in the main PR are related to the modifications in the nginx_stop_forced function, which now uses a different command for stopping Nchan publishers, while the retrieved PR introduces new functions for starting and stopping Nchan processes, indicating a direct connection in managing Nchan's lifecycle.

Poem

I'm a rabbit hopping with glee,
For a fresh new endpoint in our spree.
/nchan_stub_status added with care,
So status info is now always there.
With a twitch of my whiskers, I celebrate this code fare!
🐰🥕💻


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
etc/rc.d/rc.nginx (2)

396-398: Consider adding access restrictions for security

While the change itself is correct, the nchan_stub_status endpoint provides internal module information without any access controls. Consider adding IP restrictions or authentication to prevent unauthorized access to this monitoring endpoint.

 location /nchan_stub_status {
+    # Restrict access to local networks
+    allow 127.0.0.1;
+    allow 192.168.0.0/16;
+    allow 10.0.0.0/8;
+    allow 172.16.0.0/12;
+    deny all;
     nchan_stub_status;
 }

396-398: Consider adding a descriptive comment for consistency

For consistency with other location blocks in this file, consider adding a descriptive comment to explain the purpose of this endpoint.

+#
+# nchan status endpoint
+#
 location /nchan_stub_status {
     nchan_stub_status;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fb07a6 and 65db79a.

📒 Files selected for processing (1)
  • etc/rc.d/rc.nginx (1 hunks)
🔇 Additional comments (1)
etc/rc.d/rc.nginx (1)

396-398: LGTM: Successfully restored the nchan_stub_status function

The addition of this location block properly restores the nchan_stub_status functionality, making it accessible via HTTP/HTTPS interfaces. This complements the existing endpoint available through the unix socket at lines 154-156.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
sbin/monitor_nchan (3)

29-34: Consider adding a comment to document the purpose of the "kill" command.

Adding a brief comment explaining that this command is intended for forced stops and complete cleanup would improve maintainability.

+# Kill command: completely terminate nchan processes and remove related files (used for forced stops)
 if [[ $1 == kill ]]; then
   echo "Stopping nchan processes..."
   nchan_stop
   rm -f $nchan_pid $disk_load
   exit
 fi

10-17: Consider adding error handling to the cleanup operations.

The nchan_stop function and file removal operations don't include error checking. It might be helpful to add basic error handling to ensure that processes are properly terminated and files are successfully removed.

 nchan_stop() {
   echo -n >$nchan_list
+  local kill_status=0
   while IFS=$'\n' read -r nchan; do
     [[ ${nchan##*/} == '.*' ]] && continue
     echo $nchan >>$nchan_list
     pkill -f $nchan
+    [[ $? -ne 0 ]] && kill_status=1
   done <<< $(ps -eo cmd | grep -Po '/usr/local/emhttp/.*/nchan/.*')
+  return $kill_status
 }

 if [[ $1 == kill ]]; then
   echo "Stopping nchan processes..."
   nchan_stop
+  [[ $? -ne 0 ]] && echo "Warning: Some nchan processes may not have been terminated properly"
   rm -f $nchan_pid $disk_load
+  [[ $? -ne 0 ]] && echo "Warning: Failed to remove some nchan files"
   exit
 fi

Also applies to: 29-34


36-40: Consider refactoring to reduce code duplication between "kill" and "stop" commands.

The "kill" and "stop" commands share similar logic, with the main difference being the file removal. Consider refactoring to reduce duplication while maintaining the distinct behaviors.

 nchan_stop() {
   echo -n >$nchan_list
   while IFS=$'\n' read -r nchan; do
     [[ ${nchan##*/} == '.*' ]] && continue
     echo $nchan >>$nchan_list
     pkill -f $nchan
   done <<< $(ps -eo cmd | grep -Po '/usr/local/emhttp/.*/nchan/.*')
 }
 
+# Handle stop operations with optional cleanup
+handle_stop() {
+  echo "Stopping nchan processes..."
+  nchan_stop
+  [[ $1 == "cleanup" ]] && rm -f $nchan_pid $disk_load
+  exit
+}
 
 if [[ $1 == kill ]]; then
-  echo "Stopping nchan processes..."
-  nchan_stop
-  rm -f $nchan_pid $disk_load
-  exit
+  handle_stop cleanup
 fi
 
 if [[ $1 == stop ]]; then
-  echo "Stopping nchan processes..."
-  nchan_stop
-  exit
+  handle_stop
 fi

Also applies to: 29-34

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 65db79a and 8a5acf2.

📒 Files selected for processing (2)
  • etc/rc.d/rc.nginx (2 hunks)
  • sbin/monitor_nchan (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • etc/rc.d/rc.nginx
🔇 Additional comments (1)
sbin/monitor_nchan (1)

29-34: The new "kill" command handler looks good, but has subtle differences from the existing "stop" command.

The new feature provides a clean way to stop Nchan processes and remove related files in one operation. This aligns with the PR objective of restoring the nchan_stub_status function by providing a more complete termination option.

Note that this differs from the existing "stop" command (lines 36-40) which only stops processes but doesn't remove files. According to the AI summary, this is replacing the previous pattern of using "monitor_nchan stop remove" with "monitor_nchan kill" in the nginx_stop_forced function.

@limetech limetech merged commit eddaeb2 into unraid:master Apr 2, 2025
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