Service type of application runs in background
Introduction
Service type of application runs as a Service on Windows, Linux and Mac OS.
This type of generated exe cannot be excuted directly on Windows. If it is executed directly on Linux, Mac OS, it will go into daemon status. To run as a normal Service, you need to "/install" it first.
Install & Uninstall
You need to "/install" it first before Service type of generated exe can run as a Service. You need a Administrator privilege to install a service. For example:
YourProgram /install auto
The 'auto' is to let service automatically start up when System starts up.
Service Arguments [since 2.0.4]
From v2.0.4, the service type of application supports to add fixed arguments to programs, both Windows, Linux and Mac OS supported:
YourProgram /install auto arg1 arg2
After successful "/install", you can find the service in service manager, "services.msc" on Windows, "ntsysv" on Linux, "launchctl" on Mac OS etc. The service program will keep running after user logs out. You can also control the service start and stop through command line. On Windows:
net stop YourServiceName
On Linux:
service YourProgram stop
On Mac OS:
sudo launchctl start YourProgram
Use "/uninstall" to uninstall the service from System. You'd better stop the service first before uninstall it.
YourProgram /uninstall
About the ServiceName
For Service type on Windows, the ServiceName is specified during generating, see Step 3: Main Java Class page.
For Service type on Linux and Mac OS, the ServiceName is the Program file name.
Test
For debug use, you can run your Service type of generated exe as Console type by a "/test" parameter.
YourProgram /test
forcecwd
The current working directory of Service type is set to the "applicaton.home" by default, where the exe file is. You can use a 'forcecwd' configure item to specify a new position with a relative path or absolute path.
- See forcecwd page for details of current working directory configuration.
stderr
By default, the System.err of Service type is redirect to a disk file. You can use a 'stderr' configure item to overwrite it.
- See stdout, stderr page for details of stdout redirection.
See Also
- Service Integration - Integration with Service for Service Stop Event.
- Hello Service - Demo program of Service type.
Add new comment