Skip to content

Commit

Permalink
[NEW] management with systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Oct 14, 2023
1 parent 3678c2c commit 85964f7
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 59 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rust:1.50-alpine as builder

ENV WORKDIR /code
WORKDIR ${WORKDIR}

RUN rustup target add x86_64-unknown-linux-musl && \
apk add --no-cache musl-dev perl make gcc

ADD . .

RUN cargo build --release --target x86_64-unknown-linux-musl

FROM scratch as runner

COPY --from=builder /code/target/x86_64-unknown-linux-musl/release/rust-strom /usr/bin/rust-strom

CMD ["rust-strom"]
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,55 @@

```bash
curl -sSL https://raw.githubusercontent.com/ismoilovdevml/RustStrom/main/installer.sh | bash
chmod +x install.sh
./install.sh
```

### Get Permissions
### Creating a New User and Group for the Program

```bash
sudo groupadd rust-strom
sudo useradd -r -s /bin/false -g rust-strom rust-strom
sudo chmod 750 /etc/rust-strom/rust-strom
sudo chmod 640 /etc/rust-strom/rust-strom/*
sudo addgroup rust-strom
sudo adduser --system --no-create-home --ingroup rust-strom rust-strom
```

### Setting Permissions
```bash
sudo mv /path/to/your/executable /usr/local/bin/rust-strom
sudo mkdir -p /etc/rust-strom
sudo mv /path/to/your/config.toml /etc/rust-strom/config.toml

sudo chown rust-strom:rust-strom /usr/local/bin/rust-strom
sudo chown -R rust-strom:rust-strom /etc/rust-strom/
sudo chmod 755 /usr/local/bin/rust-strom
```
### Creating a systemd Service

```bash
sudo nano /etc/systemd/system/rust-strom.service
```

```bash
[Unit]
Description=Load Balancer RS
Description=Rust Strom Service
After=network.target

[Service]
ExecStart=/etc/rust-strom
WorkingDirectory=/opt/rust-strom
Restart=always
User=loadbalancer
Group=loadbalancer
Environment="PATH=/usr/bin:/bin" "LOAD_BALANCER_CONFIG=/etc/rust-strom/loadbalancer.toml"
AmbientCapabilities=CAP_NET_BIND_SERVICE
Type=simple
User=rust-strom
Group=rust-strom
ExecStart=/usr/local/bin/rust-strom --config /etc/rust-strom/config.toml
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

### Enable and start the service
```bash
sudo systemctl enable rust-strom
sudo systemctl start rust-strom


sudo systemctl daemon-reload
sudo systemctl restart rust-strom
sudo systemctl status rust-strom
Expand Down
20 changes: 20 additions & 0 deletions configs/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# config.toml
http_address = "[::]:80"
https_address = "[::]:443"

[[backend_pools]]
matcher = "Host('whoami.localhost')"
addresses = ["127.0.0.1:8080", "127.0.0.1:8081", "127.0.0.1:8082"]
schemes = ["HTTP", "HTTPS"]
strategy = { RoundRobin = {} }
[backend_pools.middlewares.HttpsRedirector]

[[backend_pools]]
matcher = "Host('youtube.de') && Path('/admin')"
addresses = ["192.168.0.168:15060"]
schemes = ["HTTPS"]
strategy = { RoundRobin = {} }
[backend_pools.middlewares.RateLimiter]
limit = 10
window_sec = 1
[backend_pools.middlewares.Compression]
17 changes: 0 additions & 17 deletions configs/loadbalancer.toml

This file was deleted.

39 changes: 39 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# Clone the git repo
git clone https://github.com/ismoilovdevml/RustStrom.git

# Move to the directory
cd rust-strom

# Build the program (assuming you have Rust and Cargo installed)
cargo build --release

# Move the executable and configuration
sudo mv target/release/rust-strom /usr/local/bin/
sudo mkdir -p /etc/rust-strom
sudo mv path/to/config.toml /etc/rust-strom/config.toml

# Set up user, group, and permissions
sudo addgroup rust-strom
sudo adduser --system --no-create-home --ingroup rust-strom rust-strom
sudo chown rust-strom:rust-strom /usr/local/bin/rust-strom
sudo chown -R rust-strom:rust-strom /etc/rust-strom/
sudo chmod 755 /usr/local/bin/rust-strom

# Create and start the systemd service
echo "[Unit]
Description=Rust Strom Service
After=network.target
[Service]
Type=simple
User=rust-strom
Group=rust-strom
ExecStart=/usr/local/bin/rust-strom --config /etc/rust-strom/config.toml
Restart=on-failure
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/rust-strom.service

sudo systemctl enable rust-strom
sudo systemctl start rust-strom
21 changes: 0 additions & 21 deletions installer.sh

This file was deleted.

14 changes: 6 additions & 8 deletions rust-strom.service
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
[Unit]
Description=Load Balancer RS
Description=Rust Strom Service
After=network.target

[Service]
ExecStart=/etc/rust-strom
WorkingDirectory=/opt/rust-strom
Restart=always
User=loadbalancer
Group=loadbalancer
Environment="PATH=/usr/bin:/bin" "LOAD_BALANCER_CONFIG=/etc/rust-strom/loadbalancer.toml"
AmbientCapabilities=CAP_NET_BIND_SERVICE
Type=simple
User=rust-strom
Group=rust-strom
ExecStart=/usr/local/bin/rust-strom --config /etc/rust-strom/config.toml
Restart=on-failure

[Install]
WantedBy=multi-user.target

0 comments on commit 85964f7

Please sign in to comment.