cortesi / modd

A flexible developer tool that runs processes and responds to filesystem changes
MIT License
2.8k stars 128 forks source link

Signal equivalent on Windows #45

Closed frou closed 6 years ago

frou commented 6 years ago

Hi Aldo. We talked about this briefly a while back in this issue.

To recap...

Windows doesn't support signals. So, the feature of modd whereby it can be configured to communicate with daemons by sending signals to them does not work on Windows. The signals silently fail to do anything.

(The exception to this is SIGKILL, which the Go runtime recognises the intent of, and uses a native Windows API to directly kill the target process).


I have added a feature I've called "Pipe Signals" to modd. I've made it so that it can only be enabled on Windows, because there's no need for it on other OSes where normal signals work fine.

When Pipe Signals is enabled, daemons are started with a pipe connected to their STDIN. Instead of a signal being sent to the daemon, the textual name of the signal is written as a line on that pipe instead, e.g. hangup\n or interrupt\n.

The daemon process can read its STDIN and take appropriate action. For example, I have also updated devd to be able to consume hangup in that way to cause a livereload on Windows.

Currently the feature is disabled by default (enabled using modd --pipesignals).

What do you think?

cortesi commented 6 years ago

Hi Duncan. Let me mull this over a bit. I like the approach, and I wonder if there is an argument for making this more general - that is, whether the ability to write to a process's stdin rather than send a signal might be useful in other cases on all platforms.

frou commented 6 years ago

Something to keep in mind is that it's probably a worthy goal for an identical modd.conf file to"just work", whether the user is on Unix or Windows. Presumably we don't want to get into a situation where projects have both a modd-unix.conf and modd-windows.conf?

frou commented 6 years ago

In that line of thinking, I can imagine the following as modd.conf syntax:

Use a signal:

daemon +sighup: devd -m .

Use a message:

daemon |reload: devd -m .

Use a signal if the OS supports it, otherwise use a message:

daemon +sighup|reload: devd -m .
ghost commented 6 years ago

Remove all kits please

frou commented 6 years ago

Since I'm no longer using Windows for development, I'm not fussed about this mechanism any more