25
TOPSHELF - AN EASY SERVICE HOSTING FRAMEWORK FOR BUILDING WINDOWS SERVICES USING .NET Larry Nung

Topshelf - An easy service hosting framework for building Windows services using .NET

Embed Size (px)

Citation preview

Page 1: Topshelf - An easy service hosting framework for building Windows services using .NET

TOPSHELF - AN EASY SERVICE HOSTING FRAMEWORK FOR

BUILDING WINDOWS SERVICES USING .NET

Larry Nung

Page 2: Topshelf - An easy service hosting framework for building Windows services using .NET

AGENDAIntroductionGetting startedCustom ServiceCommand-LineReferenceQ & A

2

Page 3: Topshelf - An easy service hosting framework for building Windows services using .NET

INTRODUCTION3

Page 4: Topshelf - An easy service hosting framework for building Windows services using .NET

INTRODUCTION Put Your Apps on the Topshelf An easy service hosting framework for

building Windows services using .NET

4

Page 5: Topshelf - An easy service hosting framework for building Windows services using .NET

GETTING STARTED5

Page 6: Topshelf - An easy service hosting framework for building Windows services using .NET

GETTING STARTED

6

Page 7: Topshelf - An easy service hosting framework for building Windows services using .NET

GETTING STARTED

7

Page 8: Topshelf - An easy service hosting framework for building Windows services using .NET

GETTING STARTEDusing System; using Topshelf;…class Program { static void Main(string[] args) { HostFactory.Run(x => { x.Service<Program>(s => { s.ConstructUsing(name => new Program()); s.WhenStarted(p => p.Start()); s.WhenStopped(p => p.Stop()); }); }); }

public void Start() { Console.WriteLine("Service start..."); }

public void Stop() { Console.WriteLine("Service stop..."); }}

8

Page 9: Topshelf - An easy service hosting framework for building Windows services using .NET

GETTING STARTED

9

Page 10: Topshelf - An easy service hosting framework for building Windows services using .NET

CUSTOM SERVICE10

Page 11: Topshelf - An easy service hosting framework for building Windows services using .NET

CUSTOM SERVICEusing System; using Topshelf;... class Program { static void Main(string[] args) { HostFactory.Run(x => { x.Service<ProgramService>(); }); } } class ProgramService : ServiceControl { public bool Start(HostControl hostControl) { Console.WriteLine("Service start..."); return true; } public bool Stop(HostControl hostControl) { Console.WriteLine("Service stop..."); return true; } } ...

11

Page 12: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE12

Page 13: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE service.exe [verb] [-option:value] [-switch]

run Runs the service from the command line (default) help, --help Displays help install Installs the service

--autostart The service should start automatically (default) --disabled The service should be set to disabled --manual The service should be started manually --delayed The service should start automatically (delayed) -instance An instance name if registering the service multiple times -username The username to run the service -password The password for the specified username --localsystem Run the service with the local system account --localservice Run the service with the local service account --networkservice Run the service with the network service permission --interactive The service will prompt the user at installation for the service credentials

13

Page 14: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINEstart Start the service after it has been installed --sudo Prompts for UAC if running on Vista/W7/2008

-servicename The name that the service should use when installing -description The service description the service should use when installing -displayname The display name the the service should use when installing

start Starts the service if it is not already running stop Stops the service if it is running

uninstall Uninstalls the service

-instance An instance name if registering the service multiple times --sudo Prompts for UAC if running on Vista/W7/2008

14

Page 15: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINEExamples:

service install Installs the service into the service control manager

service install -username:joe -password:bob --autostart Installs the service using the specified username/password and configures the service to start automatically at machine startup

service uninstall Uninstalls the service

service install -instance:001 Installs the service, appending the instance name to the service

name so that the service can be installed multiple times. You may need to tweak the log4net.config to make this play nicely with the log files.

15

Page 16: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

16

Page 17: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

17

Page 18: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

18

Page 19: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

19

Page 20: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

20

Page 21: Topshelf - An easy service hosting framework for building Windows services using .NET

COMMAND-LINE

21

Page 22: Topshelf - An easy service hosting framework for building Windows services using .NET

REFERENCE22

Page 23: Topshelf - An easy service hosting framework for building Windows services using .NET

REFERENCE Topshelf

http://topshelf-project.com/

Welcome to Topshelf’s documentation! — Topshelf 3.0 documentation https://

topshelf.readthedocs.io/en/latest/index.html

Topshelf/Topshelf: An easy service hosting framework for building Windows services using .NET https://github.com/Topshelf/Topshelf

23

Page 24: Topshelf - An easy service hosting framework for building Windows services using .NET

Q&A24

Page 25: Topshelf - An easy service hosting framework for building Windows services using .NET

QUESTION & ANSWER

25