Subversion Windows service configuration

Source: Internet
Author: User
Versions later than Subversion 1.4 integrate tools that support Windows Services.
Let's take a look at a related article (from http://svn.collab.net/repos/svn/tags/1.4.0/notes/windows-service.txt ):

Windows Service Support for svnserve
==========================================

Svnserve can now be run as a native Windows service. This means that
Service can be started at system boot, or at any other time, without
Need for any wrapper code to start the service. The service can be managed
Like any other Windows service, using command-line tools ("net start ",
"Net stop", or SC .exe) or GUI tools (the Services administrative tool ).


Installation
------------

For now, no means is provided to install the service. Most Windows
OSes derived from Windows NT (such as Windows XP, Windows 2000,
Windows 2003 Server) provide a command-line tool for installing
Services, called SC. EXE for "Service Control". To create a service
Svnserve, use SC. EXE:

SC create <name>
Binpath = "c: \ svn \ bin \ svnserve.exe -- service <svn-args>"
Displayname = "Subversion Repository"
Depend = Tcpip
Where <name> is any service name you want, e.g. "svnserve", and
<Svn-args> are the arguments to svnserve, such as -- root,
-- Listen-port, etc. (All of this shoshould be specified on a single
Line, of course .)

In order for svnserve to run as a Windows service, you MUST specify
The -- service argument, and you must NOT specify any other run mode
Argument, such as -- daemon, -- tunnel, -- inetd, or any of their short
Forms. There is no short form for -- service.

If the path to svnserve.exe contains spaces or other characters that
Must be escaped, then you must enclose the path to svnserve.exe
Double-quotes, which themselves must be quoted using a backslash.
Fortunately the syntax is similar to that on Unix platforms:

SC create <name>
Binpath = "\" c: \ program files \ subversion \ bin \ svnserve.exe \"..."

SC has alias options; use "SC /? ". The most relevant are:

SC create <name> create a new service
SC qc <name> query config for a service
SC query <name> query status
SC delete <name> delete any service -- BE CAREFUL!
SC config <name>... update service config; same args as SC create
SC start <name> start a service (does NOT wait for completion !)
SC stop <name> stop a service (does NOT wait for it to stop !)

Note that the command-line syntax for SC is rather odd. Key/value
Pairs are specified as "key = value" (without the double-quotes).
"Key =" part must not have any spaces, and the "value" part MUST be
Separated from the "key =" by a space.

If you want to be able to see the command shell, add these arguments
To the "SC create" command-line:

Type = own type = interact

This sets the "interactive" bit on the service, which allows it
Interact with the local console session.

You can create as your services as you need; there is no restriction
On the number of services, or their names. I use a prefix, like
"Svn. foo", "svn. bar", etc. Each service runs in a separate process.
As usual, it is your responsbility as an administrator to make sure
That no two service instances use the same repository root path, or
The same combination of -- listen-port and -- listen-host.


Uninstalling
------------

To uninstall a service, stop the service, then delete it, using "SC
Delete <name> ". Be very careful with this command, since you can
Delete any system service, including essential Windows services,
Accidentally.

Also, make sure that you stop the service before you delete it. If
You delete the service before stopping it, the Service Control Manager
Will mark the service "deleted", but will intentionally not stop
Service. The service will be deleted when the system reboots, or when
The service finally exits. After all, you only asked to delete
Service, not to stop it.

That's all there is to it.


Automatically Starting Service on System Boot
---------------------------------------------

By default, SC creates the service with the start mode set to "demand"
(Manual). If you want the service to start automatically when
System boots, add "start = auto" to the command line. You can change
The start mode for an existing service using "SC config <name> start =
Auto ", or also by using the Windows GUI interface for managing
Services. (Start, All Programs, Administrative Tools, Services, or
Just run "services. msc" from Start/Run or from a command-line .)

Note: In order for svnserve to start correctly on system boot, you
Must properly declare its startup dependencies. The Service Control
Manager will start services as early as it can, and if you do not
Properly declare its startup dependencies, it can potentially start
Before the TCP/IP stack has been started. This is why you must
Provide specify 'depend = tcpip' to SC. EXE when creating the service.


