-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repoint kardianos/service to fork elastic/kardianos-service (#4859)
* Repoint kardianos/service to fork elastic/kardianos-service * Adding comment * Rename elastic/kardianos-service to elastic/go-service * Change to github.com/elastic/go-service. * Running mage fmt --------- Co-authored-by: Blake Rouse <[email protected]> (cherry picked from commit 6e55d65) # Conflicts: # internal/pkg/agent/install/switch.go
- Loading branch information
1 parent
a37d6c4
commit be1c4a2
Showing
11 changed files
with
149 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -3759,36 +3789,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : github.com/kardianos/service | ||
Version: v1.2.1-0.20210728001519-a323c3813bc7 | ||
Licence type (autodetected): Zlib | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/github.com/kardianos/[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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package install | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/schollz/progressbar/v3" | ||
|
||
"github.com/elastic/go-service" | ||
|
||
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths" | ||
"github.com/elastic/elastic-agent/internal/pkg/agent/perms" | ||
"github.com/elastic/elastic-agent/pkg/utils" | ||
) | ||
|
||
// SwitchExecutingMode switches the executing mode of the installed Elastic Agent. | ||
// | ||
// When username and groupName are blank then it switched back to root/Administrator and when a username/groupName is | ||
// provided then it switched to running with that username and groupName. | ||
func SwitchExecutingMode(topPath string, pt *progressbar.ProgressBar, username string, groupName string) error { | ||
// ensure service is stopped | ||
status, err := EnsureStoppedService(topPath, pt) | ||
Check failure on line 25 in internal/pkg/agent/install/switch.go GitHub Actions / lint (ubuntu-latest)
|
||
if err != nil { | ||
// context for the error already provided in the EnsureStoppedService function | ||
return err | ||
} | ||
|
||
// ensure that upon exit of this function that the service is always placed back to running, in the case | ||
// that it was running when the command was executed | ||
defer func() { | ||
if err != nil && status == service.StatusRunning { | ||
_ = StartService(topPath) | ||
} | ||
}() | ||
|
||
// ensure user/group are created | ||
var ownership utils.FileOwner | ||
if username != "" && groupName != "" { | ||
ownership, err = EnsureUserAndGroup(username, groupName, pt) | ||
Check failure on line 42 in internal/pkg/agent/install/switch.go GitHub Actions / lint (ubuntu-latest)
|
||
if err != nil { | ||
// context for the error already provided in the EnsureUserAndGroup function | ||
return err | ||
} | ||
} | ||
|
||
// **start critical section** | ||
// after this point changes will be made that can leave the installed Elastic Agent broken if they do not | ||
// complete successfully | ||
|
||
// perform platform specific work | ||
err = switchPlatformMode(pt, ownership) | ||
Check failure on line 54 in internal/pkg/agent/install/switch.go GitHub Actions / lint (ubuntu-latest)
|
||
|
||
// fix all permissions to use the new ownership | ||
pt.Describe("Adjusting permissions") | ||
err = perms.FixPermissions(topPath, perms.WithOwnership(ownership)) | ||
if err != nil { | ||
return fmt.Errorf("failed to perform permission changes on path %s: %w", topPath, err) | ||
} | ||
if paths.ShellWrapperPath != "" { | ||
err = perms.FixPermissions(paths.ShellWrapperPath, perms.WithOwnership(ownership)) | ||
if err != nil { | ||
return fmt.Errorf("failed to perform permission changes on path %s: %w", paths.ShellWrapperPath, err) | ||
} | ||
} | ||
|
||
// the service has to be uninstalled | ||
pt.Describe("Removing service") | ||
// error is ignored because it's possible that its already uninstalled | ||
// | ||
// this can happen if this action failed in the middle of this critical section, so to allow the | ||
// command to be called again we don't error on the uninstall | ||
// | ||
// the install error below will include an error about the service still existing if this failed | ||
// to uninstall (really this should never fail, but the unexpected can happen) | ||
_ = UninstallService(topPath) | ||
Check failure on line 78 in internal/pkg/agent/install/switch.go GitHub Actions / lint (ubuntu-latest)
|
||
|
||
// re-install service | ||
pt.Describe("Installing service") | ||
err = InstallService(topPath, ownership, username, groupName) | ||
Check failure on line 82 in internal/pkg/agent/install/switch.go GitHub Actions / lint (ubuntu-latest)
|
||
if err != nil { | ||
pt.Describe("Failed to install service") | ||
// error context already added by InstallService | ||
|
||
// this is now in a bad state, because the service is uninstall and now the service failed to install | ||
return err | ||
} | ||
pt.Describe("Installed service") | ||
|
||
// start the service | ||
pt.Describe("Starting service") | ||
err = StartService(topPath) | ||
if err != nil { | ||
pt.Describe("Failed to start service") | ||
// error context already added by InstallService | ||
|
||
// this is now in a bad state, because the service is not running and failed to install | ||
return err | ||
} | ||
|
||
// **end critical section** | ||
// service is now re-created and started | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters