Ground-Zerro / Phobos Public
Code Issues Pull requests Actions Releases View on GitHub ↗
841 B go
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2019-2026 WireGuard LLC. All Rights Reserved.
 */

package services

import (
	"log"
	"sync"

	"golang.org/x/sys/windows/svc"
	"golang.zx2c4.com/wireguard/windows/version"
)

var (
	startedAtBoot     bool
	startedAtBootOnce sync.Once
)

func StartedAtBoot() bool {
	startedAtBootOnce.Do(func() {
		if isService, err := svc.IsWindowsService(); err == nil && !isService {
			return
		}
		if reason, err := svc.DynamicStartReason(); err == nil {
			startedAtBoot = (reason&svc.StartReasonAuto) != 0 || (reason&svc.StartReasonDelayedAuto) != 0
		} else {
			log.Printf("Unable to determine service start reason: %v", err)
		}
	})
	return startedAtBoot
}

func PrintStarting() {
	boot := ""
	if StartedAtBoot() {
		boot = " at boot"
	}
	log.Printf("Starting%s %s", boot, version.UserAgent())
}