#!/bin/bash

SERVICE_FILE="/etc/systemd/system/frpc.service"

echo "Creating systemd service file for frpc..."
sudo bash -c "cat > $SERVICE_FILE" <<EOF
[Unit]
Description=frpc service
After=network.target

[Service]
Type=simple
WorkingDirectory=/root/frp
ExecStart=/root/frp/frpc -c /root/frp/frpc.toml
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
EOF

echo "Reloading systemd daemon..."
sudo systemctl daemon-reload

echo "Starting frpc service..."
sudo systemctl restart frpc.service

echo "Enabling frpc service to start on boot..."
sudo systemctl enable frpc.service

echo "Checking frpc service status..."
sudo systemctl status frpc.service