Official Github ; official download address . It is difficult to download without Git acceleration. Let me share the latest stable version of v2.12.0
the network disk connection with the release date of 2023.01.29.
Included files:
- WinSW-x64.exe
- sample-minimal.xml
- sample-allOptions.xml
Link: https://pan.baidu.com/s/1sN3hL5HvFzzNwuz8npaQNw
Extraction code: vsvg
Why register as a service: The service can restart itself after the server is restarted.
WinSW official website usage instructions and example sharing
1. Instructions for use on the official website
1.1 Configuration instructions for use
Use WinSW as a global tool
- Take WinSW.exe or WinSW.zip from the distribution.
- Write myapp.xml (see the XML config file specification and samples for more details).
- Run winsw install myapp.xml [options] to install the service.
- Run winsw start myapp.xml to start the service.
- Run winsw status myapp.xml to see if your service is up and running.
Used as a global tool, different services use different xml files for operations.
Use WinSW as a bundled tool
- Take WinSW.exe or WinSW.zip from the distribution, and rename the .exe to your taste (such as myapp.exe).
- Write myapp.xml (see the XML config file specification and samples for more details).
- Place those two files side by side, because that’s how WinSW discovers its co-related configuration.
- Run myapp.exe install [options] to install the service.
- Run myapp.exe start to start the service.
When used as a binding tool, the xml file with the same name is used by default for operation. I personally feel that this method is more suitable for implementation partners.
Sample configuration file
You write the configuration file that defines your service. The example below is a primitive example being used in the Jenkins project:
<service>
<id>jenkins</id>
<name>Jenkins</name>
<description>This service runs Jenkins continuous integration system.</description>
<env name="JENKINS_HOME" value="%BASE%"/>
<executable>java</executable>
<arguments>-Xrs -Xmx256m -jar "%BASE%\jenkins.war" --httpPort=8080</arguments>
<log mode="roll"></log>
</service>
The full specification of the configuration file is available here . You can find more samples here .
This configuration file example is a typical executable file + parameters, suitable for many services.
1.2 Usage
WinSW is being managed by the XML configuration file.
Your renamed WinSW.exe binary also accepts the following commands:
Command | Description |
---|---|
install | Installs the service. |
uninstall | Uninstalls the service. |
start | Starts the service. |
stop | Stops the service. |
restart | Stops and then starts the service. |
status | Checks the status of the service. |
refresh | Refreshes the service properties without reinstallation. |
customize | Customizes the wrapper executable. |
dev | Experimental commands. |
Experimental commands:
Command | Description |
---|---|
dev ps | Draws the process tree associated with the service. |
dev kill | Terminates the service if it has stopped responding. |
dev list | Lists services managed by the current executable. |
Most commands require Administrator privileges to execute. WinSW will prompt for UAC in non-elevated sessions.
These commands will not be explained in detail and will be introduced when used.
2.Example sharing
2.1 Register the exe as a service
Here we use object storage MinIO minio.exe
as Use WinSW as a bundled tool
an example. The detailed steps are as follows:
- will be
WinSW-x64.exe
renamed tominio-server.ext
- The content of the added configuration file
minio-server.xim
is as follows, and the configuration details can be viewedsample-allOptions.xml
<service>
<id>minio-server</id>
<name>MinIO-Server</name>
<description>This service runs MINIO OBJECT STORE.</description>
<env name="MINIO_HOME" value="%BASE%"/>
<executable>%BASE%\minio.exe</executable>
<arguments>server D:\minio_data --console-address ":9001"</arguments>
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-size-time">
<sizeThreshold>1024</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:00:00</autoRollAtTime>
<zipOlderThanNumDays>5</zipOlderThanNumDays>
<zipDateFormat>yyyyMMdd</zipDateFormat>
</log>
<env name="MINIO_ROOT_USER" value="admin" />
<env name="MINIO_ROOT_PASSWORD" value="admin123" />
</service>
cmd
Execute the commandminio-server.exe install
to install it as a service (the service is not started at this time)
INFO - Installing service 'MinIO-Server (minio-server)'...
INFO - Service 'MinIO-Server (minio-server)' was installed successfully.
- Execute the command
minio-server.exe start
to start the service
Complete process test:
2.2 Register jar as a service
math-game.jar
Here we use Arthas (Alsace) package for testing Use WinSW as a bundled tool
as an example. The detailed steps are as follows:
- will be
WinSW-x64.exe
renamed tomath-game-server.exe
- Add the configuration file
math-game-server.xml
content as follows
<service>
<id>math-game-server</id>
<name>Math-Game-Server</name>
<description>This service runs math-game server.</description>
<env name="MATHGAME_HOME" value="%BASE%"/>
<executable>java</executable>
<arguments>-Xrs -Xmx128m -jar "%BASE%\math-game.jar"</arguments>
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-size-time">
<sizeThreshold>1024</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:00:00</autoRollAtTime>
<zipOlderThanNumDays>5</zipOlderThanNumDays>
<zipDateFormat>yyyyMMdd</zipDateFormat>
</log>
</service>
The -Xrs parameter is short for "Reduce Signal Usage", which tells the JVM to reduce the use of operating system signals. Normally, the JVM captures some operating system signals, such as SIGTERM (termination signal) and SIGINT (interrupt signal), to gracefully shut down the Java process. However, with the -Xrs parameter, the JVM will minimize the use of these signals and instead rely on Java code to handle the shutdown operation. This can improve the stability of the JVM in certain situations.
cmd
Execute the commandmath-game-server.exe install
to install it as a service (the service is not started at this time and the status is: stopped)
INFO - Installing service 'Math-Game-Server (math-game-server)'...
INFO - Service 'Math-Game-Server (math-game-server)' was installed successfully.
- Execute the command
minio-server.exe start
to start the service
Log printed after startup:
Like the exe, only part of the test is done here:
3. Summary
WinSW (Windows Service Wrapper) is an open source project that allows any executable file (usually .NET application, exe application, Java JAR file, etc.) to be converted into a Windows service. The goal of WinSW is to make it easier to run non-Windows services on Windows operating systems. It provides a way to wrap applications as Windows services, allowing you to start, stop, pause, and resume applications as services.
The following are the main features and uses of WinSW:
- Application packaging as services : WinSW allows you to wrap various types of applications as Windows services without modifying the application code. This is useful for deploying regular applications as services.
- Simplified management : Once an application is wrapped as a service, you can manage it using Windows Service Manager or command line tools such as
sc
command. This makes deploying and managing applications on Windows more convenient. - Custom configuration : WinSW allows you to customize the behavior of the service through XML or YAML configuration files, including service name, description, working directory, startup parameters, etc. This allows you to flexibly configure the service to suit different needs.