1package service 2 3import ( 4 "errors" 5 "path" 6 "reflect" 7) 8 9type Service interface { 10 Install() error 11 Uninstall() error 12 13 Status() (Status, error) 14 Start() error 15 Stop() error 16 Restart() error 17 18 ConfigStorer 19} 20 21type Config struct { 22 Name string 23 DisplayName string 24 Description string 25 Arguments []string 26} 27 28type Status int 29 30const ( 31 StatusUnknown Status = iota 32 StatusNotInstalled 33 StatusRunning 34 StatusStopped 35) 36 37var ( 38 ErrNotSuported = errors.New("system not supported") 39 ErrAlreadyInstalled = errors.New("already installed") 40 ErrNoInstalled = errors.New("not installed") 41) 42 43type RunMode int 44 45const RunModeEnv = "SERVICE_RUN_MODE" 46 47const ( 48 // RunModeNone means the current process is not run as a service. 49 RunModeNone RunMode = iota 50 51 // RunModeService specifies that the process is running as a service. 52 RunModeService 53) 54 55// Name returns the name of s. 56func Name(s Service) string { 57 return path.Base(reflect.TypeOf(s).PkgPath()) 58} 59