I've been looking at different articles, examples for hours and have successfully completely confused myself. I am trying to use YAJSW as a service wrapper and install my Executable JAR file as a windows service. I used to use Tanukisoft's community edition wrapper and it worked wonderfully, but the 64-bit Windows version isn't available in CE.
I suppose I have a few questions.
In the old software, I didn't need to Implement WrapperListener. Is this necessary for YAJSW?
If so, are there any good examples? I've seen a few, but my application doesn't return anything from the main class. It's main class is a constant running URL connection reading input from a REST API and spawning a thread to process the information received. It does have a shutdown hook for a clean exit.
Is there an easy way to translate Tanukis' configuration (below) into YAJSW's keeping the same functionality?
set.JAVA_HOME=C:/Program Files/Java/jre1.8.0_181
set.APP_HOME=G:/ProgFolder
wrapper.lang.folder=%APP_HOME%/lang
wrapper.java.command=java
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
#wrapper.java.classpath.1=../lib/wrappertest.jar
wrapper.java.classpath.1=%APP_HOME%/lib/wrapper.jar
wrapper.java.classpath.2=%APP_HOME%/RESTReader.jar
wrapper.java.classpath.3=%APP_HOME%/lib/javax.mail.jar
wrapper.java.classpath.4=%APP_HOME%
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=%APP_HOME%/lib
# Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE
# Java Additional Parameters
wrapper.java.additional.1=-Dlog4j.configurationFile=file:/%APP_HOME%/conf/log4j2.xml
wrapper.java.additional.2=-Dorg.tanukisoftware.wrapper.WrapperSimpleApp.waitForStartMain=FALSE
# Application parameters. Add parameters as needed starting from 1
#wrapper.app.parameter.1=
wrapper.app.parameter.1=com.my.org.RESTReader.EventReg
wrapper.jvm_exit.timeout=120
wrapper.shutdown.timeout=120
# Name of the service
wrapper.name=RESTReader
# Display name of the service
wrapper.displayname=REST Alarm Manager
# Description of the service
wrapper.description=REST Alarm Manager
# Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_START
wrapper.ntservice.starttype=DELAY_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
First Time Install (i.e. no existing service installed on host)
build executable jar file for your app
copy jar file to target windows machine / target directory
copy yajsw.zip to target machine / target directory
On target windows machine / target directory:
Unzip contents of yajsw.zip. Once this is completed, the yajsw.zip file can be deleted.
Open Windows command prompt in target machine / target directory and run: java -jar yourExecutableJar.jar
Get Process ID for the java process that you just started using Windows Task Manager.
Open new command window at target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat.
Run as admin
genConfig [processId]
where processID is the one you determined before
Stop java process started previously
Open wrapper.conf in target-dir\yajsw\yajsw-stable-majorversion.minorversion\conf
Edit the fields in wrapper.conf: wrapper.ntservice.name=YourServiceName;
wrapper.ntservice.displayname=YourServiceDisplayName;wrapper.ntservice.description=YourServiceDescription
Save your changes and close wrapper.conf
Run as admin
installService in target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat
Run as admin
startService in target-dir\yajsw\yajsw-stable-majorversion.minorversion\bat
Update Instructions
Stop the service using Windows Task Manager or Services Manager
In installed directory, delete the existing jar file for the project
copy new jar file to installed directory
Restart the service.
Related
Basically I would like to record the application events(JFR data) running on docker from my current system JMC.
Steps followed:
Enabled JFR port on my docker service.
Verified whether I'm able to access the docker service's JMS port from my current system and it is working perfectly.
when I tried to record the application event from JMC application, I'm getting proper data on dump but when I tried to do the same using command line options, I'm not getting the proper dump.
As part of project, we do have a batch file which internally calls the application event. I've created a local jar file which will call the batch file and run JFR command line option on that jar file but still I didn't get proper info. on dump file.
Does anybody provides any suggestion.
When using command line options, i.e. -XX:StartFlightRecording:filename=dump.jfr (JDK 11 syntax), you need to specify a directory where the file is allowed to be written. By default, it is the directory where the JVM process was started in.
If you mean using command line tools, i.e. jcmd JFR.dump filename=dump.jfr, there have been problems to attach to a JVM in a Docker container. The 'jcmd' tool can't find the correct /tmp directory where a file is located that is needed to attach to the process in the container. See https://bugs.openjdk.java.net/browse/JDK-8228343
JMC transfers recording data from the /tmp directory over JMX, so it can avoid the problem. You could write a Java program that dumps programmatically using the.FlightRecorderMXBean.
Here is the actual process i've followed.
we do have a batch file to run the application events on our Docker.
I've prepared a java program to run that particular batch file and generated a runnable jar file.
Now, I've called that particular jar file using JFR command to get those application event's dump on my system as follows:
-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=20s,duration=60s,name=Test, filename=recording.jfr,settings=profile -XX:FlightRecorderOptions=loglevel=info -jar sample.jar>
Built a new Windows Server 2016 to act as a target for jenkins orchestrated builds. We are not supposed to use oracle java anymore, so I got coretta openJDK. OpenJDK does not support javaws any more. The executable does not ship with it. I have seen some scripted workarounds, but they do not work and are poorly written to boot.
What are we supposed to use to launch slave agents on Windows machines?
There are several ways to implement this but since this is a windows server you can follow steps on https://github.com/kohsuke/winsw/blob/master/doc/installation.md#winsw-installation-guide to install jenkins slave as service without javaws.
I believe #Mike was referring to: Install Slave as a Windows service (cmd version), which does not need JNLP/javaws.
OR, under Jenkins 2 (we are using 2.121.1 plus WMI Windows Agents (aka windows-slaves:1.4), there is now an option to "Let Jenkins control this Windows slave as a Windows service", essentially in the same fashion as a Linux node.
You must have an Admin account (and password). We had to follow the guidance to edit registry when "Windows agents fail to start via DCOM" (Guidance is for Server 2012) to remotely manage the service. So far, seems to be working OK, YMMV. So far, seems to be working OK, no "subtle probelms"; YMMV.
For entries:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID{72C24DD5-D70A-438B-8A42-98424B88AFB8}
HKEY_CLASSES_ROOT\CLSID{76A64158-CB41-11D1-8B02-00600806D9B6}
(There are several matches for the keys; just change the two locations indicated)
Launch 'regedit' (as Administrator)
Find (Ctrl+F) the following registry key: "{72C24DD5-D70A-438B-8A42-98424B88AFB8}" in
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\
Right click and select 'Permissions'
Change owner to administrators group (Advanced...).
Change permissions for administrators group. Grant Full Control.
Change owner back to TrustedInstaller (user is "NT Service\TrustedInstaller" on local machine)
Repeat the steps 1-6 for HKEY_CLASSES_ROOT\CLSID{76A64158-CB41-11D1-8B02-00600806D9B6}
Restart Remote Registry Service (Administrative Tools / Services)
For me the easiest and best working solution to launch Windows Jenkins Agents without JNLP was to run in the command prompt java -jar agent.jar ... command. The command parameters should be grabbed from the url of the agent:
http://your_jenkins_url/computer/your_agent_name_or_ip/
I downloaded the agent.jar on my PC, moved it to a desired directory, launched the Command Prompt from the dir where the agent.jar was moved and executed the proposed command with the appropriate parameters.
In my case:
java -jar agent.jar -jnlpUrl http://your_jenkins_url/computer/your_agent_name_or_ip/slave-agent.jnlp -secret 76986574e97c2b635c7076740dc93326eaaf5a3ad30573144915489a1ccfee44 -workDir "D:\jenkins"
This was one of the proposed approaches in the docs here - https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines/
Java Web Start Java Web Start has been removed in Java 11. When a
Jenkins controller is running on Java 11, the Java Web Start button
will no longer appear in the Web UI. Agents for a Java 11 Jenkins
server can’t be launched from a *.jnlp file downloaded to a web
browser.
There are no plans to replace this functionality. Connect agents to
Jenkins on Java 11 with plugins like SSH Build Agents Plugin, with
operating system command line calls to java -jar agent.jar, or by
using containers.
I installed postgreSQL binaries in windows 7 32bit operating system; I can start the server from cmd but I cant run it as a windows service.
This is the error that I'm getting when I try to start the service manually:
"The postgreSQL service on local computer started and then stopped. some services stop automatically if they are not in use by other servces or programs"
All I need to do is; after booting to windows when I double clicked my java application I need to run my app smoothly without any database errors. I cannot do this because postgreSQL is not running as a windows service.
I found this in windows event viewer:
The description for Event ID 0 from source PostgreSQL cannot be found.
Either the component that raises this event is not installed on your local computer or the installation is corrupted.
You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory
I googled about it but I was not able to find an answer.
Problem was solved
path to the data directory was wrong in windows service file.
So I delete the service file from this method:
1)Run Regedit or Regedt32.
2)Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
3)Look for the postgreSQL service that you want delete and delete it.
4)reboot the computer.
After that open the cmd (Run as administrator) Go to the postgreSQL bin directory and run this command to create a new windows service:
pg_ctl.exe register -N "PostgreSQL" -U "NT AUTHORITY\NetworkService" -D "C:/Program Files/postgresql/pgsql/bin/pgsql/data" -w
This worked for me. Hope this will help.
This is a note for a normal user. If using an official installer it should has a build-in service,
Win+R and type services.msc
Search Postgres service based on the version installed,
e.g., "postgresql-x64-13 - PostgreSQL Server 13"
Click stop, start, or restart the service option
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or
directory
This looks like your working directory is C:\Windows\system32 and you are running postgres there and it looks for data/postgresql.conf.
Try changing the working directory or specifying -D C:\path\to\my\data.
I've installed a GlassFish Server instance into Netbeans, and I'm trying to install its update center. I have run Netbeans as an Administrator under Windows 7.
I'm on a fast internet connection, pkg.oracle.com seems to load rather fast from the browser. Still, I am keeping on getting this error:
C:\Program Files\glassfish-4.0>"C:\Program Files\Java\jdk1.6.0_45\bin\java" -Dimage.path="C:\Program Files\glassfish-4.0\bin\\.." -jar "C:\Program Files\glassfish-4.0\bin\\..\pkg/lib/pkg-bootstrap.jar" "C:\Users\velosyp\AppData\Local\Temp\pkg-bootstrap1368.props"
Proxy: Using system proxy settings.
Install image: C:\Program Files\glassfish-4.0
Installing pkg packages.
Downloading 2 packages.
Downloading pkg (514 files, 6 463 109 bytes).
Downloading python2.4-minimal (278 files, 3 828 949 bytes).
Executing 906 install actions.
Installing updatetool packages.
Downloading 2 packages.
Downloading updatetool (564 files, 4 632 599 bytes).
Input/output error: Read timed out
Could not download application packages. This could be because:
- a proxy server is needed to access the internet. Please ensure that
the system proxy server settings in your Internet Options control panel
(under Connections:LAN Settings) are correct, or set the HTTP_PROXY
environment variable to the full URL of the proxy server.
- the package server or network connection is slow.
If you are getting time out errors you can try setting the
PKG_CLIENT_CONNECT_TIMEOUT and PKG_CLIENT_READ_TIMEOUT
environment variables and try again. For example to increase
the timeouts to 300 seconds set them to 300
- the package server is down or otherwise inaccessible or it is
generating invalid data. Please contact the provider of the package
server.
What could be wrong?
This may be a problem with the slow GlassFish update server. Here are some steps you can try:
You should retry first to see if the error occurs again. You can start a cmd, navigate to the \glassfish\bin directory and run updatetool.bat so you can see the output which is printed after the one you posted.
If you are behind a proxy you should make sure it is setup correctly in the system settings.
You can also try to install the updates through the GlassFish admin console. Start your GlassFish instance and navigate to http:\localhost:4848. On the bottom of the left menu click on Updatetool. There you can choose and install the desired updates.
Another option is to change the timeouts of the pkg tool. To set the timeout to 300 seconds do the following in a cmd (on Windows):
set PKG_CLIENT_CONNECT_TIMEOUT=300
set PKG_CLIENT_READ_TIMEOUT=300
You last (ok, there may be other ones) option is to just skip the update process and do the tutorial with the current version. It should work anyway and I can see in my GlassFish update center that there is only an update for the tutorial documentation at the moment.
and
check this
Try pkg first, then pkg install updatetool.
Another option is to bootstrap the (smaller) pkg command first, and then use the pkg command to install updatetool (instead of bootstrapping updatetool). For example:
pkg list
Answer 'y' to bootstrap the pkg command. Then:
pkg install updatetool
to install updatetool using the pkg command.
How do I run a Java .jar file as a Windows service on a Windows 2008 server? I have a jar file called SomeJavaFile.jar located under the C:\SomeDirectory directory on a Windows Server 2008 box. I usually just run this jar manually in the command line with: java –cp SomeJavaFile.jar com.ctg.SomeJavaFile and I let it run 24/7.
The problem with our Windows Server is if it restarts I need to run it as a service so it will automatically start as a service upon startup, because our processing for Vistakon runs 24/7. I have Googled around and tried to use a service wrapper and the sc.exe command to create the service.
I put the wrapper service.exe in the C:\SomeDirectory\. I use the following command to create it: sc.exe SomeJavaService binPath= “C:\SomeDirectory\service.exe \”java –jar C:\SomeDirectory\SomeJavaFile.jar\”” type= own start= auto error= ignore. This creates the SomeJavaService service correctly but when I try to start it I get an error that says the service on Local Computer started then stopped.
Some services stop automatically if they are not in use by other services or programs. Do I need to alter my sc.exe command to have the exact previous working command line maybe, by adding in the com.ctg.SomeJavaFile? So should I change This jar should just run in the background and constantly poll/ping the C:/poll directory then if there is data present it processes the data and sends an export file to another directory.
I have used this same .jar file for years successfully and it hasn't changed, but I cannot get it to run as a Windows service. This is the site I use to get the service wrapper http://code.google.com/p/simple-service-wrapper/. Any help would be greatly appreciated!
"winsw" is the standalone version of the Windows Service installer shipping with the Glassfish Java EE reference implementation.
Works well, but is not a fully polished product - I have used it for exactly this purpose for a couple of years. Requires .NET in some recent version on the Windows machine.
https://github.com/kohsuke/winsw
I think that the best bet would be wrap your java app with Procrun of Apache Commons Daemon .
Procrun is a set of applications that allow Windows users to wrap
(mostly) Java applications (e.g. Tomcat) as a Windows service.
The service can be set to automatically start when the machine boots
and will continue to run with no user logged onto the machine.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat (that triggers the jar file)/.exe as a System service with all the required call back methods to SCM.
Note : 1. Wrapping the process with sc.exe / srvany.exe would not work as it does not have any call back process to the SCM (Service Control Manager). 2. And java service Wrapper is a third party API (many are LGPL licensed).
If you start your Java code from commandline by using java -j some.jar does it run until you terminate the program, or does it stop by itself?
There needs to be a NON-Deamon Thread, that is running all the time. A JVM will terminate, if there is no thread running, that is not flagged as daemon.
If you have a little budget, buy an installer tool. I use instll4j. With that tool, you can create service launcher and install them during instllation.
The following solution is working fine for me having OpenFire Connection Manager (which is a jar file) running as service on Windows Server.
Download and install the Non-Sucking Service Manager
I didn't use the batch made by OpenFire team, because it didn't work for me (dependencies not found error...) So, make a batch file with the following code :
#ECHO OFF
cd /D "E:\connection_manager\lib"
java -jar startup.jar
and save it as cm_startup.bat in the bin folder of connection manager.
After that you can create the service with NSSM.
So, open a cmd.exe and run the following command :
nssm install ConnManager "E:\connection_manager\lib\cm_startup.bat"
.
Doc & examples
More documentation and examples for the Non-Sucking Service Manager here : https://nssm.cc/usage Actually NSSM as a lot of options available.
Here is a more complexe example :
nssm install solr "%JavaExe%" -Dsolr.solr.home="\"%CD%\solr"\"
-Djetty.home="\"%CD%"\" -Djetty.logs="\"%CD%\logs"\" -cp
"\"%CD%\lib\*.jar"\";"\"%CD%\start.jar"\" -jar "\"%CD%\start.jar"\"