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

Preview:

Citation preview

TOPSHELF - AN EASY SERVICE HOSTING FRAMEWORK FOR

BUILDING WINDOWS SERVICES USING .NET

Larry Nung

AGENDAIntroductionGetting startedCustom ServiceCommand-LineReferenceQ & A

2

INTRODUCTION3

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

building Windows services using .NET

4

GETTING STARTED5

GETTING STARTED

6

GETTING STARTED

7

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

GETTING STARTED

9

CUSTOM SERVICE10

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

COMMAND-LINE12

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

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

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

COMMAND-LINE

16

COMMAND-LINE

17

COMMAND-LINE

18

COMMAND-LINE

19

COMMAND-LINE

20

COMMAND-LINE

21

REFERENCE22

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

Q&A24

QUESTION & ANSWER

25

Recommended