Run standalone.bat from Wildfly like background process command line? - java

I'm having trouble installing Wildfly as a service.
So I need to be able to run the Wildlfy in standalone mode as a temporary solution, but I want it to run in the background since it is a shared server and by mistake someone can close the console:
C:\wildfly-10.1.0.Final\bin>standalone.bat --silent --close-cmd-after-start
Basically I want to be able to close the terminal once the standalone.bat is executed

The solution thanks to the suggestion of Eriksun
cd C:\wildfly-10.0.0.Final\bin>
powershell -c "saps standalone.bat -windowstyle hidden"

In case of linux you can use something like this one ./standalone.sh & . So, you can try
C:\wildfly-10.1.0.Final\bin>standalone.bat --silent --close-cmd-after-start &
which helps to run your application on background.

Related

Windows - running command as a service

I have a command that I would like to create a service from. For example: "java -jar agent.jar" (the command is blocking - when closing the cmd it will stop the agent). I would like to make the command run as a service in the background so I can log out from my user and it will still work.
On Linux, I know for a fact that I can use nohup mycommand. The problem is on Windows OS. Also, replace java with javaw will solve the blocking issue but when I sign out it will still kill the agent.
How do I do that?
I'll appreciate your help!
Tomer.
Use Windows services feature.
Read this answer.
And this solution.

How to start a java service from Jenkins

Jenkins newbie here, I'm using Jenkins to build a SpringBoot app with Maven. What I have done ok so far:
Check out the code
Build the app
Copy the app to app folder.
However i could not complete this step:
Start the app as a server (standalone, not using Tomcat).
I use this command
java -jar app.jar &
but as long as Jenkins finishs the job, the app also quits (I don't see the log shows that the app exits, but when I checked, it did not run)
Jenkins runs on same server with the app (Amazon linux).
Any help is much appreciate.
Try using nohup. Something like this:
killall -9 app.jar
nohup java -jar app.jar > app.log 2>&1 &
But I strongly advise you to create a Docker image with your application to deploy it.
Best regards.

Screen -dmS working from command line but not from Java (Spigot restart script)

I recently changed my dedicated server and since then the script I use to restart my minecraft server isn't working anymore.
I can call the script using sh start.sh and my server starts, however when I use the in-game /restart command or when I instruct the server to restart from my plugin, the server closes and never restarts.
Here is the content of my start.sh
screen -dmS mc_hub1 java -jar -Xmx2048M -DIReallyKnowWhatIAmDoingISwear server.jar
Unless I'm running the script from the command-line, nothing happens, the screen isn't even created.
The issue seems to be originating from screen -dmS mc_hub1 because the restart instruction works if I remove it, actually it feels like I can't use anything related to screens from Java but it used to work so I'm a bit lost.
The dedicated server on which everything works is running Debian 9.9, Screen 4.05.00 and the new one is running Debian 9.11 and Screen 4.05.00.
I tried to add the -L option to enable logging but it doesn't even create the file,
Everything in the folder has read and execute permissions,
I tried to call the script from my plugin using java.lang.ProcessBuilder, no exception but still no result
ProcessBuilder pb = new ProcessBuilder("start.sh");
pb.directory(new File("/home/minecraft/uhc/"));
pb.start();
Java version doesn't seem to be causing the problem (I tested with the latest one and the one from my first dedicated server which is older)
Any help would be appreciated, thanks

Centos java custom service

I have a script.sh that set some environment variable and start a java server.
#!/bin/bash
export JAVA_HOME="/opt/java"
export ....
nohup $JAVA_HOME/bin/java "$MEMORY_JAVA_OPS" -classpath "$MY_CLASSPATH" $MAIN_CLASS &
I would like to transform this script (now is launched by /etc/rc.d/rc.local) in a service.
I tried many examples found online and over StackOverflow.
I created myservice.service file using many templates found online... No one work!
one example is:
[Unit]
Description=MyService Java Process Restart Upstart Script
After=auditd.service systemd-user-sessions.service time-sync.target
[Service]
User=root
TimeoutStartSec=0
Type=simple
KillMode=process
#export JAVA_HOME=/opt/java/jdk-9
#export PATH=$PATH:$JAVA_HOME/bin
WorkingDirectory=/tmp/myworkdir
ExecStart=/path/to/myscript.sh
[Install]
WantedBy=multi-user.target
With some configurations, the service starts but the status command says that it is dead (while it is actually running). With others it does not start. With none it stops with the command stop ....
I tried Type=Simple, forking, oneshot... always some problem.
I would simply that after boot or when user launch systemctl start myservice, service start, and if after some time crash will be started again. And if I will run systemclt stop myservice it stops and not need to kill the process.
Firstly it need to be said, that concept "service" greatly differs in Linux/Unix and Windows environment. From your question seems to me you are looking for Unix solution.
In unix you typically register some statup and stop script/command. The startup script just runs your java application via java -jar app.jar. This application does business logic & also opens listening on some SHUTDOWN port.
The stop script/command just invokes another (or the same with different cmd parameters) java application which does nothing else just sending STOP command to original application's SHUTDOWN port.
You can look in more detail for example on tomcat startup/stop scripts - they are doing exactly this.
For windows is better to use some wrappers like WinRun4J or whatever else. Of course you can have one multiplatform maven archetype for "universal multiplatform" service like we do.
EDITED:
If you are still unsure how to configure it on Linux, read https://linuxconfig.org/how-to-create-systemd-service-unit-in-linux
ExecStart will be the startup java -jar app.jar and ExecStop will be the stopping command java -jar app-stopper.jar

Listen to serial port at STARTUP using java with arguments on Debian(Rasbian)

I've been stuck two weeks trying to figure out how to run this at startup.
I use the following chain of commands on the terminal:
1. source ~/.bashrc
2. source ~/.tinyos.sh
3. java net.tinyos.tools.Listen -comm serial#/dev/ttyUSB0:telosb | python demo.py`
The third command uses java to listen to the serial port and pipes it to a python script which cleans, converts and uploads to mysql localhost.
This works fine on ssh terminal. But ive tried using nohup+update-rc.d, upstart, systemd, crontab to make it run on startup and it just wont work! When I reboot and check logs / database, its as if the command never happened. I need this to run like a daemon and continue running until shutdown.
Thanks a lot.
How are you trying to execute the program ? Are there are permission issues accessing / executing the script ?
Which version of debian are you running - look at upstart scripts if you are running Jesse+
I'd put those three lines in a bash script and use upstart scripts to trigger them on start. Another option is to use supervisord to make sure that your scripts run and restart if for any reason the program crashes.

Categories