Address binding issue - java

I am trying to run a web application (which is a servlet + gradle project). I am using Jetty to run the application. When I run the application , I am getting the error:
Address already in use
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.0-bin.zip'.
When, I enter localhost:8080 , I used to get jenkins default page, So I uninstalled jenkins and tried again, but getting the same error.
Please help in resolving this issue, also how do we get to know which application is running on corresponding port?

You can use the command "netstat". Look for the line in which the column "remote address" ends with ":8080".
Depending on the OS you're running:
Windows:
netstat -b -n -a -p TCP
The process is printed above the line.
Linux:
netstat -a -n -p | grep 8080
The process is printed as the last column of the line.

Related

Using Freenas 11.2 my java process closes when leaving jail shell

For the past 2 weeks I've been busy trying to figure out how to setup my minecraft server onto my freenas server.
I was able to get it up and running stably when going into the jail manually typing in my startup command:
cd /root/Minecraft_Server
java -Xmx4096M -Xms4096M -jar forge-1.12.2-14.23.4.2757-universal.jar
And then just close the shell.
I tried looking to automate this command and put it into and sh file in crontab and everything, that didn't work so i decided to upgrade to 11.2 to see if that has any solutions.
Now the main problem already is that if I try to run my command manually in the shell, and i leave the webui, it will just close the server down to unlike in the 11.1 freenas.
Does anyone have any more ideas here?
In the same location as the server I have a minecraft.sh script with this command.
If I manually run the script it works, but if I use crontab it won't start it either.
The corntab command that i've used is:
#reboot /root/Minecraft_Server/minecraft.sh
I also tried putting in the command directly but this also was useless.
I even tried the exec.poststart but when i direct it to /root/minecraft_Server/minecraft.sh it won't start either, it won't even run the jail anymore
use “screen java ...”
on relog to shell do screen -x to get on the server shell
You can configure your Java command as a service that starts whenever the jail starts. That way, the Java server doesn’t depend on the shell or webui.
Basically, create a usr/local/etc/rc.d/minecraftd file that includes the following script:
#!/bin/sh
#
# PROVIDE: minecraftd
# REQUIRE: LOGIN DAEMON NETWORKING mountcritlocal
# KEYWORD: shutdown
#
# Use the following variables to configure the minecraft server. For example, to
# configure the ON/OFF knob variable:
# sysrc minecraftd_enable="YES"
#
# minecraftd_enable="YES"
# minecraftd_user_dir="/root/minecraft"
# minecraftd_jar_path="/root/minecraft/server.jar"
# minecraftd_java_opts="-Xms512M -Xmx1024M"
. /etc/rc.subr
name=minecraftd
rcvar=`set_rcvar`
pidfile=/var/run/minecraftd.pid
load_rc_config $name
start_cmd="${name}_start"
: ${minecraftd_enable="NO"}
: ${minecraftd_user_dir="/root/minecraft"}
: ${minecraftd_jar_path="/root/minecraft/server.jar"}
: ${minecraftd_java_opts="-Xms512M -Xmx1024M"}
minecraftd_start() {
if [ -e $pidfile ]; then
echo "$name already running."
else
echo "Starting $name..."
/usr/sbin/daemon -f -p $pidfile \
/usr/local/bin/java -Duser.dir=$minecraftd_user_dir \
$minecraftd_java_opts \
-jar $minecraftd_jar_path nogui
echo "$name started."
fi
}
run_rc_command $1
Then configure the service to start on boot:
sysrc minecraftd_enable="YES"
And restart your jail.
For more information, check Installing a Minecraft server on FreeNAS.
Disclaimer: My team published that article.
Hope this helps somebody.

Shell script to validate if my tomcat is running or not - uniquely identify

