use better tailscaled.service

Signed-off-by: Xe <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-04-29 18:24:14 +00:00
parent 286641b916
commit dd50643eaf
2 changed files with 43 additions and 3 deletions

25
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"archive/tar" "archive/tar"
"compress/gzip" "compress/gzip"
_ "embed"
"flag" "flag"
"fmt" "fmt"
"io" "io"
@ -17,7 +18,10 @@ import (
var ( var (
out = flag.String("out", ".", "where to save squashfs images to") out = flag.String("out", ".", "where to save squashfs images to")
tsTarballPath = flag.String("tarball", "./var/tailscale_1.24.2_amd64.tgz", "path to tailscale tarball on disk") tsTarballPath = flag.String("tarball", "./var/tailscale_1.24.2_amd64.tgz", "path to tailscale tarball on disk")
distro = flag.String("distro", "arch", "distro to stamp into system extension") distro = flag.String("distro", "steamos", "distro to stamp into system extension")
//go:embed tailscaled.service
systemdService []byte
) )
func main() { func main() {
@ -64,8 +68,6 @@ func main() {
fname = filepath.Join(tmpDir, "usr", "bin", "tailscale") fname = filepath.Join(tmpDir, "usr", "bin", "tailscale")
case "tailscaled": case "tailscaled":
fname = filepath.Join(tmpDir, "usr", "sbin", "tailscaled") fname = filepath.Join(tmpDir, "usr", "sbin", "tailscaled")
case "tailscaled.service":
fname = filepath.Join(tmpDir, "usr", "lib", "systemd", "system", "tailscaled.service")
default: default:
continue continue
} }
@ -80,6 +82,8 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
fout.Chmod(0755)
err = fout.Close() err = fout.Close()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -99,6 +103,21 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
fout, err = os.Create(filepath.Join(tmpDir, "usr", "lib", "systemd", "system", "tailscaled.service"))
if err != nil {
log.Fatal(err)
}
_, err = fout.Write(systemdService)
if err != nil {
log.Fatal(err)
}
err = fout.Close()
if err != nil {
log.Fatal(err)
}
binPath, err := exec.LookPath("mksquashfs") binPath, err := exec.LookPath("mksquashfs")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

21
tailscaled.service Normal file
View File

@ -0,0 +1,21 @@
[Unit]
Description=Tailscale node agent
Documentation=https://tailscale.com/kb/
Wants=network-pre.target
After=network-pre.target NetworkManager.service systemd-resolved.service
[Service]
ExecStartPre=/usr/sbin/tailscaled --cleanup
ExecStart=/usr/sbin/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock --port 0
ExecStopPost=/usr/sbin/tailscaled --cleanup
Restart=on-failure
RuntimeDirectory=tailscale
RuntimeDirectoryMode=0755
StateDirectory=tailscale
StateDirectoryMode=0700
CacheDirectory=tailscale
CacheDirectoryMode=0750
Type=notify
[Install]
WantedBy=multi-user.target