Comments (15)
I was having the same problem: Putting "go run xxx.go" in the -command doesn't restart.
But after trying a few options, I found the following works:
CompileDaemon -build "go build cmds/server/server.go" -command "./server"
I had to use both the -build and -command flags.
from compiledaemon.
OT but since I have done this, config.vm.synced_folder "src/", "/dst", type: 'nfs'
should suffice.
from compiledaemon.
Do you have a short example that reproduces the behaviour?
from compiledaemon.
+1 same here
from compiledaemon.
@jswierad Can you provide a little bit more information? The initial post was not very detailed to begin with so any bit of information helps. What type of application do you run? Can you provide the source code? etc.
from compiledaemon.
I figured it out already (10 mins ago....)
My issue was vagrant and shared folders. I run my app inside vagrant, with code shared via shared folders (no nfs, no rsync). Changes that I make outside vagrant to this code are not being reported as "modified" inside vagrant, so CopileDaemon doesn't detect any changes.
When I change this code inside vagrant, everything is working correctly.
Now trying to find out how to make my vagrant to use rsync or nfs, since there are some bugs in vagrant in this area as well...
from compiledaemon.
Thanks a lot for hint; already tried that, unfortunately I'm having issues with vagrant and nfs.
Yak shaving for me today...
from compiledaemon.
It seems I've found a solution (not perfect, more like workaround, but it works in above setup)
This vagrant plugin: https://github.com/smerrill/vagrant-gatling-rsync
Nice stuff for fixing auto-rsync in Mac and Vagrant that is broken out of the box.
from compiledaemon.
@githubnemo I also encountered the same problem
2017/06/21 11:26:05 Running build command!
2017/06/21 11:26:06 Build ok.
2017/06/21 11:26:06 Restarting the given command.
2017/06/21 11:26:11 Running build command!
2017/06/21 11:26:12 Build ok.
2017/06/21 11:26:12 Hard stopping the current process..
2017/06/21 11:26:12 Restarting the given command.
2017/06/21 11:26:12 stdout: 2017/06/21 11:26:12 Error in main(): listen tcp 127.0.0.1:3100: bind: address already in use
Here's the simple example I used to demonstrate the problem
package main
import (
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
log.SetOutput(os.Stdout)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGQUIT)
server := &http.Server{
Addr: "localhost:3100",
Handler: http.DefaultServeMux,
}
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
log.Println("111")
})
go func() {
if err := server.ListenAndServe(); err != nil {
log.Printf("Error in main(): %v", err)
}
}()
log.Println("interrupt: ", <-sig)
server.Close()
}
I've tried to include listening to all signals but still didn't work...
I'm running CompileDaemon using the following options
CompileDaemon -verbose -command="go run app.go"
from compiledaemon.
Are you sure that the process is still running or is the socket just not freed yet? Can you check if the process is terminated?
from compiledaemon.
I'm not 100% sure. I did grep before/after code change
~/G/s/s/u/r/raw-data ☕️ ps aux | grep app.go
<E> fish: getcwd() failed with errno 2/No such file or directory
rsuwandi 93552 0.1 0.0 556598884 2324 s020 S+ 2:50PM 0:00.12 CompileDaemon -verbose -exclude-dir .git -exclude-dir .idea -exclude-dir .vs-code -pattern=(.+\.go|.+\.c|.+\.json)$ -command=go run app.go -color -command-stop
rsuwandi 93638 0.0 0.0 2432804 1952 s027 R+ 2:51PM 0:00.00 grep --color=always -I app.go
rsuwandi 93560 0.0 0.1 556633292 11608 s020 S+ 2:51PM 0:00.15 go run app.go
~/G/s/s/u/r/raw-data ☕️ ps aux | grep app.go
rsuwandi 93552 0.1 0.0 556598884 2328 s020 S+ 2:50PM 0:00.15 CompileDaemon -verbose -exclude-dir .git -exclude-dir .idea -exclude-dir .vs-code -pattern=(.+\.go|.+\.c|.+\.json)$ -command=go run app.go -color -command-stop
rsuwandi 93692 0.0 0.0 2442020 2056 s027 S+ 2:51PM 0:00.00 grep --color=always -I app.go
rsuwandi 93682 0.0 0.1 556625356 11676 s020 S+ 2:51PM 0:00.17 go run app.go
PID changed so I assume the process is killed but when I call the endpoint it's still responding with the original behaviour (printing "111" instead of something else). If it's only the socket that's not freed I would imagine that hitting the endpoint will not do anything isn't it?
from compiledaemon.
Are you sure that you are running the correct application? It does not seem to be a problem with CompileDaemon as far as I can see.
from compiledaemon.
@githubnemo Yup, I recorded a gif file to demonstrate. app.go
is the same file as I described earlier
Previously when hitting the endpoint it prints "111" but I changed it to "abc" and it still shows "111"
from compiledaemon.
@lancerushing Your way worked for me, thanks for sharing!!
from compiledaemon.
To summarize this issue:
- the general problem of processes not being restarted is fixed with the introduction of hard-stopping, the example in this comment works just fine simply by running
CompileDaemon -command ./server
, following output can be seen:
% CompileDaemon -command ./server
2020/11/09 22:56:13 Running build command!
2020/11/09 22:56:13 Build ok.
2020/11/09 22:56:13 Restarting the given command.
2020/11/09 22:56:20 Running build command! # <- change occured
2020/11/09 22:56:20 Build ok.
2020/11/09 22:56:20 Hard stopping the current process..
2020/11/09 22:56:20 Restarting the given command.
- with vagrant the issue is that volumes mounted do not seem to propagate the change info properly which makes
CompileDaemon
think there was no change. This comment suggests to use anrsync
plugin with vagrant to sync contents and notify the VM FS about the change.
I think this issue can be closed.
from compiledaemon.
Related Issues (20)
- Use CompileDaemon with go generate? HOT 4
- Latest commit tag not included in master
- include multiple directories HOT 2
- Terminate the program if a build fails
- Restart the program if it fails HOT 2
- Docker + Go 1.18 = /bin/sh: CompileDaemon: not found HOT 2
- package math/bits: unrecognized import path "math/bits" (import path does not begin with hostname) HOT 2
- Install for go 1.18+ HOT 10
- CompileDeamon not found golang 1.18 HOT 10
- "CompileDaemon": executable file not found in $PATH: unknown HOT 2
- Docker - File Changes not being Acknowledged
- Security Best Practice HOT 1
- 1.19 "stuck" on Build ok. HOT 3
- Support go.work
- Could not start command: can't start command: fork/exec ~/directory/to/go-project: no such file or directory HOT 1
- Go does not rebuild when .env file is changed
- Docker MacOS no rebuilding even with pulling on HOT 2
- error obtaining VCS status: exit status 128 HOT 1
- CompileDaemon did not install with vendor directory HOT 1
- Not detecting changes with Docker running on Windows with Linux containers in WSL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiledaemon.