@@ -12,6 +12,7 @@ import (
1212
1313type ServiceDefinition struct {
1414 serviceName string
15+ serviceType serviceType
1516 args []string
1617 description string
1718 docs []string
@@ -24,6 +25,14 @@ type ServiceDefinition struct {
2425 err error // if error reading selfAbsolutePath
2526}
2627
28+ // affects how service manager gauges the service start success (which if fails, can make service manager restart the service)
29+ type serviceType string
30+
31+ const (
32+ ServiceTypeExec serviceType = "exec" // will consider the unit started immediately after the main service binary has been executed
33+ ServiceTypeNotify serviceType = "notify" // it is expected that the service sends a "READY=1" notification message
34+ )
35+
2736type Option func (* ServiceDefinition )
2837
2938func Service (serviceName string , description string , opts ... Option ) ServiceDefinition {
@@ -40,6 +49,7 @@ func newService(serviceName string, description string, opts []Option, userServi
4049 selfAbsolutePath , err := currentExecutableNoFollowSymlink ()
4150
4251 sf := ServiceDefinition {
52+ serviceType : ServiceTypeExec ,
4353 userService : userService ,
4454 serviceName : serviceName ,
4555 description : description ,
@@ -153,6 +163,7 @@ func serialize(sf ServiceDefinition) string {
153163 l ("" )
154164 l ("[Service]" )
155165 l ("ExecStart=" + strings .Join (append ([]string {sf .selfAbsolutePath }, sf .args ... ), " " ))
166+ l ("Type=" + string (sf .serviceType ))
156167 l ("WorkingDirectory=" + filepath .Dir (sf .selfAbsolutePath ))
157168 l ("Restart=always" )
158169 l ("RestartSec=10s" )
@@ -181,6 +192,12 @@ func unitfilePath(sf ServiceDefinition) (string, error) {
181192 }
182193}
183194
195+ func Type (typ serviceType ) Option {
196+ return func (sf * ServiceDefinition ) {
197+ sf .serviceType = typ
198+ }
199+ }
200+
184201// FIXME(security): args are not shell escaped - DO NOT TAKE THIS FROM USER INPUT
185202func Args (args ... string ) Option {
186203 return func (sf * ServiceDefinition ) {
0 commit comments