I see many shell scripts to check process if that is running we proceed further.
But there is scenario like below or if we have multiple tomcat running on single host, how do we identify if our process running?
e.g if I go to path /opt/alfresco/tomcat/bin and execute command
ps -ef | grep tomcat
It will give me output (even tomcat is not running)
[alfresco#host030 bin]$ ps -ef |grep tomcat
alfresco 12090 11302 0 22:57 pts/0 00:00:00 grep tomcat
[alfresco#host030 bin]$
So if I am using alfresco tomcat and I need to validate if my tomcat process actually started and running, how do I validate?
Also to differentiate between any java and tomcat running, HOW ?
You can try with the below script. Do grep for the listening port, use your port number.
JAVA_HOME=/usr/java/default
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
export JAVA_HOME=$JAVA_HOME
if [ $SHUTDOWN_PORT -ne 0 ]; then
echo 'Alfresco is running'
else
echo "Alfresco is not running"
To start it you can use
ALF_HOME=/www/web/dev1/alfresco
$ALF_SCRIPT start
If your tomcat is running as a service you can run service tomcat status.
If its not running as service its recommended to do it..
Read this how to do it: https://www.linux.com/learn/managing-linux-daemons-init-scripts

IOS Webkit Debug proxy issue - Unable to bind device

I am trying to start ios webkit debug proxy by passing the udid and the port number.
Command: ios_webkit_debug_proxy -c 4ea8dd11e8c4fbc1a2deadbeefa0fd3bbbb268c7:27753 -d.
Facing issue while binding the device on port number 27753. Error message,'Unable to bind udid on port 27753-27753'
Check this web link https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/ios-webkit-debug-proxy.md, if it helps.
Most likely it cannot be bind to the port since it's already taken.
Check if the port is taken by another process (or same type of process that is hanged by some reason) by running sof -t -i tcp:27753 command in terminal.
To find and kill process run sof -t -i tcp:27753 | xargs kill command in terminal, but it's not safe to do in case if you have parallel execution and/or not only ios_webkit_debug_proxy is using port 27753.

How to keep a GlassFish server's domain active while disconnected from SSH to an EC2 instance? [duplicate]

I connect to the linux server via putty SSH. I tried to run it as a background process like this:
$ node server.js &
However, after 2.5 hrs the terminal becomes inactive and the process dies. Is there anyway I can keep the process alive even with the terminal disconnected?
Edit 1
Actually, I tried nohup, but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.
Is there anything I have to do in Putty?
Edit 2 (on Feb, 2012)
There is a node.js module, forever. It will run node.js server as daemon service.
nohup node server.js > /dev/null 2>&1 &
nohup means: Do not terminate this process even when the stty is cut
off.
> /dev/null means: stdout goes to /dev/null (which is a dummy
device that does not record any output).
2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null). You may replace &1 with a file path to keep a log of errors, e.g.: 2>/tmp/myLog
& at the end means: run this command as a background task.
Simple solution (if you are not interested in coming back to the process, just want it to keep running):
nohup node server.js &
There's also the jobs command to see an indexed list of those backgrounded processes. And you can kill a backgrounded process by running kill %1 or kill %2 with the number being the index of the process.
Powerful solution (allows you to reconnect to the process if it is interactive):
screen
You can then detach by pressing Ctrl+a+d and then attach back by running screen -r
Also consider the newer alternative to screen, tmux.
You really should try to use screen. It is a bit more complicated than just doing nohup long_running &, but understanding screen once you never come back again.
Start your screen session at first:
user#host:~$ screen
Run anything you want:
wget http://mirror.yandex.ru/centos/4.6/isos/i386/CentOS-4.6-i386-binDVD.iso
Press ctrl+A and then d. Done. Your session keeps going on in background.
You can list all sessions by screen -ls, and attach to some by screen -r 20673.pts-0.srv command, where 0673.pts-0.srv is an entry list.
This is an old question, but is high ranked on Google. I almost can't believe on the highest voted answers, because running a node.js process inside a screen session, with the & or even with the nohup flag -- all of them -- are just workarounds.
Specially the screen/tmux solution, which should really be considered an amateur solution. Screen and Tmux are not meant to keep processes running, but for multiplexing terminal sessions. It's fine, when you are running a script on your server and want to disconnect. But for a node.js server your don't want your process to be attached to a terminal session. This is too fragile. To keep things running you need to daemonize the process!
There are plenty of good tools to do that.
PM2: http://pm2.keymetrics.io/
# basic usage
$ npm install pm2 -g
$ pm2 start server.js
# you can even define how many processes you want in cluster mode:
$ pm2 start server.js -i 4
# you can start various processes, with complex startup settings
# using an ecosystem.json file (with env variables, custom args, etc):
$ pm2 start ecosystem.json
One big advantage I see in favor of PM2 is that it can generate the system startup script to make the process persist between restarts:
$ pm2 startup [platform]
Where platform can be ubuntu|centos|redhat|gentoo|systemd|darwin|amazon.
forever.js: https://github.com/foreverjs/forever
# basic usage
$ npm install forever -g
$ forever start app.js
# you can run from a json configuration as well, for
# more complex environments or multi-apps
$ forever start development.json
Init scripts:
I'm not go into detail about how to write a init script, because I'm not an expert in this subject and it'd be too long for this answer, but basically they are simple shell scripts, triggered by OS events. You can read more about this here
Docker:
Just run your server in a Docker container with -d option and, voilá, you have a daemonized node.js server!
Here is a sample Dockerfile (from node.js official guide):
FROM node:argon
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
Then build your image and run your container:
$ docker build -t <your username>/node-web-app .
$ docker run -p 49160:8080 -d <your username>/node-web-app
Always use the proper tool for the job. It'll save you a lot of headaches and over hours!
another solution disown the job
$ nohup node server.js &
[1] 1711
$ disown -h %1
nohup will allow the program to continue even after the terminal dies. I have actually had situations where nohup prevents the SSH session from terminating correctly, so you should redirect input as well:
$ nohup node server.js </dev/null &
Depending on how nohup is configured, you may also need to redirect standard output and standard error to files.
Nohup and screen offer great light solutions to running Node.js in the background. Node.js process manager (PM2) is a handy tool for deployment. Install it with npm globally on your system:
npm install pm2 -g
to run a Node.js app as a daemon:
pm2 start app.js
You can optionally link it to Keymetrics.io a monitoring SAAS made by Unitech.
$ disown node server.js &
It will remove command from active task list and send the command to background
I have this function in my shell rc file, based on #Yoichi's answer:
nohup-template () {
[[ "$1" = "" ]] && echo "Example usage:\nnohup-template urxvtd" && return 0
nohup "$1" > /dev/null 2>&1 &
}
You can use it this way:
nohup-template "command you would execute here"
Have you read about the nohup command?
To run command as a system service on debian with sysv init:
Copy skeleton script and adapt it for your needs, probably all you have to do is to set some variables. Your script will inherit fine defaults from /lib/init/init-d-script, if something does not fits your needs - override it in your script. If something goes wrong you can see details in source /lib/init/init-d-script. Mandatory vars are DAEMON and NAME. Script will use start-stop-daemon to run your command, in START_ARGS you can define additional parameters of start-stop-daemon to use.
cp /etc/init.d/skeleton /etc/init.d/myservice
chmod +x /etc/init.d/myservice
nano /etc/init.d/myservice
/etc/init.d/myservice start
/etc/init.d/myservice stop
That is how I run some python stuff for my wikimedia wiki:
...
DESC="mediawiki articles converter"
DAEMON='/home/mss/pp/bin/nslave'
DAEMON_ARGS='--cachedir /home/mss/cache/'
NAME='nslave'
PIDFILE='/var/run/nslave.pid'
START_ARGS='--background --make-pidfile --remove-pidfile --chuid mss --chdir /home/mss/pp/bin'
export PATH="/home/mss/pp/bin:$PATH"
do_stop_cmd() {
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
$STOP_ARGS \
${PIDFILE:+--pidfile ${PIDFILE}} --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
rm -f $PIDFILE
return $RETVAL
}
Besides setting vars I had to override do_stop_cmd because of python substitutes the executable, so service did not stop properly.
Apart from cool solutions above I'd mention also about supervisord and monit tools which allow to start process, monitor its presence and start it if it died. With 'monit' you can also run some active checks like check if process responds for http request
For Ubuntu i use this:
(exec PROG_SH &> /dev/null &)
regards
Try this for a simple solution
cmd & exit

Launching a JBoss AS Cluster on Separate Machines to run EJBCA

Right now I am running my EJBCA project on single Jboss server using following command
run.sh -c default -b test.mywebsite.net
and it works fine, but now I want to launch my EJBCA application on clustered jboss machines
for this I have read following links
1.1.2. Launching a JBoss AS Cluster
1.1.3. Web Application Clustering Quick Start
then further I read that There are two aspects to setting up web tier clustering:
Configuring an External Load Balancer.
Configuring Your Web Application for Clustering.
now my questions are
When I go with the External Load Balancer. and when I go with second
option
If I go with second option how it will work ? and what will be my -b
option while running this Jboss servers.
because in point 1.1.2 I read that
Two processes can't bind sockets to the same address and port, so we'll have to tell JBoss to use different ports for the two instances.
EJBCA Version :- ejbca_4_0_12
JBOSS Version :- jboss-6.1.0.Final
EDIT 1
right now I am running my server like this
/run.sh -c default -b test.mysite.net
so it will listen on
https://test.mysite.net:8443/ejbca/
now I have to run my application as
Machine 1
./run.sh -c node1 -g DocsPartition -u 239.255.100.100 \
-b test.mysite.net -Djboss.messaging.ServerPeerID=1 \
-Djboss.service.binding.set=ports-default
Machine 2
./run.sh -c node2 -g DocsPartition -u 239.255.100.100 \
-b test.mysite.net -Djboss.messaging.ServerPeerID=2 \
-Djboss.service.binding.set=ports-default
so that I can only access to
https://test.mysite.net:8443/ejbca/
Please can any one explain this In brife so That I can clear with this things Thanks..
When you follow the documentation you mentioned (Scenario 3: Two Nodes on a Single, Non-Multihomed, Server) you have two JBoss instances:
./run.sh -c node1 -g DocsPartition -u 239.255.100.100 \
-b 192.168.0.101 -Djboss.messaging.ServerPeerID=1 \
-Djboss.service.binding.set=ports-default
./run.sh -c node2 -g DocsPartition -u 239.255.100.100 \
-b 192.168.0.101 -Djboss.messaging.ServerPeerID=2 \
-Djboss.service.binding.set=ports-01
They will listen on:
1) http://192.168.0.101:8080
2) http://192.168.0.101:8180
So to which node you will point your browser to reach the cluster? You can't use either of the two if you want failover. You need to configure a load-balancer.
Furthermore JBoss needs to know that it should replicate the http-session. Therefore you need to configure your web application for clustering. Hence you need to configure 1) and 2) not 1) or 2).
The -b x.x.x.x points to a (the) public IP-address of your server.

Categories

Resources