windows-service.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 12 Jan 2015 23:04:42 +0200
changeset 1672 7a489de6fb71
parent 1671 ee48c908b156
child 1673 ed7fa7e54aaa
permissions -rw-r--r--
Service wrapper.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
.. include:: HEADER.rst
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
==================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
 Windows service.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
==================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
.. contents::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
List services.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
==============
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
List of all running services::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
  cmd> net start
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
List of all services::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
  cmd> sc query
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
List of specific service::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
  cmd> sc query NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    24
GUI tool::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    25
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    26
  cmd> services.msc
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    27
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
Start/stop service.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
===================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
  cmd> net start NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
  cmd> sc start NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
  cmd> net stop NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
  cmd> sc stop NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    38
  cmd> services.msc
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    40
Create service.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    41
===============
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    42
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    43
In order to create service from any executable use ``srvany.exe`` from Windows
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    44
Resource Kits 2003 (take attention to spaces after ``=``)::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    45
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    46
  cmd> sc create NAME binPath= "c:\Program Files\Windows Resource Kits\Tools\srvany.exe" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    47
       type= own start= auto error= normal DisplayName= "NAME for services.msc"
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    48
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    49
Then pass what ``srvany.exe`` wrapper to do::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    50
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    51
  cmd> reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NAME\Parameters" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    52
     /v "Application" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    53
     /d "\"c:\Program Files\Java\jre7\bin\java.exe\" -cp c:\home\devel\service Main"
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    54
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    55
Above you see quoting syntax for spaces and quotes. Next start service with::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    56
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    57
  cmd> sc start NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    58
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    59
If you make error recheck your settings with::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    60
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    61
  cmd> reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NAME" /s
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    62
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    63
Or remove service and make steps again::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    64
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    65
  cmd> sc delete NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    66
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    67
Visit GUI ``services.msc`` and check with ``procexp.exe`` that service actually
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    68
do job.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    69
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    70
  http://www.microsoft.com/en-us/download/confirmation.aspx?id=17657
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    71
    Windows Server 2003 Resource Kit Tools download.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    72
  http://stackoverflow.com/questions/3663331/creating-a-service-with-sc-exe-how-to-pass-in-context-parameters
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    73
    How to pass parameters to sc.exe runnable.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    74
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    75
Delete service.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    76
===============
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    77
::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    78
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    79
  cmd> sc delete NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    80
1672
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    81
Service wrapper.
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    82
================
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    83
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    84
  http://en.wikipedia.org/wiki/Service_wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    85
    Service wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    86
  http://nssm.cc/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    87
    NSSM - the Non-Sucking Service Manager
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    88
  http://sourceforge.net/projects/yajsw/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    89
    Yet Another Java Service Wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    90
  https://github.com/kohsuke/winsw/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    91
    A wrapper executable that can be used to host any executable as an Windows
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    92
    service
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    93
  http://code.google.com/p/simple-service-wrapper/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    94
    Simple Windows Service Wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    95