Example #1
0
func Git(provisioner provision.Provisioner, app provision.App, w io.Writer) error {
	log.Write(w, []byte("\n ---> Tsuru receiving push\n"))
	log.Write(w, []byte("\n ---> Replicating the application repository across units\n"))
	out, err := clone(provisioner, app)
	if err != nil {
		out, err = pull(provisioner, app)
	}
	if err != nil {
		msg := fmt.Sprintf("Got error while clonning/pulling repository: %s -- \n%s", err.Error(), string(out))
		log.Write(w, []byte(msg))
		return errors.New(msg)
	}
	log.Write(w, out)
	log.Write(w, []byte("\n ---> Installing dependencies\n"))
	if err := provisioner.InstallDeps(app, w); err != nil {
		log.Write(w, []byte(err.Error()))
		return err
	}
	log.Write(w, []byte("\n ---> Restarting application\n"))
	if err := app.Restart(w); err != nil {
		log.Write(w, []byte(err.Error()))
		return err
	}
	return log.Write(w, []byte("\n ---> Deploy done!\n\n"))
}
Example #2
0
// Restart runs the restart hook for the app, writing its output to w.
func (app *App) Restart(w io.Writer) error {
	app.Log("executing hook to restart", "tsuru")
	err := app.preRestart(w)
	if err != nil {
		return err
	}
	err = log.Write(w, []byte("\n ---> Restarting your app\n"))
	if err != nil {
		return err
	}
	err = Provisioner.Restart(app)
	if err != nil {
		return err
	}
	return app.postRestart(w)
}
Example #3
0
File: app.go Project: nemx/tsuru
// Restart runs the restart hook for the app, writing its output to w.
func (app *App) Restart(w io.Writer) error {
	err := app.hookRunner().Restart(app, w, "before")
	if err != nil {
		return err
	}
	err = log.Write(w, []byte("\n ---> Restarting your app\n"))
	if err != nil {
		log.Errorf("[restart] error on write app log for the app %s - %s", app.Name, err)
		return err
	}
	err = Provisioner.Restart(app)
	if err != nil {
		log.Errorf("[restart] error on restart the app %s - %s", app.Name, err)
		return err
	}
	return app.hookRunner().Restart(app, w, "after")
}
Example #4
0
// runHook executes the given list of commands, as a hook identified by the
// kind string. If the list is empty, it returns nil.
//
// The hook itself may be "pre-restart" or "post-restart".
func (app *App) runHook(w io.Writer, cmds []string, kind string) error {
	if len(cmds) == 0 {
		return nil
	}
	app.Log(fmt.Sprintf("Executing %s hook...", kind), "tsuru")
	err := log.Write(w, []byte("\n ---> Running "+kind+"\n"))
	if err != nil {
		return err
	}
	for _, cmd := range cmds {
		err = app.sourced(cmd, w)
		if err != nil {
			return err
		}
	}
	return err
}
Example #5
0
File: app.go Project: janqii/tsuru
func (app *App) Stop(w io.Writer) error {
	log.Write(w, []byte("\n ---> Stopping your app\n"))
	err := Provisioner.Stop(app)
	if err != nil {
		log.Errorf("[stop] error on stop the app %s - %s", app.Name, err)
		return err
	}
	units := make([]Unit, len(app.Units))
	for i, u := range app.Units {
		u.State = provision.StatusStopped.String()
		units[i] = u
	}
	app.Units = units
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	return conn.Apps().Update(bson.M{"name": app.Name}, app)
}
Example #6
0
File: app.go Project: nihao/tsuru
// runHook executes the given list of commands, as a hook identified by the
// kind string. If the list is empty, it returns nil.
//
// The hook itself may be "pre-restart" or "post-restart".
func (app *App) runHook(w io.Writer, cmds []string, kind string) error {
	if len(cmds) == 0 {
		app.Log(fmt.Sprintf("Skipping %s hooks...", kind), "tsuru")
		fmt.Fprintf(w, "Skipping %s hooks...", kind)
		return nil
	}
	app.Log(fmt.Sprintf("Executing %s hook...", kind), "tsuru")
	err := log.Write(w, []byte("\n ---> Running "+kind+"\n"))
	if err != nil {
		return err
	}
	for _, cmd := range cmds {
		p, err := deployHookAbsPath(cmd)
		if err != nil {
			app.Log(fmt.Sprintf("Error obtaining absolute path to hook: %s.", err), "tsuru")
			continue
		}
		err = app.Run(p, w)
		if err != nil {
			return err
		}
	}
	return err
}