Running Jenkins from command line vs as Windows service - java

I ran into a very strange issue. I need to configure proxy in my Jenkins to be able to access SVN repository in one of the jobs. I have done so in 2 ways:
Started Jenkins from command line with the required arguments
Started Jenkins as Windows service while the arguments are defined in the jenkins.xml file.
Starting from command line:
C:\>java -DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP
="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=312
8 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar %JENKINS_HOME%\jenkins
.war
Starting as service (below is the jenkins.xml contents):
<executable>java</executable>
<arguments>-DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar "%JENKINS_HOME%\jenkins.war"</arguments>
So that's exactly the same. The issue however is that when I am using command line to start Jenkins, proxying works fine. But when I start Jenkins as service, the repo (through the proxy) cannot be accessed and I get this error message:
Please note that if I look at the System Properties in System Information section, the proxy parameters appear the same in both cases so the configuration is being applied properly:
Apparently there is a difference in how Jenkins starts up depending on how it was started (command line or windows service). What reinforces this assumption is that I see that some log files are only being written when I start Jenkins as a service but not when I start it from command line. I am talking about these log files:
jenkins.wrapper.log
jenkins.out.log
What do I need to do differently to get the same result from Jenkins as service as I do when I start it from command line? What configuration am I missing?

Jenkins as a Windows service doesn't run under your current user but under the LocalSystem Account by default.
See MSDN: Using the LocalSystem Account as a Service Logon Account and SO: The difference between the 'Local System' account and the 'Network Service' account? for the implications.

Related

Cannot debug Java application with Eclipse

I have a Java (Vert.x) application on my machine that I am trying to attach Eclipse to for debugging.
I usually start the Java application in my console like so:
java -jar build/libs/my-app.jar
Upon reading about debugging, I am attempting to start the app as follows:
java -jar build/libs/my-app.jar -Xdebug -Xrunjdwp:transort:transport=dt_socket,address=8001,server=y,suspend=n
The app seems to start up in the console fine when I run this.
I then go into Eclipse, and try to connect to the app via debugging via Run -> Debug Configurations. This is what my debug configuration looks like:
When I click debug, I get an error box that pops up and says that the connection is refused (I covered the name of my real app). See below:
What am I doing wrong? How can I get remote debugging to connect to my app with Eclipse?
According to my reading of this JDWP documentation, your -Xrunjdwp option is incorrect:
-Xrunjdwp:transort:transport=dt_socket,address=8001,server=y,suspend=n
should be
-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n
If your system has multiple IP addresses, there could be some confusion about which IPs the agent is listening for connections on. You could force a specific address; e.g.
-Xrunjdwp:transport=dt_socket,address=127.0.0.1:8001,server=y,suspend=n
and use the matching IP and port in the Eclipse debug connection parameters.
AND ... as Dave Thompson spotted ... all JVM options must be placed before the -jar argument. (Anything after the -jar name.jar will be treated as command line arguments for your application.)

Spring boot App not working after ssh logout

