Skip to content
/ service Public

service will install / un-install and run a program as a service (daemon).

License

Notifications You must be signed in to change notification settings

axgle/service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create system services in Go.

golang service package will install / un-install and run a program as a service (daemon). Currently supports Windows XP+ and Linux/Upstart.

To start out follow "example/main.go".

package main

import (
	"github.com/axgle/service"
	"fmt"
	"os"
)

func main() {
	var displayName = "Go Service Test"
	var desc = "This is a test Go service.  It is designed to run well."
	var ws, err = service.NewService("GoServiceTest2", displayName, desc)

	if(err != nil) {
		fmt.Printf("%s unable to start: %s", displayName, err)
		return
	}

	if len(os.Args) > 1 {
		var err error
		verb := os.Args[1]
		switch verb {
		case "install":
			err = ws.Install()
			if err != nil {
				fmt.Printf("Failed to install: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" installed.\n", displayName)
		case "remove":
			err = ws.Remove()
			if err != nil {
				fmt.Printf("Failed to remove: %s\n", err)
				return
			}
			fmt.Printf("Service \"%s\" removed.\n", displayName)
		}
		return
	}
	err = ws.Run(func() error {
		// start
		go doWork()
		ws.LogInfo("I'm Running!")
		return nil
	}, func() error {
		// stop
		stopWork()
		ws.LogInfo("I'm Stopping!")
		return nil
	})
	if err != nil {
		ws.LogError(err.Error())
	}
}

func doWork() {

}
func stopWork() {

}

From https://bitbucket.org/kardianos/service

About

service will install / un-install and run a program as a service (daemon).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages