Coder Social home page Coder Social logo

go-windows-svc's Introduction

GO Windows Service Shell

This is based on the GO Windows service example program provided by the GO Project. It is a project shell to create a Windows service.

Getting Started

The program compiles and runs on GO 1.8. The generated executable accepts a single parameter. The parameter values include:

  • debug - runs the program from the command-line
  • install - installs a windows service
  • remove - removes the windows service
  • start
  • stop
  • pause
  • continue

Installing and Updating a Service

After compiling an executable, the service can be installed from an Administrative command prompt. Typing

YourExecutable.EXE install 

will install the service.

To update the service, stop the service, replace the executble and restart the service.

The service can be removed from an Administrative command prompt by typing:

YourExecutable.EXE remove 

Customizing

The code exists in two packabages

  • cmd/gosvc - Wrapper to control the service
  • app - Your application

All service boilerplate code is in the four files in cmd/gosvc with a "svc_" prefix. There should be no need to modify this code.

The only code you should need to change is in main.go.

  • Replace the import of github.com/billgraziano/go-windows-svc/app with the path to your package.
  • svcName - This constant is the name of the installed service. This is used for NET START and NET STOP commands.
  • svcNameLong - This is the longer service name that appears in the Services control panel.
  • svcLauncher() - This launches app.Run passing it a Windows Event Logger, the svcName, and the SHA1 hash from GIT.

You should also rename the gosvc directory to the name of your executable.

  • setup() - This function is called to do any application setup. If returns a non-nil error, the service will exit.
  • yourApp() - This is launched as a GO routine. This is the body of your application. Here you can launch web servers, listeners, or whatever your application does.

Advanced

Logging

The server struct exposes a winlog variable that is a logger. This will write to the console when running interactively and to the Winodws Application Event Log when running as a service. I typically use this for any service errors, start and stop notification, and any issues reading configuration or setting up logging.

Other

This uses the GO error wrapper package. You can easily remove it if you prefer not to use it.

go-windows-svc's People

Contributors

billgraziano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-windows-svc's Issues

Improve structure

Maybe create a winsvc struct. This would have

  • service name values
  • method to write to the application log
  • Interactive (bool)

This could be passed in to setup and yourapp.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.