Starting and Stopping the Service
---------------------------------

You start and stop the service like any other Windows service. You
Can use the command-line "net start <name>", use the GUI Services
Interface.


Debugging
---------

Debugging a Windows service can be difficult, because the service runs
In a very different context than a user who is logged in. By default,
Services run in a "null" desktop environment. They cannot interact
With the user (desktop) in any way, and vice versa.

Also, by default, services run as a special user, called LocalSystem.
LocalSystem is not a "user" in the normal sense; it is an NT security
ID (SID) that is sort of like root, but different. LocalSystem
Typically does NOT have access to any network shares, even if you use
"Net use" to connect to a remote file server. Again, this is because
Services run in a different login session.

Depending on which OS you are running, you may have difficulty
Attaching a debugger to a running service process. Also, if you are
Having trouble * starting * a service, then you can't attach to
Process early enough to debug it.

So what's a developer to do? Well, there are several ways you can
Debug services. First, you'll want to enable "interactive" access
The service. This allows the service to interact with the local
Desktop -- you'll be able to see the command shell that the service
Runs in, see console output, etc. To do this, you can either use
Standard Windows Services tool (services. msc), or you can do it using
SC .exe.

* With the GUI tool, open the properties page for a service, and go
To the "Log On" page. Select "Local System account", and make
Sure the "Allow service to interact with desktop" box is checked.

* With SC. EXE, configure the service using the command:

SC <name> config type = own type = interact

Yes, you must specify type = twice, and with exactly the spacing
Shown.

In both cases, you'll need to restart the service. When you do, if
The service started successfully, you'll see the console window of
Service. By default, it doesn' t print anything out.

Next, you'll want to attach a debugger, or configure the service
Start under a debugger. Attaching a debugger shocould be
Straightforward -- just find the process ID. But if you need to debug
Something in the service startup path, you'll need to have a debugger
Attached from the very beginning. There are two ways to do this.

In the first method, you alter the command-line of the service (called
The "binary path"). To do this, use SC. EXE to set the binary path
Whatever debugger you are going to use. I use the most recent version
Of WinDbg, which is excellent, and is available:

Http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx

For example, this command wocould configure the service to start under
Debugger:

SC config <name> binpath = "d: \ dbg \ windbg.exe-g-G d: \ svn \ bin \ svnserve.exe
-- Root d: \ path \ root -- listen-port 9000"
Depend = Tcpip

The entire command must be on a single line, of course, and the binary
Path must be in double-quotes. Also, the spacing MUST be: binpath = "..."

Substitute whatever debugger you want, with whatever command-line you
Want, in place of windbg.exe. Then start the service (SC start
<Name>), and the Service Control Manager shocould execute
Command-line you provided as the binary path. Then your debugger
Shocould start, and shocould launch the svnserve process.


Known Issues
------------

* No management tool (installer, etc.). For the first version, this
Is intentional; we just want to get the service functionality tested
And committed before dealing with installation.

* Right now, I don't know of a way to cleanly stop the svnserve
Process. Instead, the implementation closes the listen socket,
Which causes the main loop to exit. This isn't as bad as it sounds,
And is a LOT better than other options (such as terminating
Thread ).


To Do
-----

* The support for running svnserve as a Windows service is complete,
But there is still more work to be done for installing and managing
Services.

According to the above, to configure the subversion as a Windows Service, the process is quite simple:

In Windows NT (including Windows XP, Windows 2000, and Windows 2003 Server), a tool for installing services is included, which is called "Service Control" and also supports SC .exe.

For example, if my Subversion (Latest Version 1.4.6) is installed in "C: \ Program Files \ Subversion", the version library is in "E: \ SVN ", I want the corresponding Subversion service named SVNService. The command for installing this svn service can be written as follows: SC create SVNService binPath = "\" C: \ Program Files \ Subversion \ bin \ svnserve.exe \ "-- service-rE: \ SVN" DisplayName = "SVNService" depend = Tcpip start = auto (enter a line)
The result is as follows:

Net start/stop is to start/Close the service.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.