Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realize is not killing the current app #247

Open
L4B0MB4 opened this issue May 17, 2019 · 5 comments
Open

Realize is not killing the current app #247

L4B0MB4 opened this issue May 17, 2019 · 5 comments

Comments

@L4B0MB4
Copy link

L4B0MB4 commented May 17, 2019

Currently when you build a webserver in go, realize will not restart the app on change but will run the new one in parallel.

Expected:
When you change an app and the original is still running, realize should stop the old version and start the new version

Actual Behaviour
Realize runs old and new versions of the app in parallel.

Reproduction
main.go

package main

import (
	"fmt"
	"log"
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	ImportMe()
	fmt.Fprintf(w, "Hi there, I love %s!", r.URL)
}

func main() {
	http.HandleFunc("/", handler)
	log.Fatal(http.ListenAndServe(":8080", nil))

}

.realize.yaml

settings:
  legacy:
    force: true
    interval: 0s
schema:
  - name: go-server
    path: .
    commands:
      clean:
        status: true
      install:
        status: true
      build:
        status: true
      run:
        status: true
        method: go-server.exe
    watcher:
      extensions:
        - go
      paths:
        - /
      ignored_paths:
        - .git
        - .realize
        - vendor

Now start realize with "realize start".
[13:56:23][GO-SERVER] : Install started [13:56:24][GO-SERVER] : Install completed in 1.671 s [13:56:24][GO-SERVER] : Build started [13:56:26][GO-SERVER] : Build completed in 1.634 s [13:56:26][GO-SERVER] : Running..

Change something in your go-code
[13:56:23][GO-SERVER] : Install started [13:56:24][GO-SERVER] : Install completed in 1.671 s [13:56:24][GO-SERVER] : Build started [13:56:26][GO-SERVER] : Build completed in 1.634 s [13:56:26][GO-SERVER] : Running.. [13:56:57][GO-SERVER] : GO changed D:\go-server\main.go [13:56:58][GO-SERVER] : Install started [13:56:59][GO-SERVER] : Install completed in 1.291 s [13:57:00][GO-SERVER] : Build started [13:57:01][GO-SERVER] : Build completed in 1.591 s [13:57:01][GO-SERVER] : Running.. [13:57:01][GO-SERVER] : 2019/05/17 13:57:01 listen tcp :8080: bind: Normalerweise darf jede Socketadresse (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet werden.

Translation for last line: " Normaly each socket adress should only be used once"

@L4B0MB4
Copy link
Author

L4B0MB4 commented May 17, 2019

Please let me know if I´m missing a command that changes this behaviour

@pavles6
Copy link

pavles6 commented Jun 2, 2019

I am having a same problem. Hopefully author will fix this.

@jc21
Copy link

jc21 commented Jul 9, 2019

I too am having the same problem. My app runs a webserver and also runs workers that wait to finish jobs before exiting when requested to exit. So what ends up happening is the newly built version runs before the previous command has exited cleanly, and my app complains that the http port is already in use and fails.

Given that I want my jobs to complete and not have the app killed forcefully, perhaps realize could make sure the previous command has ended before starting a new one. A config setting for the termination type, forceful or clean might be useful?

@pedrofaria
Copy link

Same issue here

@pedrofaria
Copy link

Well after some time on research, I figure out a workaround to fix this problem. Basically you need to run a command every restart.

Inside a linux container, I did this with my .realize.yaml file:

# ...
  watcher:
    scripts:
    - type: before
      command: pkill server-api
      output: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants