Go "ready" for cross platform daemon development?

1,225 views
Skip to first unread message

Nathan Trimble

unread,
Oct 5, 2011, 8:06:38 PM10/5/11
to golan...@googlegroups.com
I am getting ready to rewrite some in-house code at work.  Currently we have a python console program and a C# GUI application for uploading data to some servers.  I want to push the upload code into a daemon (RHEL, Mac OS 10.6 and 10.7) and service (Windows).  Before I decide on an environment to write this thing in, I'd like to know how ready for prime time Go might be for this.  I really like the language, and the ease of deployment (no framework/interpreter).

At a high level, the daemon will:

Watch file system
Data / file transfer using HTTP
Use kerberos, HTTPS + basic auth, cookies, etc.
Serve some basic HTML/CSS status/update pages

Before I spend a bunch of time stumbling on various gotchas, I thought I'd consult the list first.  I have done a bit of go coding for fun (a *very* basic DynDNS client).  I've been through the tutorial, sample code, etc.  I have not tried Go on Windows yet though.  That seems to be my biggest unknown.

Thanks.

-Nate

Brad Fitzpatrick

unread,
Oct 5, 2011, 8:21:06 PM10/5/11
to Nathan Trimble, golan...@googlegroups.com
I think you're good to go.  We're in the same boat.  I got a Windows machine recently after a decade apart, specifically for testing my side project on Windows with Go and it was pretty painless and just worked for the most part.  I had to put stuff in conventional Windows paths and I had to fix up one use of os.Link.

There's even a library now to do system tray icons on Windows to say "hey user, I'm running.  click here to launch your web browser to localhost:8080 and see my pretty web UI."

I'm not sure about registering / running as a Windows Service, but I can't imagine it's too hard.

Krzysztof Kowalczyk

unread,
Oct 5, 2011, 9:29:30 PM10/5/11
to Nathan Trimble, golan...@googlegroups.com
It'll be challenging to implement a Windows Service in Go.

First, you'll have to write wrappers around Windows APIs for service
functions (http://msdn.microsoft.com/en-us/library/windows/desktop/ms685942(v=VS.85).aspx).
That's the easy part.

The way windows services work is that a service executable registers a
service callback function that is called by Windows. It cannot be a Go
function because it has to use a specific, WINAPI calling convention
and it's unclear (to me) how that would interact with segmented stacks
in Go. You'll have to write some bridge function. Frankly, you'll
encounter problems that, while probably solvable given enough effort,
might not have been solved before by anyone.

Also be aware that services (written in any language) are severely
restricted in what APIs they can use (no GUI at all, because they run
headless, but also some networking calls are not supported etc.).
Having implemented a windows service once, I don't recommend it at
all.

Also, as far as I know, Go doesn't have cross-platform support for
file changes notifications (inotify/ReadDirectoryChanges()).

-- kjk

On Wed, Oct 5, 2011 at 5:06 PM, Nathan Trimble <nathan....@gmail.com> wrote:

brainman

unread,
Oct 5, 2011, 9:33:54 PM10/5/11
to golan...@googlegroups.com, Nathan Trimble
On Thursday, 6 October 2011 10:21:06 UTC+10, Brad Fitzpatrick wrote:
 
I'm not sure about registering / running as a Windows Service, but I can't imagine it's too hard.



Creating Windows Service is not supported at this moment. It can certainly be done.
Not sure about how easy, but I have been wrong before many time :-)

Alex

brainman

unread,
Oct 5, 2011, 9:48:50 PM10/5/11
to golan...@googlegroups.com, Nathan Trimble
On Thursday, 6 October 2011 11:29:30 UTC+10, Krzysztof Kowalczyk wrote:
It'll be challenging to implement a Windows Service in Go.

We like challenges, that is what we do :-)
 

... It cannot be a Go


function because it has to use a specific, WINAPI calling convention

You can write small C or asm function in runtime to do that.
 

and it's unclear (to me) how that would interact with segmented stacks
in Go. You'll have to write some bridge function.

Yes, you could write something small in C or asm just to get things started and do everything else in a different Go thread. 

Having implemented a windows service once, I don't recommend it at
all.

I have implemented and use service programs. There are some restrictions to what you can do with them, but there are some important advantages too: they don't require user login and will start at computer startup automatically, they have access to all local resources on computer but don't require user logon. Most "server" type programs, like web, mail, database servers are perfect candidates for a windows service.
 

Also, as far as I know, Go doesn't have cross-platform support for
file changes notifications (inotify/ReadDirectoryChanges()).

Correct, not existent at the moment.

Alex

Paulo Pinto

unread,
Oct 6, 2011, 1:59:06 AM10/6/11
to golang-nuts
Well you might try to use to use sc.exe instead.

http://support.microsoft.com/kb/251192

It allows normal programs to run as services. But be aware
that you won't have access to the service API and the actions
invoked by the services control panel.

--
Paulo

Guillermo Estrada

unread,
Oct 18, 2012, 4:11:30 PM10/18/12
to golan...@googlegroups.com, Nathan Trimble, brad...@golang.org
There's even a library now to do system tray icons on Windows to say "hey user, I'm running.  click here to launch your web browser to localhost:8080 and see my pretty web UI."

Does someone happen to know the name of this library? I am very interested in using it. 

Ken Allen

unread,
Oct 20, 2012, 5:30:22 PM10/20/12
to golan...@googlegroups.com, nathan....@gmail.com
For implementing windows services there's this: http://code.google.com/p/winsvc/ but I've not used it.

Ken Allen

unread,
Oct 20, 2012, 5:34:56 PM10/20/12
to golan...@googlegroups.com, Nathan Trimble, brad...@golang.org
Haha woops, I just noticed the date of the original post. I suppose my other reply is probably not needed.

Anyway, https://github.com/lxn/walk can do what you want.
Reply all
Reply to author
Forward
0 new messages