Skip to content

Commit

Permalink
Change to github.com/elastic/go-service.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakerouse authored and ycombinator committed Jun 11, 2024
1 parent 1cacb4c commit 16b2e2a
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 142 deletions.
64 changes: 32 additions & 32 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,36 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0.
limitations under the License.


--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-service
Version: v0.0.0-20240611154109-f44f756f194f
Licence type (autodetected): Zlib
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected]/LICENSE:

Copyright (c) 2015 Daniel Theophanes

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.


--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-sysinfo
Version: v1.14.0
Expand Down Expand Up @@ -3782,36 +3812,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-service
Version: v0.0.0-20230215200102-9832e01049dd
Licence type (autodetected): Zlib
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected]/LICENSE:

Copyright (c) 2015 Daniel Theophanes

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.


--------------------------------------------------------------------------------
Dependency : github.com/magefile/mage
Version: v1.15.0
Expand Down Expand Up @@ -12445,11 +12445,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
Dependency : golang.org/x/sys
Version: v0.20.0
Version: v0.21.0
Licence type (autodetected): BSD-3-Clause
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.20.0/LICENSE:
Contents of probable licence file $GOMODCACHE/golang.org/x/sys@v0.21.0/LICENSE:

Copyright (c) 2009 The Go Authors. All rights reserved.

Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/go-elasticsearch/v8 v8.14.0
github.com/elastic/go-licenser v0.4.1
github.com/elastic/go-service v0.0.0-20240611154109-f44f756f194f
github.com/elastic/go-sysinfo v1.14.0
github.com/elastic/go-ucfg v0.8.8
github.com/elastic/mock-es v0.0.0-20240605193845-b5546a703d6f
Expand All @@ -36,7 +37,6 @@ require (
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
github.com/josephspurrier/goversioninfo v0.0.0-20190209210621-63e6d1acd3dd
github.com/kardianos/service v1.2.1-0.20210728001519-a323c3813bc7
github.com/magefile/mage v1.15.0
github.com/mitchellh/gox v1.0.1
github.com/mitchellh/hashstructure v1.1.0
Expand Down Expand Up @@ -65,7 +65,7 @@ require (
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/sys v0.21.0
golang.org/x/term v0.20.0
golang.org/x/text v0.15.0
golang.org/x/time v0.5.0
Expand Down Expand Up @@ -295,9 +295,6 @@ replace (
github.com/dop251/goja => github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20
github.com/dop251/goja_nodejs => github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6
github.com/tonistiigi/fifo => github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c

// The upstream fork at https://github.com/kardianos/service does not seem to be actively maintained.
github.com/kardianos/service => github.com/elastic/go-service v0.0.0-20230215200102-9832e01049dd
)

// Exclude this version because the version has an invalid checksum.
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ github.com/elastic/go-elasticsearch/v8 v8.14.0/go.mod h1:WRvnlGkSuZyp83M2U8El/LG
github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ=
github.com/elastic/go-licenser v0.4.1 h1:1xDURsc8pL5zYT9R29425J3vkHdt4RT5TNEMeRN48x4=
github.com/elastic/go-licenser v0.4.1/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/elastic/go-service v0.0.0-20230215200102-9832e01049dd h1:oCW0HQv6qJRDQ4H4izgrISOjXja4C+Atmz4sgl3aq1k=
github.com/elastic/go-service v0.0.0-20230215200102-9832e01049dd/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
github.com/elastic/go-service v0.0.0-20240611154109-f44f756f194f h1:kMtsJ3zfcBBR6wfbf5yUExmvWLru6R7zSLaJIfSjU3g=
github.com/elastic/go-service v0.0.0-20240611154109-f44f756f194f/go.mod h1:3lVNFcuNMdWJrSpGF5SMPUVuC+qOYobfPIrMQUoizrk=
github.com/elastic/go-structform v0.0.10 h1:oy08o/Ih2hHTkNcRY/1HhaYvIp5z6t8si8gnCJPDo1w=
github.com/elastic/go-structform v0.0.10/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
Expand Down Expand Up @@ -2545,8 +2545,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"gopkg.in/ini.v1"

"github.com/kardianos/service"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"runtime"
"strings"

"github.com/elastic/go-service"
"github.com/jaypipes/ghw"
"github.com/kardianos/service"
"github.com/otiai10/copy"
"github.com/schollz/progressbar/v3"

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/installed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"path/filepath"

"github.com/kardianos/service"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/install/pkgmgr"
Expand Down
98 changes: 3 additions & 95 deletions internal/pkg/agent/install/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package install

import (
"fmt"
"path/filepath"
"runtime"

"github.com/kardianos/service"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)
Expand Down Expand Up @@ -85,11 +84,6 @@ func newService(topPath string, opt ...serviceOpt) (service.Service, error) {
}

if runtime.GOOS == "linux" {
// The github.com/kardianos/service library doesn't support KillMode in their prebuilt template.
// This option allows to pass our own template for the systemd unit configuration, which is a copy
// of the prebuilt template with added KillMode option
cfg.Option["SystemdScript"] = linuxSystemdScript

// By setting KillMode=process in Elastic Agent's systemd unit configuration file, we ensure
// that in a scenario where the upgraded Agent's process is repeatedly crashing, systemd keeps
// the Upgrade Watcher process running so it can monitor the Agent process for long enough to
Expand All @@ -99,98 +93,12 @@ func newService(topPath string, opt ...serviceOpt) (service.Service, error) {
}

if runtime.GOOS == "darwin" {
// The github.com/kardianos/service library doesn't support ExitTimeOut in their prebuilt template.
// This option allows to pass our own template for the launch daemon plist, which is a copy
// of the prebuilt template with added ExitTimeOut option
cfg.Option["LaunchdConfig"] = darwinLaunchdConfig
cfg.Option["ExitTimeOut"] = darwinServiceExitTimeout

// Set the stdout and stderr logs to be inside the installation directory, ensures that the
// Set log directory to be inside the installation directory, ensures that the
// executing user for the service can write to the directory for the logs.
cfg.Option["StandardOutPath"] = filepath.Join(topPath, fmt.Sprintf("%s.out.log", paths.ServiceName))
cfg.Option["StandardErrorPath"] = filepath.Join(topPath, fmt.Sprintf("%s.err.log", paths.ServiceName))
cfg.Option["LogDirectory"] = topPath
}

return service.New(nil, cfg)
}

// A copy of the launchd plist template from github.com/kardianos/service
// with added .Config.Option.ExitTimeOut option
const darwinLaunchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key>
<string>{{html .Name}}</string>
<key>ProgramArguments</key>
<array>
<string>{{html .Path}}</string>
{{range .Config.Arguments}}
<string>{{html .}}</string>
{{end}}
</array>
{{if .UserName}}<key>UserName</key>
<string>{{html .UserName}}</string>{{end}}
{{if .Config.Option.GroupName -}}
<key>GroupName</key>
<string>{{html .Config.Option.GroupName}}</string>
{{- end}}
{{if .ChRoot}}<key>RootDirectory</key>
<string>{{html .ChRoot}}</string>{{end}}
{{if .Config.Option.ExitTimeOut}}<key>ExitTimeOut</key>
<integer>{{html .Config.Option.ExitTimeOut}}</integer>{{end}}
{{if .WorkingDirectory}}<key>WorkingDirectory</key>
<string>{{html .WorkingDirectory}}</string>{{end}}
<key>SessionCreate</key>
<{{bool .SessionCreate}}/>
<key>KeepAlive</key>
<{{bool .KeepAlive}}/>
<key>RunAtLoad</key>
<{{bool .RunAtLoad}}/>
<key>Disabled</key>
<false/>
<key>StandardOutPath</key>
<string>{{html .Config.Option.StandardOutPath}}</string>
<key>StandardErrorPath</key>
<string>{{html .Config.Option.StandardErrorPath}}</string>
</dict>
</plist>
`

// A copy of the systemd config template from github.com/kardianos/service
// with added .Config.Option.KillMode option
const linuxSystemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}}
{{if .UserName}}User={{.UserName}}{{end}}
{{if .Config.Option.GroupName -}}
Group={{.Config.Option.GroupName}}
{{- end}}
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
{{if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
{{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}}
{{if .Restart}}Restart={{.Restart}}{{end}}
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
{{if .Config.Option.KillMode}}KillMode={{.Config.Option.KillMode}}{{end}}
RestartSec=120
EnvironmentFile=-/etc/sysconfig/{{.Name}}
[Install]
WantedBy=multi-user.target
`
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
"time"

"github.com/kardianos/service"
"github.com/elastic/go-service"
"github.com/schollz/progressbar/v3"

"github.com/elastic/elastic-agent-libs/logp"
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"runtime"
"time"

"github.com/kardianos/service"
"github.com/elastic/go-service"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
Expand Down
2 changes: 1 addition & 1 deletion testing/integration/upgrade_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"testing"
"time"

"github.com/kardianos/service"
"github.com/elastic/go-service"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down

0 comments on commit 16b2e2a

Please sign in to comment.