Contents

managing frp with systemd: a best-practice approach

Contents

frp is a fantastic tool for intranet penetration, but managing it effectively can be a challenge. systemd provides a robust and elegant solution for automating frp’s startup and ensuring its resilience. this post will guide you through creating a best-practice systemd unit file for frp, focusing on clarity, efficiency, and robustness.

here’s the optimized unit file:

[Unit]
Description=frp server
Requires=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/frpc -c /path/to/your/frpc.ini
Restart=on-failure

[Install]
WantedBy=multi-user.target

let’s break down the key components:

  • [Unit] section:

    • Description: a concise description of the service.
    • Requires=network-online.target: this ensures frp starts only after the network is fully online and can reach external hosts. this is a hard dependency, meaning frp won’t launch if network-online.target fails.
    • After=network-online.target: this ensures frp starts after network-online.target. while Requires implies After, explicitly stating it improves readability and clarity.
  • [Service] section:

    • ExecStart=/usr/bin/frpc -c /path/to/your/frpc.ini: this specifies the command to start frp. crucially, use the absolute path to the frpc executable. replace /path/to/your/ with the actual path to your frpc.ini configuration file.
    • Restart=on-failure: this automatically restarts frp if it crashes, ensuring continuous operation.
  • [Install] section:

    • WantedBy=multi-user.target: this ensures frp starts when the system enters multi-user mode (i.e., normal operation).

why these choices?

we use Requires instead of Wants for network-online.target to create a hard dependency. this prevents frp from starting prematurely if the network isn’t ready, avoiding potential errors and frustration. Restart=on-failure adds resilience, automatically restarting frp in case of crashes.

further considerations:

this example assumes you’re using a standard systemd setup. minor variations might be necessary depending on your specific distribution and frp configuration. always consult your distribution’s documentation for potential nuances.

i’m using Ubuntu-20.04 and frp version 0.33. what about you? share your experiences and any modifications you’ve made in the comments below!