1 Star 1 Fork 0

liuyi / GoSmoothServe

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

GoSmoothServe

Introduction

GoSmoothServe is a reverse proxy service designed to seamlessly hot-reload web services on a single server, enabling smooth restarts and shutdowns without losing requests.

  • It facilitates updating services without restarts, maintaining continuity of existing connections to ensure users enjoy stable and uninterrupted service seamlessly.

  • With GoSmoothServe, managing and scaling your web services becomes effortless, offering efficient load balancing and a seamless updating experience.

  • If there are no specific requirements, GoSmoothServe can directly replace nginx as a web proxy service.

    However, if firewall requirements exist, it is recommended to use nginx in front and then pass requests to GoSmoothServe. GoSmoothServe focuses solely on seamless hot-reloading and smooth stopping and restarting.

Usage

Start the GoSmoothServe reverse proxy service

Starting the reverse proxy service will read all configurations under ./service and start all services.

./smoothtool -start all
Stop the GoSmoothServe reverse proxy service

This will stop all services, but it will wait until all connections are completed before completely interrupting the service.

./smoothtool -stop all

Start a web service

./smoothtool -start example_service_name
Stop a running web service

This will stop the service named example_service_name specified in the configuration file, no longer accepting new requests. However, it will wait until all connections are completed before completely interrupting the service.

./smoothtool -stop example_service_name
Restart a running web service

This will restart the service named example_service_name specified in the configuration file, allowing new requests. It will restart multiple instances of the service one by one. Incoming requests will be distributed to the working instances, ensuring no request loss or interruption. Instances processing requests will not be assigned new requests. The service will be restarted once all requests are processed.

./smoothtool -restart example_service_name

Run as a system service

Running the following code under the bin directory will automatically install smoothserve as a system service, starting with the system.

sudo bash install_smoothserve.sh

Folder Structure

Structure List:

  • bin
    • smoothtool
    • smoothserve
    • smoothserve.yaml
    • services
      • example.com.yaml
      • example2.com.yaml

File Descriptions:

  • bin: Root directory of executable files, can be placed anywhere.
  • smoothserve: Runs in the background, accepts HTTP requests from users or passed through nginx proxy, and reverse proxies to various proxied service instances.
  • smoothtool: Command-line tool to control the reverse proxy service.
  • smoothserve.yaml: Configuration file for reverse proxy (similar to nginx.conf).
  • services: Contains configuration files for proxied services (similar to nginx vhost).

Configuration Files

smoothserve.yaml

CommandPort: 8080 # Port for smooth_tool_linux to send commands to the reverse proxy service
ProxyAddr: "127.0.0.1" # IP address of the reverse proxy service
SubConfigDir: ./services

services/service_config.yaml

name: service_name
server_name: "service_domain, service2_domain"
server_ip:  127.0.0.1 # IP address of the instance
port: 8085 # Port for reverse proxy requests
start_instance_port: 8086 # Starting port for multiple instances of this service. If there are 3 instances, they would be 8086, 8087, 8088.
instance_count: 3 # Number of instances of this service to start on this server
executable_path: your/web/service/bin/file # Entry file of the service
auto_restart: true # Whether to listen for file changes. If true, the service will automatically hot-reload when changes occur in this configuration file or in the files or directories listed in watch_files.
delay_running_time: 3 # Delay in seconds before restarting each instance of the service. It's recommended to set this based on how long it takes for your service to become operational after startup.
watch_files: # List of files and directories to monitor for automatic restarts.
  - ./your/view/folder
  - ./your/web/files
  - ./files/in/your/web/service/folder

Considerations for the Web Service being Proxied

  • To enable multiple instances to run simultaneously, it's necessary to read the command-line argument port during startup and dynamically set the port number for HTTP requests. This can be achieved using the flag standard library:
      var servicePort int = 0
      flag.IntVar(&servicePort, "port", 8081, "Port to start the service")
MIT License Copyright (c) 2024 liuyi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

GoSmoothServe 是一个用于在单台服务器上平滑启动多个 Web 服务实例的工具。它可以实现在更新服务时无需重启,同时保持现有连接的连续性,从而确保用户无感知地享受到服务的稳定和持续性。通过 GoSmoothServe,您可以轻松管理和扩展您的 Web 服务,提供高效的负载均衡和无缝的更新体验。 expand collapse
Go and 2 more languages
MIT
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ourbrander/go-smooth-serve.git
git@gitee.com:ourbrander/go-smooth-serve.git
ourbrander
go-smooth-serve
GoSmoothServe
master

Search

344bd9b3 5694891 D2dac590 5694891