Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Add a file watcher to re-start host when files change #45

Closed
glennc opened this issue May 20, 2014 · 9 comments
Closed

Add a file watcher to re-start host when files change #45

glennc opened this issue May 20, 2014 · 9 comments
Assignees
Milestone

Comments

@glennc
Copy link
Member

glennc commented May 20, 2014

So that we can edit a controller and refresh the browser to see changes.

@glennc
Copy link
Member Author

glennc commented May 20, 2014

@davidfowl We said to move this bug to here, but does it actually make sense? Can hosting actually do it?

@seanfuture
Copy link

In case useful to anyone on Mac OS X ( as a temporary stop-gap ), I've created the following scripts which implement file system watching for the sample HelloMVC project, as listed below. This is used in conjunction w/ LiveReload for non-compiled file changes. To start the script, run ./watch.sh from the Terminal ( scripts copied to root of HelloMVC example ):

#/!bin/sh
# watch.sh - FS watcher for ASP.NET vNext on Mac OS X
# .. Used in conjunction with ./auto-restart.sh
# .. To use run ./watch.sh from the Terminal
# Startup
pkill -f kestrel
pkill -15 screen
screen -S vnext -d -m
screen -S vnext -p 0 -X stuff $'k kestrel\n'
# Start file system watch ..
fswatch -o ./Controllers ./Models | xargs -n1 ./auto-restart.sh
#/!bin/sh
# auto-restart.sh - Restart component for ASP.NET vNext on Mac OS X
# .. Used in conjunction with ./watch.sh
# screen -S vnext -p 0 -X stuff $'pkill -f kestrel\n'
screen -S vnext -p 0 -X stuff $'q\n'
while [ 1 ]
do
    pid=`ps -ef | grep "kestrel" | grep -v grep | awk ' {print $2}'`
    if [ "$pid" = "" ]
    then
            screen -S vnext -p 0 -X stuff $'k kestrel\n'
            exit
    fi
    sleep 0.05
done

You may wish to sudo chmod +x watch.sh; sudo chmod +x auto-restart.sh before running. There is a slight pause / down-time incurred while the web server restarts itself. "brew install fswatch" was run to install fswatch. Additional code paths must be added to the "fswatch" line in watch.sh.

Above scripts are not affiliated w/ ASP.NET vNext and aren't officially supported of course - Rather, thought they might be of interest to at least one individual.

I'm sure a more elegant and streamlined solution is in the works.

@glennc glennc added this to the Backlog milestone Sep 12, 2014
@Praburaj
Copy link
Contributor

Praburaj commented Apr 8, 2015

@glennc is this still a problem? I think we do restart the process when we pass in a --watch switch while starting the dnx process right?

@akamud
Copy link

akamud commented May 1, 2015

I'm testing this on Windows and --watch just kills the process without restarting it.

By looking at the code here, it doesn't restart.

@mykebates
Copy link

I am seeing the same on Windows and Mac.

@muratg muratg removed this from the Backlog milestone May 4, 2015
@Tratcher
Copy link
Member

Tratcher commented May 4, 2015

@davidfowl? I recall that this is intended. --watch looks for file changes and kills the process, but it relies on another process to monitor it and re-start it. IIS does this for us, and I think VS does also.

@seanfuture
Copy link

If you're thinking of leaving it as-is, then the current setup will continue to be relatively substandard for those not using IIS compared to alternate technologies. In Node.js when using grunt / gulp, for example, FS watchers and automatic restarts of web servers are common place and super convenient. I recommend modernizing the toolchain for those who don't use IIS to support this and potentially offer a different switch / default behavior depending on settings and/or environment.

@muratg muratg added this to the 1.0.0-beta5 milestone May 7, 2015
@muratg
Copy link

muratg commented May 7, 2015

I don't recall the discussion around having another process doing the restart for you - this is for sure not the case for cross plat. @lodejard @davidfowl any suggestions here? I'm leaning towards doing the restart here.

@Tratcher
Copy link
Member

Going back to aspnet/dnx#1795 as the primary discussion thread.

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

No branches or pull requests

7 participants