So I'm deploying my Spring Boot application on an Ubuntu LTS Server. It is built with maven and running with embedded Tomcat.
I'm still new to the deployment process, what I did was:
Log into server via ssh
use scp to upload my_application.zip
unzip it in ssh
java -jar my_application.jar
Now all of that works perfectly fine and I've been using it like that for quiet some time. Now I have to make the Application to stay online and available after logging out of the shell.
I have read some documentation about running processes in background on Linux and I've tried it with nohup java -jar myApplication.jar &, with the screen command and with bg. All of them worked fine while I'm logged into the ssh.
Here comes my problem:
As soon as I end the ssh session the Web App is still available (so the process clearly didn't stop) but it just looks & behaves really weird.
CSS is not applied, JS does not work etc.
My guess would be that some paths or file system accesses are messed up, but I have no idea at all how that could origin from the ssh session.
(When I log back into ssh everything is working fine again)
Would be great if someone has a clue here
If your server has encrypted home directory, it will get re-encrypted once you log out and therefore your script will stop working. It does not have a lot of sense to have encrypted homes on servers so you can disable it.
Or just run the script from different directory and avoid working with files under home directory.
I think you should use systemd for this case.
Also You can add new system user for your app.
You can find more information here:
Spring Boot: 59.2.2 Installation as a systemd service
Ubuntu Wiki: Systemd For UpstartUsers
For example:
Create file myunit.service
[Unit]
Description=MySpringService
After=syslog.target
After=network.target
After=mysql.service
[Service]
Type=forking
PIDFile=/work/www/myunit/shared/tmp/pids/service.pid
WorkingDirectory=/work/www/myunit/current
User=myunit
Group=myunit
Environment=RACK_ENV=production
OOMScoreAdjust=-1000
ExecStart=/usr/local/bin/bundle exec service -C /work/www/myunit/shared/config/service.rb --daemon
ExecStop=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state stop
ExecReload=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state restart
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Copy file to /etc/systemd/system/
Run:
systemctl enable myunit
systemctl start myunit

Why doesn't my JBoss AS bin directory contain a run.sh script?

I am running Ubuntu 16.04 and I need to install and run Restcomm JSS7 stack as a JBoss AS Service.
I followed this video tutorial to install JBoss AS 7. Then I set the JBOSS_HOME environment variable to installation directory of JBoss AS 7. As a result, I was able to start the JBoss AS successfully by executing ./run.sh in the bin sub-folder of the installation directory.
Then I followed this guide to install Restcomm JSS7 stack. For that, I downloaded restcomm-jss7-7.4.1404.zip, unzipped it to /opt/ and then navigated to the ss7-jboss sub-directory and then executed ant deploy,
and the result was
...
BUILD SUCCESSFUL
which according to the guide is an indication of the service deployed successfully.
Then I am following CHAPTER 4 SECTION 4.1 of this user manual to run it as a JBoss AS Service. According to it,
All you have to do to start the Service is start the JBoss AS. This
will automatically start the SS7 Service. To start the JBoss Server
you must execute the run.sh (Unix) or run.bat (Microsoft Windows)
startup script in the /bin folder (on Unix or
Windows).
TWO PROBLEMS:
My <jboss_install_directory>/bin does NOT have a run.sh script. Because of this reason, I tried by running JBoss AS by using the regular standalone.sh script.
Next in the user manual, it is stated:
Result: If the service started properly you should see following lines
in the Unix terminal or Command Prompt depending on your environment:
(Note: I have pasted the following excerpt from user manual here, since it is too long to paste in this question.)
But I see none of those lines in my terminal. Rather, my terminal output of running ./standalone.sh is pasted here.
So I don't know how and where to proceed from here. Please help.
NOTE: This question is NOT a duplicate of my other question. Like I mentioned in the question titles, this question is about why my JBoss AS installation doesn't contain a run.sh script, and what would be its alternative. The other question is about some possible command to find out the JBoss Services started when it is running? When a beginner is starting to learn something, their entire purpose Not getting the job done. They have many confusions/questions in their mind.
The documentation documents how to start a JBoss 5.1 server but your installation uses a JBoss 7.1 server, which is why you have to use standalone.sh instead of run.sh to start the server and why the logs are different.
Since you correctly reach the JBoss AS 7.1.0.Final "Thunder" started in 3955ms line I wouldn't worry too much (except about using a documentation that is clearly outdated).
The documentation of your product only declares compatibility with JBoss 5.1.0. While it may work on later releases, you might want to check if there's a more recent version of your product. I wouldn't recommend installing JBoss AS 5.1.0 as it isn't supported anymore and will contain security breaches.

Problems about Jenkins running remote shell script

I have some question when using jenkins.
the scenario:
I have installed a tomcat on machine A,and config all necessary environment including JDK, and they work well.
I wrote a shell script named restart.sh to kill the tomcat process,and restart.
I execute the script and it works well.When I check the tomcat process using ps -ef,and it shows the exact JDK path as I already config.The JDK path is /usr/local/java/JDK7
When I execute the restart.sh script via jenkins,problem comes. I can see the tomcat process using the wrong JDK path,/usr/bin/java,not the path as i config. I use SSH Publishers plugin to run the remote script.see as the image below:
enter image description here
I don't know how this problem happen,please help,Thanks all
This might be the problem of path variables, just to cross verify , find JAVA_HOME on your server 1. By logging onto server manually 2. From Exec command of your ssh section of your jenkins job , most probably you will find the answer.
i'm assuming you're jenkins is configured to use jdk which is defined at its root level.
if this didn't solve , we need to look into this problem from another angle.

Install4j: installing a service

For my installation, I am trying to install both my database server (which is postgresql) and my application server as services. I know it is possible to install postgres using pg_ctl from console by starting it as admin. But as far I know it is not possible for java to start cmd.exe in administrative mode. So I was hoping to be able to achieve it by Install4j. I saw the sample "hello" project. But there it creates a launcher. But in my case for postgresql I need to run the pg_ctl along with some arguments. And for application server I have my own batch file as the executor. For PGSQL I have tried giving windows arguments i.e. -N service_name -D data_folder. But for both cases it fails to start the service. I also tried manually from the Services menu in Windows it fails to start. I have the account setting as "local system".
I have also tried running pg_ctl using "run executable or batch file" action but still I could not find the service in the windows services list, not to mention the same arguments work fine from command prompt. I have added a figure of the action properties I used in the project.
If your installer has executed a "Request privileges" action and you execute pg_ctl.exe with a "Run executable or batch file" action, it will be executed with admin privileges, because the the default value of the "Action elevation type" property of that action is "Elevate to maximum available privileges".

Categories

Resources