Skip to content

Commit 4ac50d8

Browse files
committed
service: go fmt comments
1 parent 9832e01 commit 4ac50d8

File tree

7 files changed

+89
-54
lines changed

7 files changed

+89
-54
lines changed

example/logging/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
var logger service.Logger
1717

1818
// Program structures.
19-
// Define Start and Stop methods.
19+
//
20+
// Define Start and Stop methods.
2021
type program struct {
2122
exit chan struct{}
2223
}
@@ -54,11 +55,12 @@ func (p *program) Stop(s service.Service) error {
5455
}
5556

5657
// Service setup.
57-
// Define service config.
58-
// Create the service.
59-
// Setup the logger.
60-
// Handle service controls (optional).
61-
// Run the service.
58+
//
59+
// Define service config.
60+
// Create the service.
61+
// Setup the logger.
62+
// Handle service controls (optional).
63+
// Run the service.
6264
func main() {
6365
svcFlag := flag.String("service", "", "Control the system service.")
6466
flag.Parse()

service.go

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -167,42 +167,70 @@ func New(i Interface, c *Config) (Service, error) {
167167
}
168168

169169
// KeyValue provides a list of system specific options.
170-
// * OS X
171-
// - LaunchdConfig string () - Use custom launchd config.
172-
// - KeepAlive bool (true) - Prevent the system from stopping the service automatically.
173-
// - RunAtLoad bool (false) - Run the service after its job has been loaded.
174-
// - SessionCreate bool (false) - Create a full user session.
175-
//
176-
// * Solaris
177-
// - Prefix string ("application") - Service FMRI prefix.
178-
//
179-
// * POSIX
180-
// - UserService bool (false) - Install as a current user service.
181-
// - SystemdScript string () - Use custom systemd script.
182-
// - UpstartScript string () - Use custom upstart script.
183-
// - SysvScript string () - Use custom sysv script.
184-
// - OpenRCScript string () - Use custom OpenRC script.
185-
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
186-
// - ReloadSignal string () [USR1, ...] - Signal to send on reload.
187-
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
188-
// - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files.
189-
// - Restart string (always) - How shall service be restarted.
190-
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
191-
// in addition to the default ones.
192-
// - LogDirectory string(/var/log) - The path to the log files directory
193-
//
194-
// * Linux (systemd)
195-
// - LimitNOFILE int (-1) - Maximum open files (ulimit -n)
196-
// (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7)
197-
// * Windows
198-
// - DelayedAutoStart bool (false) - After booting, start this service after some delay.
199-
// - Password string () - Password to use when interfacing with the system service manager.
200-
// - Interactive bool (false) - The service can interact with the desktop. (more information https://docs.microsoft.com/en-us/windows/win32/services/interactive-services)
201-
// - DelayedAutoStart bool (false) - after booting start this service after some delay.
202-
// - StartType string ("automatic") - Start service type. (automatic | manual | disabled)
203-
// - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction)
204-
// - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string.
205-
// - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds.
170+
//
171+
// - OS X
172+
//
173+
// - LaunchdConfig string () - Use custom launchd config.
174+
//
175+
// - KeepAlive bool (true) - Prevent the system from stopping the service automatically.
176+
//
177+
// - RunAtLoad bool (false) - Run the service after its job has been loaded.
178+
//
179+
// - SessionCreate bool (false) - Create a full user session.
180+
//
181+
// - Solaris
182+
//
183+
// - Prefix string ("application") - Service FMRI prefix.
184+
//
185+
// - POSIX
186+
//
187+
// - UserService bool (false) - Install as a current user service.
188+
//
189+
// - SystemdScript string () - Use custom systemd script.
190+
//
191+
// - UpstartScript string () - Use custom upstart script.
192+
//
193+
// - SysvScript string () - Use custom sysv script.
194+
//
195+
// - OpenRCScript string () - Use custom OpenRC script.
196+
//
197+
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
198+
//
199+
// - ReloadSignal string () [USR1, ...] - Signal to send on reload.
200+
//
201+
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
202+
//
203+
// - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files.
204+
//
205+
// - Restart string (always) - How shall service be restarted.
206+
//
207+
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
208+
// in addition to the default ones.
209+
//
210+
// - LogDirectory string(/var/log) - The path to the log files directory
211+
//
212+
// - Linux (systemd)
213+
//
214+
// - LimitNOFILE int (-1) - Maximum open files (ulimit -n)
215+
// (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7)
216+
//
217+
// - Windows
218+
//
219+
// - DelayedAutoStart bool (false) - After booting, start this service after some delay.
220+
//
221+
// - Password string () - Password to use when interfacing with the system service manager.
222+
//
223+
// - Interactive bool (false) - The service can interact with the desktop. (more information https://docs.microsoft.com/en-us/windows/win32/services/interactive-services)
224+
//
225+
// - DelayedAutoStart bool (false) - after booting start this service after some delay.
226+
//
227+
// - StartType string ("automatic") - Start service type. (automatic | manual | disabled)
228+
//
229+
// - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction)
230+
//
231+
// - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string.
232+
//
233+
// - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds.
206234
type KeyValue map[string]interface{}
207235

208236
// bool returns the value of the given name, assuming the value is a boolean.
@@ -325,16 +353,16 @@ type System interface {
325353
// Interface represents the service interface for a program. Start runs before
326354
// the hosting process is granted control and Stop runs when control is returned.
327355
//
328-
// 1. OS service manager executes user program.
329-
// 2. User program sees it is executed from a service manager (IsInteractive is false).
330-
// 3. User program calls Service.Run() which blocks.
331-
// 4. Interface.Start() is called and quickly returns.
332-
// 5. User program runs.
333-
// 6. OS service manager signals the user program to stop.
334-
// 7. Interface.Stop() is called and quickly returns.
335-
// - For a successful exit, os.Exit should not be called in Interface.Stop().
336-
// 8. Service.Run returns.
337-
// 9. User program should quickly exit.
356+
// 1. OS service manager executes user program.
357+
// 2. User program sees it is executed from a service manager (IsInteractive is false).
358+
// 3. User program calls Service.Run() which blocks.
359+
// 4. Interface.Start() is called and quickly returns.
360+
// 5. User program runs.
361+
// 6. OS service manager signals the user program to stop.
362+
// 7. Interface.Stop() is called and quickly returns.
363+
// - For a successful exit, os.Exit should not be called in Interface.Stop().
364+
// 8. Service.Run returns.
365+
// 9. User program should quickly exit.
338366
type Interface interface {
339367
// Start provides a place to initiate the service. The service doesn't
340368
// signal a completed start until after this function returns, so the

service_aix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build aix
1+
//go:build aix
2+
// +build aix
23

34
// Copyright 2015 Daniel Theophanes.
45
// Use of this source code is governed by a zlib-style

service_go1.8.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build go1.8
1+
//go:build go1.8
2+
// +build go1.8
23

34
package service
45

service_nosu_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a zlib-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !su
56
// +build !su
67

78
package service_test

service_su_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// This needs to be run as root/admin hence the reason there is a build tag
6+
//go:build su
67
// +build su
78

89
package service_test

servicetest_unix_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a zlib-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
56
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
67

78
package service_test

0 commit comments

Comments
 (0)