Skip to content

Commit

Permalink
Merge pull request #57 from AssetsArt/main
Browse files Browse the repository at this point in the history
Refactor EasyProxy::new() to use app_conf.pingora for grace period an…
  • Loading branch information
Aitthi authored Sep 30, 2024
2 parents be574f7 + 3cd4eea commit 9b815f2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "easy-proxy"
version = "0.1.2"
version = "0.1.3"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Easy Proxy**, a simple proxy server designed to provide essential features for network traffic management and proxying.
based on [pingora](https://github.com/cloudflare/pingora)

## Installation
## Installation or Upgrade
```bash
curl -fsSL https://raw.githubusercontent.com/AssetsArt/easy-proxy/main/scripts/install.sh | bash
```
Expand Down
38 changes: 30 additions & 8 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ if [ -z "$LATEST_TAG" ]; then
exit 1
fi

# OS gnu or musl
OS_TYPE=$(ldd --version | grep -q musl && echo "musl" || echo "gnu")
# Detect OS type (gnu or musl)
if ldd --version 2>&1 | grep -q musl; then
OS_TYPE="musl"
else
OS_TYPE="gnu"
fi

# Construct download URLs
BINARY_NAME="$BINARY-$ARCH-$OS-$OS_TYPE"
Expand Down Expand Up @@ -73,16 +77,29 @@ rm linux-checksums.txt
# Make the binary executable
chmod +x "$BINARY_NAME"

# Move the binary to the install directory
echo "Installing $BINARY_NAME to $INSTALL_DIR..."
sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY"
# Check if binary already exists
if [ -f "$INSTALL_DIR/$BINARY" ]; then
echo "Existing installation detected. Updating $BINARY..."
sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY"
# Restart the service if it's running
if systemctl is-active --quiet easy-proxy; then
echo "Restarting easy-proxy service..."
sudo systemctl restart easy-proxy
else
echo "easy-proxy service is not running."
fi
else
echo "Installing $BINARY_NAME to $INSTALL_DIR..."
sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY"
fi

# Create configuration directory
CONFIG_DIR="/etc/easy-proxy"
if [ ! -d "$CONFIG_DIR" ]; then
echo "Creating configuration directory at $CONFIG_DIR..."
sudo mkdir -p "$CONFIG_DIR"
fi

CONFIG_DIR_PROXY="$CONFIG_DIR/proxy"
if [ ! -d "$CONFIG_DIR_PROXY" ]; then
echo "Creating configuration directory at $CONFIG_DIR_PROXY..."
Expand All @@ -99,9 +116,7 @@ proxy:
https: "0.0.0.0:443"
config_dir: "/etc/easy-proxy/proxy"
pingora:
# https://github.com/cloudflare/pingora/blob/main/docs/user_guide/daemon.md
daemon: true
# https://github.com/cloudflare/pingora/blob/main/docs/user_guide/conf.md
threads: $(nproc)
# upstream_keepalive_pool_size: 20
# work_stealing: true
Expand All @@ -110,6 +125,8 @@ pingora:
# upgrade_sock: /tmp/pingora_upgrade.sock
# user: nobody
# group: webusers
# grace_period_seconds: 1
# graceful_shutdown_timeout_seconds: 1
# ca_file: /etc/ssl/certs/ca-certificates.crt
EOL
else
Expand Down Expand Up @@ -143,10 +160,15 @@ EOL
sudo systemctl start easy-proxy
else
echo "Service file already exists at $SERVICE_FILE. Skipping creation."
# Reload systemd daemon in case the service file was updated
sudo systemctl daemon-reload
# Restart the service
echo "Restarting easy-proxy service..."
sudo systemctl restart easy-proxy
fi

# Verify service status
echo "Checking easy-proxy service status..."
sudo systemctl status easy-proxy
echo "Service status: $(systemctl is-active easy-proxy)"

echo "Installation and setup completed successfully!"
10 changes: 7 additions & 3 deletions src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ impl EasyProxy {
if let Some(upstream_keepalive_pool_size) = app_conf.pingora.upstream_keepalive_pool_size {
conf.upstream_keepalive_pool_size = upstream_keepalive_pool_size;
}
conf.grace_period_seconds = conf.grace_period_seconds.or(Some(1));
conf.graceful_shutdown_timeout_seconds = conf.graceful_shutdown_timeout_seconds.or(Some(1));
conf.grace_period_seconds = app_conf.pingora.grace_period_seconds.or(Some(1));
conf.graceful_shutdown_timeout_seconds = app_conf
.pingora
.graceful_shutdown_timeout_seconds
.or(Some(1));
// println!("{:#?}", conf);
pingora_server.configuration = conf.into();
pingora_server.bootstrap();
let mut pingora_svc =
proxy::http_proxy_service(&pingora_server.configuration, easy_proxy.clone());
pingora_svc.add_tcp(&app_conf.proxy.http);
Expand All @@ -102,6 +105,7 @@ impl EasyProxy {
// prometheus_service_http.add_tcp("127.0.0.1:6192");
// pingora_server.add_service(prometheus_service_http);

pingora_server.bootstrap();
Ok(pingora_server)
}
}
Expand Down

0 comments on commit 9b815f2

Please sign in to comment.