// Copyright (c) 2026 Petr BalvĂ­n (https://petrbalvin.org) // SPDX-License-Identifier: MIT package main import ( "errors" "log" "net" "os" ) // notifyReady announces readiness to the service manager over // $NOTIFY_SOCKET, the raw unix datagram socket of the sd_notify // protocol. The message is the one READY=1 line; nothing else is sent // and no dependency is pulled in. Without the variable, the process is // not running under a Type=notify unit and the step is skipped quietly. func notifyReady() error { addr := os.Getenv("NOTIFY_SOCKET") if addr == "" { return nil } conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: addr, Net: "unixgram"}) if err != nil { return err } defer conn.Close() if _, err := conn.Write([]byte("READY=1")); err != nil { return err } return nil } // notifyReadyOrLog announces readiness and reports a failure on the log // without ending the service: a manager that expects the notification // times the unit out, but the server itself is ready to serve either way. func notifyReadyOrLog() { if err := notifyReady(); err != nil && !errors.Is(err, os.ErrNotExist) { log.Printf("nfsd: the readiness notification failed: %v", err) } }