Skip to content

Commit

Permalink
copyFrom for systemd engine
Browse files Browse the repository at this point in the history
  • Loading branch information
zc authored and CMGS committed Mar 13, 2020
1 parent c507ac3 commit e8890b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion engine/systemd/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ func (b *unitBuilder) buildExec() *unitBuilder {

cmds := []string{}
for _, cmd := range b.opts.Cmd {
cmds = append(cmds, fmt.Sprintf("'%s'", cmd))
if strings.Contains(cmd, " ") {
cmd = fmt.Sprintf("'%s'", cmd)
}
cmds = append(cmds, cmd)
}

b.serviceBuffer = append(b.serviceBuffer, []string{
Expand Down
9 changes: 6 additions & 3 deletions engine/systemd/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"path"
"path/filepath"
"strings"

Expand All @@ -22,6 +24,7 @@ const (
cmdSystemdRestart = `/bin/systemctl restart %s`
cmdSystemdStop = `/bin/systemctl stop %s`
cmdSystemdStatus = `/bin/systemctl show %s --property SubState,ActiveState,Environment,Description --no-pager`
cmdCopyToStdout = `/bin/cp -f '%s' /dev/stdout`
)

// VirtualizationCreate creates systemd service
Expand Down Expand Up @@ -159,7 +162,7 @@ func (s *SSHClient) VirtualizationUpdateResource(ctx context.Context, ID string,
}

// VirtualizationCopyFrom copy files from one service to another
func (s *SSHClient) VirtualizationCopyFrom(ctx context.Context, ID, path string) (reader io.ReadCloser, filename string, err error) {
err = types.ErrEngineNotImplemented
return
func (s *SSHClient) VirtualizationCopyFrom(ctx context.Context, ID, source string) (reader io.ReadCloser, filename string, err error) {
stdout, stderr, err := s.runSingleCommand(ctx, fmt.Sprintf(cmdCopyToStdout, source), nil)
return ioutil.NopCloser(stdout), path.Base(source), errors.Wrap(err, stderr.String())
}

0 comments on commit e8890b0

Please sign in to comment.