-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple/stupid 'command' service manager.
If a cert specifies 'service_manager' setting as 'command', then action is passed to /bin/bash -c (or /bin/sh if bash can't be found). This allows custom actions to be taken- things beyond just init scripts. Note that there are multiple CERTMGR_* variables exposed to the shell code invoked; this is to allow for the target to decide what to do when these things change.
- Loading branch information
Showing
4 changed files
with
108 additions
and
8 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
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,62 @@ | ||
package svcmgr | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/cloudflare/cfssl/log" | ||
) | ||
|
||
var ( | ||
shellBinary string | ||
canCheckSyntax bool | ||
) | ||
|
||
type commandManager struct { | ||
command string | ||
} | ||
|
||
func (cm commandManager) TakeAction(change_type string, spec_path string, ca_path string, cert_path string, key_path string) error { | ||
env := []string{ | ||
"CERTMGR_CA_PATH=" + ca_path, | ||
"CERTMGR_CERT_PATH=" + cert_path, | ||
"CERTMGR_KEY_PATH=" + key_path, | ||
"CERTMGR_SPEC_PATH=" + spec_path, | ||
"CERTMGR_CHANGE_TYPE=" + change_type, | ||
} | ||
return runEnv(env, shellBinary, "-c", cm.command) | ||
} | ||
|
||
func newCommandManager(action string, service string) (Manager, error) { | ||
if service != "" { | ||
log.Warningf("svcmgr 'command': service '%s' for action '%s' doesn't do anything, ignoring", service, action) | ||
} | ||
if canCheckSyntax { | ||
err := run(shellBinary, "-n", "-c", action) | ||
if err != nil { | ||
return nil, fmt.Errorf("svcmgr 'command': action '%s' failed bash -n -c parse checks: %s", action, err) | ||
} | ||
} else { | ||
log.Warningf("svcmgr 'command': skipping parse check for '%s' since bash couldn't be found", action) | ||
} | ||
return &commandManager{ | ||
command: action, | ||
}, nil | ||
} | ||
|
||
func init() { | ||
// prefer bash if we can find it since it allows us to validate | ||
var err error | ||
shellBinary, err = exec.LookPath("bash") | ||
canCheckSyntax = true | ||
if err != nil { | ||
log.Infof("svcmgr 'command' couldn't find a bash binary; action statements will not be able to be validated for syntax: err %s", err) | ||
shellBinary, err = exec.LookPath("sh") | ||
if err != nil { | ||
log.Error("svcmgr 'command' is unavailable due to both bash and sh not being found in PATH") | ||
return | ||
} | ||
canCheckSyntax = false | ||
} | ||
SupportedBackends["command"] = newCommandManager | ||
} |
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