github.com/Axway/agent-sdk@v1.1.101/pkg/cmd/service/daemon/daemon.go (about) 1 package daemon 2 3 import "strings" 4 5 // Status constants. 6 const ( 7 statNotInstalled = "Service not installed" 8 ) 9 10 // Daemon interface has a standard set of methods/commands 11 type Daemon interface { 12 // GetTemplate - gets service config template 13 GetTemplate() string 14 15 // SetTemplate - sets service config template 16 SetTemplate(string) error 17 18 // Install the service into the system 19 Install(args ...string) (string, error) 20 21 // Update the service definition on the system 22 Update(args ...string) (string, error) 23 24 // Remove the service and all corresponding files from the system 25 Remove() (string, error) 26 27 // Start the service 28 Start() (string, error) 29 30 // Stop the service 31 Stop() (string, error) 32 33 // Status - check the service status 34 Status() (string, error) 35 36 // Enable - sets the service to persist reboots 37 Enable() (string, error) 38 39 // Logs - gets the service logs 40 Logs() (string, error) 41 42 // Run - run executable service 43 Run(e Executable) (string, error) 44 45 // SetEnvFile - sets the environment file argument for generating the agent command 46 SetEnvFile(string) error 47 48 // SetUser - sets the user that executes the service 49 SetUser(string) error 50 51 // setGroup - sets the group that executes the service 52 SetGroup(string) error 53 54 // GetServiceName - gets the name of the service 55 GetServiceName() string 56 } 57 58 // Executable interface defines controlling methods of executable service 59 type Executable interface { 60 // Start - non-blocking start service 61 Start() 62 // Stop - non-blocking stop service 63 Stop() 64 // Run - blocking run service 65 Run() 66 } 67 68 // New - Create a new daemon 69 // 70 // name: name of the service 71 // 72 // description: any explanation, what is the service, its purpose 73 func New(name, description string, dependencies ...string) (Daemon, error) { 74 return newDaemon(strings.Join(strings.Fields(name), "_"), description, dependencies) 75 }