source: valtobtest/subversion-1.6.2/notes/windows-service.txt @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

File size: 8.6 KB
Line 
1Windows Service Support for svnserve
2====================================
3
4svnserve can now be run as a native Windows service.  This means that the
5service can be started at system boot, or at any other time, without the
6need for any wrapper code to start the service.  The service can be managed
7like any other Windows service, using command-line tools ("net start",
8"net stop", or sc.exe) or GUI tools (the Services administrative tool).
9
10
11Installation
12------------
13
14For now, no means is provided to install the service.  Most Windows
15OSes derived from Windows NT (such as Windows XP, Windows 2000,
16Windows 2003 Server) provide a command-line tool for installing
17services, called SC.EXE for "Service Control". To create a service for
18svnserve, use SC.EXE:
19
20   sc create <name>
21      binpath= "c:\svn\bin\svnserve.exe --service <svn-args>"
22      displayname= "Subversion Repository"
23      depend= Tcpip
24
25where <name> is any service name you want, e.g. "svnserve", and
26<svn-args> are the arguments to svnserve, such as --root,
27--listen-port, etc.  (All of this should be specified on a single
28line, of course.)
29
30In order for svnserve to run as a Windows service, you MUST specify
31the --service argument, and you must NOT specify any other run mode
32argument, such as --daemon, --tunnel, --inetd, or any of their short
33forms.  There is no short form for --service.
34
35If the path to svnserve.exe contains spaces or other characters that
36must be escaped, then you must enclose the path to svnserve.exe with
37double-quotes, which themselves must be quoted using a backslash.
38Fortunately the syntax is similar to that on Unix platforms:
39
40   sc create <name>
41      binpath= "\"c:\program files\subversion\bin\svnserve.exe\" ..."
42
43SC has many options; use "sc /?".  The most relevant are:
44
45   sc create <name>     create a new service
46   sc qc <name>         query config for a service
47   sc query <name>      query status
48   sc delete <name>     delete any service -- BE CAREFUL!
49   sc config <name> ... update service config; same args as sc create
50   sc start <name>      start a service (does NOT wait for completion!)
51   sc stop <name>       stop a service (does NOT wait for it to stop!)
52
53Note that the command-line syntax for SC is rather odd.  Key/value
54pairs are specified as "key= value" (without the double-quotes).  The
55"key=" part must not have any spaces, and the "value" part MUST be
56separated from the "key=" by a space.
57
58If you want to be able to see the command shell, add these arguments
59to the "sc create" command-line:
60
61   type= own type= interact
62
63This sets the "interactive" bit on the service, which allows it to
64interact with the local console session.
65
66You can create as many services as you need; there is no restriction
67on the number of services, or their names.  I use a prefix, like
68"svn.foo", "svn.bar", etc.  Each service runs in a separate process.
69As usual, it is your responsbility as an administrator to make sure
70that no two service instances use the same repository root path, or
71the same combination of --listen-port and --listen-host.
72
73
74Uninstalling
75------------
76
77To uninstall a service, stop the service, then delete it, using "sc
78delete <name>".  Be very careful with this command, since you can
79delete any system service, including essential Windows services,
80accidentally.
81
82Also, make sure that you stop the service before you delete it.  If
83you delete the service before stopping it, the Service Control Manager
84will mark the service "deleted", but will intentionally not stop the
85service.  The service will be deleted when the system reboots, or when
86the service finally exits.  After all, you only asked to delete the
87service, not to stop it.
88
89That's all there is to it.
90
91
92Automatically Starting Service on System Boot
93---------------------------------------------
94
95By default, SC creates the service with the start mode set to "demand"
96(manual).  If you want the service to start automatically when the
97system boots, add "start= auto" to the command line.  You can change
98the start mode for an existing service using "sc config <name> start=
99auto", or also by using the Windows GUI interface for managing
100services.  (Start, All Programs, Administrative Tools, Services, or
101just run "services.msc" from Start/Run or from a command-line.)
102
103Note: In order for svnserve to start correctly on system boot, you
104must properly declare its startup dependencies.  The Service Control
105Manager will start services as early as it can, and if you do not
106properly declare its startup dependencies, it can potentially start
107before the TCP/IP stack has been started.  This is why you must
108provide specify 'depend= Tcpip' to SC.EXE when creating the service.
109
110
111Starting and Stopping the Service
112---------------------------------
113
114You start and stop the service like any other Windows service.  You
115can use the command-line "net start <name>", use the GUI Services
116interface.
117
118
119Debugging
120---------
121
122Debugging a Windows service can be difficult, because the service runs
123in a very different context than a user who is logged in.  By default,
124services run in a "null" desktop environment.  They cannot interact
125with the user (desktop) in any way, and vice versa.
126
127Also, by default, services run as a special user, called LocalSystem.
128LocalSystem is not a "user" in the normal sense; it is an NT security
129ID (SID) that is sort of like root, but different.  LocalSystem
130typically does NOT have access to any network shares, even if you use
131"net use" to connect to a remote file server.  Again, this is because
132services run in a different login session.
133
134Depending on which OS you are running, you may have difficulty
135attaching a debugger to a running service process.  Also, if you are
136having trouble *starting* a service, then you can't attach to the
137process early enough to debug it.
138
139So what's a developer to do?  Well, there are several ways you can
140debug services.  First, you'll want to enable "interactive" access for
141the service.  This allows the service to interact with the local
142desktop -- you'll be able to see the command shell that the service
143runs in, see console output, etc.  To do this, you can either use the
144standard Windows Services tool (services.msc), or you can do it using
145sc.exe.
146
147   * With the GUI tool, open the properties page for a service, and go
148     to the "Log On" page.  Select "Local System account", and make
149     sure the "Allow service to interact with desktop" box is checked.
150
151   * With SC.EXE, configure the service using the command:
152
153         sc <name> config type= own type= interact
154
155     Yes, you must specify type= twice, and with exactly the spacing
156     shown.
157
158In both cases, you'll need to restart the service.  When you do, if
159the service started successfully, you'll see the console window of the
160service.  By default, it doesn't print anything out.
161
162Next, you'll want to attach a debugger, or configure the service to
163start under a debugger.  Attaching a debugger should be
164straightforward -- just find the process ID.  But if you need to debug
165something in the service startup path, you'll need to have a debugger
166attached from the very beginning.  There are two ways to do this.
167
168In the first method, you alter the command-line of the service (called
169the "binary path").  To do this, use SC.EXE to set the binary path to
170whatever debugger you are going to use.  I use the most recent version
171of WinDbg, which is excellent, and is available at:
172
173   http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx
174
175For example, this command would configure the service to start under a
176debugger:
177
178   sc config <name> binpath= "d:\dbg\windbg.exe -g -G d:\svn\bin\svnserve.exe
179      --root d:\path\root --listen-port 9000"
180      depend= Tcpip
181
182The entire command must be on a single line, of course, and the binary
183path must be in double-quotes.  Also, the spacing MUST be: binpath= "..."
184
185Substitute whatever debugger you want, with whatever command-line you
186want, in place of windbg.exe.  Then start the service (sc start
187<name>), and the Service Control Manager should execute the
188command-line you provided as the binary path.  Then your debugger
189should start, and should launch the svnserve process.
190
191
192Known Issues
193------------
194
195* No management tool (installer, etc.).  For the first version, this
196  is intentional; we just want to get the service functionality tested
197  and committed before dealing with installation.
198
199* Right now, I don't know of a way to cleanly stop the svnserve
200  process.  Instead, the implementation closes the listen socket,
201  which causes the main loop to exit.  This isn't as bad as it sounds,
202  and is a LOT better than other options (such as terminating a
203  thread).
204
205
206To Do
207-----
208
209* The support for running svnserve as a Windows service is complete,
210  but there is still more work to be done for installing and managing
211  services.
Note: See TracBrowser for help on using the repository browser.