Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add socket path option #10

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ and update tailscale route advertisements accordingly.
## Commandline options

```
Usage: tailscale-manager <configfile.json> [--dryrun] [--tailscale PATH]
[--interval INT] [--max-shrink-ratio RATIO]
Usage: tailscale-manager <configfile.json> [--dryrun] [--tailscale PATH]
[--socket SOCKET_PATH] [--interval INT]
[--max-shrink-ratio RATIO]

Tailscale routes manager

Expand Down Expand Up @@ -96,6 +97,8 @@ Available options:
--dryrun Dryrun mode
--tailscale PATH Path to the tailscale executable
(default: "tailscale")
--socket SOCKET_PATH Path to the tailscaled socket
(default: "/var/run/tailscale/tailscaled.sock")
--interval INT Interval (in seconds) between runs. 0 means exit
after running once. (default: 0)
--max-shrink-ratio RATIO Max allowed route shrinkage between consecutive runs,
Expand Down
8 changes: 7 additions & 1 deletion src/TailscaleManager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data TailscaleManagerOptions
{ configFile :: FilePath
, dryRun :: Bool
, tailscaleCmd :: FilePath
, socketPath :: FilePath
, interval :: Seconds
, maxShrinkRatio :: Double
}
Expand Down Expand Up @@ -68,6 +69,11 @@ tsManagerOptions =
<> help "Path to the tailscale executable"
<> value "tailscale"
<> showDefault)
<*> strOption (long "socket"
<> metavar "SOCKET_PATH"
<> help "Path to the tailscaled socket"
<> value "/var/run/tailscale/tailscaled.sock"
<> showDefault)
<*> option auto (long "interval"
<> metavar "INT"
<> help "Interval (in seconds) between runs. 0 means exit after running once."
Expand Down Expand Up @@ -128,7 +134,7 @@ runOnce options prevRoutes = do
let shrinkage = shrinkRatio prevRoutes newRoutes
if shrinkage < maxShrinkRatio options
then do
invokeTailscale $ ["set", "--advertise-routes=" ++ intercalate "," (map show $ S.toList newRoutes)] ++ tsExtraArgs config
invokeTailscale $ ["--socket=" ++ socketPath options, "set", "--advertise-routes=" ++ intercalate "," (map show $ S.toList newRoutes)] ++ tsExtraArgs config
logDelay
return newRoutes
else do
Expand Down
Loading