Skip to content

Instantly share code, notes, and snippets.

@badri
Created October 15, 2015 11:19
Show Gist options
  • Save badri/e13bf52d58b22edeb1d7 to your computer and use it in GitHub Desktop.
Save badri/e13bf52d58b22edeb1d7 to your computer and use it in GitHub Desktop.
tsuru app-run --interactive patch
diff --git a/api/app.go b/api/app.go
index 6f83296..4df3e3b 100644
--- a/api/app.go
+++ b/api/app.go
@@ -467,6 +467,7 @@ func runCommand(w http.ResponseWriter, r *http.Request, t auth.Token) error {
}
appName := r.URL.Query().Get(":app")
once := r.URL.Query().Get("once")
+ interactive := r.URL.Query().Get("interactive")
rec.Log(u.Email, "run-command", "app="+appName, "command="+string(c))
app, err := getApp(appName, u, r)
if err != nil {
@@ -475,7 +476,7 @@ func runCommand(w http.ResponseWriter, r *http.Request, t auth.Token) error {
keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 30*time.Second, "")
defer keepAliveWriter.Stop()
writer := &tsuruIo.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
- err = app.Run(string(c), writer, once == "true")
+ err = app.Run(string(c), writer, once == "true", interactive == "false")
if err != nil {
writer.Encode(tsuruIo.SimpleJsonMessage{Error: err.Error()})
return err
diff --git a/app/app.go b/app/app.go
index 03d3ecb..1de9bd2 100644
--- a/app/app.go
+++ b/app/app.go
@@ -803,7 +803,7 @@ func (app *App) InstanceEnv(name string) map[string]bind.EnvVar {
// Run executes the command in app units, sourcing apprc before running the
// command.
-func (app *App) Run(cmd string, w io.Writer, once bool) error {
+func (app *App) Run(cmd string, w io.Writer, once bool, interactive bool) error {
if !app.Available() {
return stderr.New("App must be available to run commands")
}
@@ -811,19 +811,23 @@ func (app *App) Run(cmd string, w io.Writer, once bool) error {
logWriter := LogWriter{App: app, Source: "app-run"}
logWriter.Async()
defer logWriter.Close()
- return app.sourced(cmd, io.MultiWriter(w, &logWriter), once)
+ return app.sourced(cmd, io.MultiWriter(w, &logWriter), once, interactive)
}
-func (app *App) sourced(cmd string, w io.Writer, once bool) error {
+func (app *App) sourced(cmd string, w io.Writer, once bool, interactive bool) error {
source := "[ -f /home/application/apprc ] && source /home/application/apprc"
cd := fmt.Sprintf("[ -d %s ] && cd %s", defaultAppDir, defaultAppDir)
cmd = fmt.Sprintf("%s; %s; %s", source, cd, cmd)
- return app.run(cmd, w, once)
+ return app.run(cmd, w, once, interactive)
}
-func (app *App) run(cmd string, w io.Writer, once bool) error {
+func (app *App) run(cmd string, w io.Writer, once bool, interactive bool) error {
if once {
- return Provisioner.ExecuteCommandOnce(w, w, app, cmd)
+ if interactive {
+ return Provisioner.ExecuteCommandOnce(w, w, app, cmd, "-i", "-t")
+ } else {
+ return Provisioner.ExecuteCommandOnce(w, w, app, cmd)
+ }
}
return Provisioner.ExecuteCommand(w, w, app, cmd)
}
diff --git a/provision/provision.go b/provision/provision.go
index b3eb5bb..ca321b6 100644
--- a/provision/provision.go
+++ b/provision/provision.go
@@ -161,7 +161,7 @@ type App interface {
// Run executes the command in app units. Commands executed with this
// method should have access to environment variables defined in the
// app.
- Run(cmd string, w io.Writer, once bool) error
+ Run(cmd string, w io.Writer, once bool, interactive bool) error
Envs() map[string]bind.EnvVar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment