I need to start the service of Jboss 7.1.1 remotely through SSH. But when execute the command does not happened.
The command: ssh user#server '/etc/init.d/jboss-as start' #(no error, no service started)
The script jboss-as:
#!/bin/sh
case "$1" in
start)
echo "Starting JBoss AS 7"
su --command "/path/to/jboss-as-7.1.1.Final/bin/standalone.sh >& /dev/null &" root
;;
stop)
echo "Stopping JBoss AS 7"
su --command "/path/to/jboss-as-7.1.1.Final/bin/jboss-cli.sh --connect command=:shutdown" root
;;
*)
echo "Usage: /etc/init.d/jboss-as {start|stop}"
exit 1
;;
esac
exit 0
How to execute the command: ssh user#server 'service jboss-as start' or ssh user#server '/etc/init.d/jboss-as start'?
The connection with ssh is OK
The Jboss Server is OK
If i execute the code: ssh user#server '/etc/init.d/mysql restart' it happens!
One of a few things are limiting your ability to run this service with the command as that is a valid method of starting the service.
user#server '/etc/init.d/jboss-as start'
All of which you can test remotely after initiating the SSH connection. SSH into the server and start the service with the same user you are going to connect with using the above command.
Firstly make sure the service is actually called 'jboos-as' with ls /etc/init.d/ |grep 'jboss'. The result will be exactly how you will call the command so replace jboss-as with the output from the grep.
Secondly it is a permissions issue on the init script. From what I could see online you have to create this script so if the permissions are not setup correctly it will not execute.
To check run ls -al /etc/init.d/ |grep 'jboss' and your output should appear as follows:
Output:
-rwxr-xr-x. 1 root root 2979 Sep 19 05:34 jboss*
The user issuing the start command will need to match the first user listed. In this case the first 'root' and/or be in the same group as the group listing which is the second 'root' in the example. This can vary if for instance your user is in the wheel group, but generally services are run as root or a specific user for that service.
Lastly The more important aspect is that the file is executable. This is listed as the x value in the ls -al output above. If no 'x's are listed you will need to make the file executable with the following:
chmod +x /etc/init.d/jboss
IMPORTANT all the above command will need you to referrence the file as it output in the first grep command, so /etc/init.d/jboss-as or /etc/init.d/jboss or /etc/init.d/jboss-something different.
I hope this helps you out and if it does not please post the results of the ls -al output and we can help you further.
Ok.
Let`s go.
Search the name of the jboss service:
ls /etc/init.d/ |grep 'jboss' Returned "jboss-as". It is ok!
Permissions:
ls -al /etc/init.d/ |grep 'jboss' Returned exactly the same output: -rwxr-xr-x. 1 root root 2979 Sep 19 05:34 jboss-as Its ok!
Still do not works.
The principal objective to execute this command is an action of button in the Java program using SWT and the lib that implements SSH called JSCH. Look the code:
Session session = jsch.getSession("user", "SERVER_IP_ADDRESS", PORT);
session.setPassword("pass");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand("'/etc/init.d/jboss-as start'"); #command to start jboss service
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect();
Related
I have installed Apache GUI on Linux Debian in the following directory
/usr/local/apachegui/ApacheGUI/bin
by the following instruction as shown on this webpage:
https://www.howtoforge.com/tutorial/ubuntu-apache-gui/
At the end of the instruction, it's says run the following command:
sudo ./run.sh
when I run the above command I get the following output but with an error
./run.sh: 1: [: -ne: unexpected operator
Bottom of the terminal window its mention tomcat started and as in above mention tutorial webpage claims after running run.sh command
Your ApacheGUI is now starting and listening on port 9999.
Next, open your web browser and type the URL >http://your-server-ip:9999/ApacheGUI. You will >be redirected to the following page (ApachiGUI home page)
In my case when I am typing the above URL with my IP address or localhost my Chrome browser print: output site can not be reach
So I searched to check if port 9999 is enabled and listening in my case I was unable to see port 9999 in my list of ports so ran the following commands and the terminal window didn't produce any output from here I assumed port 9999 is close
pi#Home:~ $ ss -na | grep :9999
After using the above command terminal window return back to ip#home:$
now I open a separate terminal window and ping port 9999 and as result, This terminal window hang now it is clear the port 9999 is not open in my server so to open the close port I run the following command
Open port command:
sudo iptables -A INPUT -p tcp --dport 9999 -j ACCEPT
To update the firewall rules, I restart the iptables service
sudo iptables -L
output:
pi#Home:~ $ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:9999
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Now I check again a list of open ports on my server and I still can't see port 9999
After taking all these steps executed following command:
pi#Home:/usr/local/apachegui/ApacheGUI/bin $ ./run.sh
Output:
Using CATALINA_BASE: /usr/local/apachegui/ApacheGUI/tomcat Using
CATALINA_HOME: /usr/local/apachegui/ApacheGUI/tomcat Using
CATALINA_TMPDIR: /usr/local/apachegui/ApacheGUI/tomcat/temp Using
JRE_HOME: /usr Using CLASSPATH:
/usr/local/apachegui/ApacheGUI/tomcat/bin/bootstrap.jar:/usr/local/apachegui/ApacheGUI/tomcat/bin/tomcat-juli.jar
Tomcat started.
look like the initial error is resolved but I am still unable access ApacheGUI from my browser still unable to resolve the error mention above can anyone suggest what is the solution to this problem?
The run.sh file is a badly written shell script with content:
if [ $UID -ne 0 ]; then
sudo ../tomcat/bin/startup.sh
exit
fi
exec ../tomcat/bin/startup.sh
Just execute tomcat/bin/startup.sh. This script can fail in many ways:
there is no shebang (#!interpreter_name), so it is executed using /bin/sh or whatever the default shell is,
UID is not a POSIX variable (cf. this question), so the result is blank and test ([) only sees -ne 0. Usually in such cases the variable should be quoted or tested if it is not empty,
the path ../tomcat/bin/startup.sh is relative to the current directory, not the directory of the script.
By executing following tests you will learn port testing and port configuration and at the end of these test you will be able to find out either problem exist within your Server ports or you have to check the setting of your browser. In my case I have taken an unintentional long route, I set my testing plan into three sections as follow
Server Ports and Browser
If you ever experience the same issue my advise is to troubleshoot
Server Browser and then test Ports
By executing tomcat/bin/startup.sh it does start the server successfully just like run.sh (as mention in Question and given answer above) but the browser was still unable to load the localhost:9999/ApacheGUI index page because the server's initial error
./run.sh: 1: [: -ne: unexpected operator
was resolve (as shown in question) but the browser was still unable to load the GUI page so for this reason just to find out if there is a problem with port 9999 itself or there is something else causing localhost not to communicate with the browser via port 9999 I have carried out following tests:
I believe the following information is suitable for a tester who wants to troubleshoot ports but if you think there is nothing wrong with your ports and the problem may lies with the browser then visit the following link Where I had the same problem with port 8080 and I overcome this issue by modifying browser settings:
https://stackoverflow.com/questions/66524719/tomcat10-home-page-can-not-load-by-typing-localhost8080-error-err-connection-r
Reboot my server and execute the following command in terminal
tomcat/bin/startup.sh
output shows
Tomcat started
With this output, I know ApacheGUI is installed and the server is up and running.
Q: if the server is running so whey localhost:9999/ApacheGUI index
page is unable to load?
let's test port 9999 and take the following steps to check either it's port on your machine causing this error or it's something else
StepNO:1
pi#Home:~ $ nc -vz 192.168.0.16 9999
Connection to 192.168.0.16 9999 port [tcp/*] succeeded!
StepNO:2
type command on Linux terminal to test port 9999 (Enter)
pi#Home:~ $ sudo ls | nc -l -p 9999
(Cursor start flashing with no output)
StepNo:3
Then turn ON Window computer and open PuTTY client
Establish SSH connection from window machine by typing the following credentials in PuTTY Client interface:
Server: 192.168.0.16 port 9999
(Press Enter)
if port 9999 is open successfully you will get the following results
Linux Server Terminal (StepNO:2) Where cursor was flashing start responding to
Client request and print following line (where the cursor is still flashing):
SSH-2.0-PuTTY_Release_0.74
StepNO:4
Open a new terminal window and typed another command to make sure port 9999 is definitely open and responding (Linux Server terminal in StepNO:2 still open)
pi#Home:~ $ nmap -p 9999 192.168.0.16
Output:
Starting Nmap 7.70 ( https://nmap.org ) at 2021-03-05 23:44 GMT Nmap
scan report for 192.168.0.16 Host is up (0.00049s latency).
PORT STATE SERVICE 9999/tcp open abyss
Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds
This stage confirmed I have successfully open port 9999 and the port is responding to
TCP protocols
StepNO:5
in the same Linux server terminal (stepNO:2) I type the following command again:
sudo ls | nc -l -p 9999 (Enter)
(Cursor start flashing)
Now I have open the browser and type ApacheGUI URL
192.168.0.16:9999/ApacheGUI (Enter)
Linux server terminal from StepNO:2 where the cursor is flashing start responding to
URL request from the browser and print the following lines in the terminal window:
Output:
GET /ApacheGUI/ HTTP/1.1 Host: 192.168.0.16:9999 Connection:
keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (X11;
Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/86.0.4240.197 Safari/537.36 Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9
But: my ApacheGUI index page still unable to load and showing the following error message
This site can’t be reached192.168.0.16 refused to connect. Try:
Checking the connection Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
At this stage, I am 100% sure that my installed server is up and running. Port 9999 in my server is open and functional so there is nothing else that can cause this error except the browser so I have followed the step to tune my browser setting as described in answer to the following link:
https://stackoverflow.com/questions/66524719/tomcat10-home-page-can-not-load-by-typing-localhost8080-error-err-connection-r
Result: Successful connection ApacheGUI index page finally loaded to the browser.
I have the following Jenkins post-build shell script:
ssh user#my_server <<EOF
service my_service stop
service my_service start
tail -f /opt/services/my_service/logs/current
exit
EOF
This script restarts my_service on a remote host (my_server).
My problem is: command service my_service start just makes a request to RUNIT to run a my_service, i.e service my_service start returns immediately after execution.
But service my_service start runs a SpringBoot java web application that writes all log info into .../logs/current log file. To catch this log info I've added command tail -f /opt/services/my_service/logs/current but in this case Jenkins build is never ends)) such as tail -f command never stops.
Is there a way to execute my post-build script (which only start my web app on a remote server) and grabbing the .../logs/current log file during 2 minutes or until this log has the line "Web app MyApplication has been Started".
I wanna see the content of .../logs/current log file right in Jenkins's Console output and kill tail -f after 2 minutes
tail -f will not end until it gets interrupted, so your script will never finish running.
what you can do is use grep -q on your log, which will exit with 0 exit status when it finds it's pattern:
grep -q 'Web app MyApplication has been Started' <(tail -f /opt/services/my_service/logs/current)
I'm unsuccessful with combining "Sudo" and "ScpTo" cases.
I noticed, that both work through "exec" channel.
Clean "ScpTo" case finishes with "Permission denied" message.
"Sudo" case
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("sudo -S -u <supervisor> whoami");
works fine.
When I connect to my server through FarManager I write server option:
sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server
Also, I can run usual SFTP client like this:
sftp -s 'sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server' "usual user"#"host"
and give put command.
But such option (-s) is not implemented in JSch.
How can I configure my case (Sudo & ScpTo) with JSch?
In ScpTo.java example, there's this code:
String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
Change that to:
String command="sudo su -l <supervisor> -c scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
At this moment I am using command below as a part of my batch script to boot domain1:
asadmin start-domain domain1
however I have recently installed domain1 as a service so now when I use this command the domain is starting under my user process instead of booting as a service. So after I logout, the domain is gone. I used:
net start domain1
and
sc start domain1
However both of these seem to return as soon as signal[or whatever else] is dispatched toward service, and they do not wait untill domain1 is actually started. "asadmin start-domain" did return after it started the domain...
I have to wait as in my script I am undeploying/deploying new app shortly after domain start. So is there any way to start Glassfish as service using batch command and wait untill it is started?
Install:
sc create ServiveName binpath= <PATH_TO_SERVICE>.exe
net start ServiveName
PAUSE
Start:
net start ServiceName
PAUSE
Stop:
net stop ServiceName
PAUSE
Uninstall:
net stop ServiceName
sc delete ServiceName
PAUSE
One of the solutions I am using:
#echo off
SETLOCAL enableextensions enabledelayedexpansion
set GLASSFISH_HOME=c:\glassfish
set DOMAIN=domain1
net start %DOMAIN%
:loop
call timeout /t 1 /NOBREAK > NUL
echo Still waiting for domain to start
for /f "tokens=1,2 delims= " %%A IN ( '"%GLASSFISH_HOME%\bin\asadmin.bat" list-domains' ) DO IF "%%A"=="%DOMAIN%" SET GLASSFISH_RUNNING=%%B
if not "%GLASSFISH_RUNNING%"=="running" (
goto loop
)
I modified the above version a little bit for better understanding:
#echo off
SETLOCAL enableextensions enabledelayedexpansion
set GLASSFISH_HOME=D:\glassfish
set DOMAIN=domainName
set SERVICE_NAME="name of your service"
net start %SERVICE_NAME%
:loop
call timeout /t 1 /NOBREAK > NUL
echo Still waiting for domain to start
for /f "tokens=1,2 delims= " %%A IN ( '"%GLASSFISH_HOME%\bin\asadmin.bat" list-domains' ) DO IF "%%A"=="%DOMAIN%" SET GLASSFISH_RUNNING=%%B
if not "%GLASSFISH_RUNNING%"=="running" (
goto loop
)
Some applicatios already provide possiblities to automatically create Windows services. However every .exe can be configured this way.
GUI: http://www.sevenforums.com/tutorials/2495-services-start-disable.html
Console: https://support.microsoft.com/de-de/kb/137890
Automatic startup before logon: https://serverfault.com/questions/227862/run-a-program-without-user-being-logged-on
Type the following code in notepad and save [name].bat (for windows)
cd C:\glassfish3\glassfish3\bin
asadmin start-domain
PAUSE
I am trying to get my java application deployed on tomcat server (in windows), I am getting the following error. Please help me with some guideline on the following connection error. I have admin privilege and server is running in local.
C:\builds>cap local deploy
DL is deprecated, please use Fiddle
* 2013-04-01 14:19:06 executing `local'
* 2013-04-01 14:19:06 executing `deploy'
* 2013-04-01 14:19:06 executing `deploy:update'
** transaction: start
* 2013-04-01 14:19:06 executing `deploy:update_code'
* executing "xcopy C:/_Savita/app/my-app \"C:/builds/releases/20
130401084906\" /S/I/Y/Q/E && (echo > C:/builds/releases/20130401084906/REVISION
)"
servers: ["localhost"]
*** [deploy:update_code] rolling back
* executing "rm -rf C:/builds/releases/20130401084906; true"
servers: ["localhost"]
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionErr
or, connection failed for: localhost (Errno::ECONNREFUSED: No connection could b
e made because the target machine actively refused it. - connect(2))
connection failed for: localhost (Errno::ECONNREFUSED: No connection could be ma
de because the target machine actively refused it. - connect(2))
Please find below the deploy script used
set :application, "myApp"
#set :scm, "git"
set :repository, "C:/_Savita/app/my-app"
#set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
task :local do
roles.clear
server "localhost", :app
set :user, "Savita Doddamani"
set :java_home, "C:/Program Files (x86)/Java/jdk1.6.0_25"
set :tomcat_home, "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0"
set :tomcat_manager, "user"
set :tomcat_manager_password, "pwd"
set :maven_home, "C:/_Savita/softwares/apache-maven-2.2.1"
set :deploy_to, "C:/builds/"
set :use_sudo, false
namespace :tomcat do
task :deploy do
puts "==================Building with Maven======================" #Line 22
run "export JAVA_HOME=#{java_home} && cd #{deploy_to}/ && #{maven_home}/bin/mvn clean install package -DskipTests"
puts "==================Undeploy war======================"#Line 24
run "curl --user #{tomcat_manager}:#{tomcat_manager_password} http://$CAPISTRANO:HOST$:8080/manager/text/undeploy?path=/#{application}"
puts "==================Deploy war to Tomcat======================" #Line 26
run "curl --upload-file #{deploy_to}/current/target/dist/local/#{application}*.war --user #{tomcat_manager}:#{tomcat_manager_password} http://$CAPISTRANO:HOST$:8080/manager/text/deploy?path=/#{application}"
end
end
after "deploy", "tomcat:deploy" #Line 30
after "tomcat:deploy", "deploy:cleanup" # keep only the last 5 releases
end
ECONNREFUSED is the return from the connect(2) system call. It means that the server process is not listening on TCP port 8080. Java takes time to start up and you may be attempting to connect via curl too soon or you have not configured Tomcat to listen on port 8080 or you have not started Tomcat at all.