I have some scripts to start and stop a java application which using jenkins.

  1. First option

    Check the port and kill pid if java is running. And then start the application.

  2. Second Option

    Write the pid which running on specific port and kill. Then start the application.

Which one is more accurate? If I used second option I cannot run as a systemd service. Because it is only killing accessing pid file creating while starting the application.

Note: I am not using containers. Just using jenkins shell scripting.

  • Hi and welcome! Are containers an option for you? You can very easy start and stop them. – Peter Dec 17 '18 at 4:57
  • 4
    Why not using systemd commands ? – Tensibai Dec 17 '18 at 9:40
  • I tried to do that. But failed to figure out a solution. Can I store below commands in systemd and call from jenkins? [Unit] Description=Test Background [Service] ExecStart=/bin/bash -c "/usr/bin/java -jar /var/www/test.com/*.jar" Type=simple WorkingDirectory=/var/www/test.com [Install] WantedBy=multi-user.targe – Janith Dec 17 '18 at 9:49
  • Showing what you tried is good, but it would be easier to read if you edited this into the original question. – chicks Dec 17 '18 at 12:18
  • 2
    i guess the best method to start and stop an application is to create the application as a systemd service and put the app in /etc/systemd/system directory. In this way you will have the option to start, restart and stop your service – Sunil Dec 20 '18 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.