service

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 6 Imported by: 0

README

go-windows-service

A library that wraps Windows SCM operations into one nice call.

Windows

The wrapper assumes a typical CLI for Windows services.

Usage: example.exe </i>|</u>|</d>
        /i - install service.
        /u - uninstall service.
        /d - debug with console.

Install and uninstall operations should runs as admin.

Linux and other

The wrapper tries not to interfere with the work and immediately transfers control to the nested function. All that the wrapper does is:

  • sets a panic handler before calling the nested function
  • sets signal handlers for graceful shutdown the application

See entry_other.go file.

Examples
package main

import (
	"context"
	"log"

	service "github.com/sergereinov/go-windows-service"
)

var (
	// You can set the Version at compile stage of your dev pipeline with:
	// go build -ldflags="-X main.Version=1.0.0" ./example
	Version     = "1.0.0"
	Name        = service.ExecutableFilename()
	Description = "My service"
)

func main() {
	// Init your favorite logger
	logger := log.Default()

	// Run service wrapper
	service.Service{
		Version:     Version,
		Name:        Name,
		Description: Description,
		Logger:      logger,
	}.Proceed(func(ctx context.Context) {

		logger.Printf("Service %s v%s started", Name, Version)

		//Do what the service should do

		<-ctx.Done()

		logger.Printf("Service %s v%s stopped", Name, Version)
	})
}

Examples in projects that use this library:

Similar Projects

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdditionalArgs added in v1.0.2

func AdditionalArgs() []string

func ExecutableFilename

func ExecutableFilename() string

func IsDebugMode added in v1.0.2

func IsDebugMode() bool

Types

type Logger

type Logger interface {
	Printf(string, ...interface{})
	Fatalf(string, ...interface{})
}

type Service

type Service struct {
	Version     string
	Name        string
	Description string
	Logger      Logger
}

func (Service) Proceed

func (s Service) Proceed(payload func(context.Context))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL