Configuring your jar file as a service on the linux instance

  • 1. create a unit file located in /etc/systemd/system

    $ sudo vi /etc/systemd/system/demo.service

  • 2. add thees lines to the file
  • [Unit]
    Description = a demo service
    After = network.target
    [Service]
    ExecStart = /home/ubuntu/scripts/demo.sh
    [Install]
    WantedBy = multi-user.target

  • 3 . create a directory named 'scripts' in the main root
  • $ cd


    $ mkdir scripts


  • 4. create a file demo.sh using vim
  • $ sudo vi /scripts/demo.sh


  • 5. add the next lines to the file assuming your demo.jar file is located in the/home/ubuntu directory .
  • #!/bin/bash
    sudo java -jar /home/ubuntu/demo.jar

    insert ( by clicking the 'i' key) and add the following changes. click the 'esc' key and then ':wq' saving the changes to the file.

  • 6.make the script executable
  • $ sudo chmod +x demo.sh


  • 7. back to your main dir and enable the service by
  • $ sudo systemctl enable demo.service


  • 8. start your service
  • $ sudo systemctl start demo.service


  • 9. reboot and check if the service is on
  • $ sudo reboot


  • 10. babam !!
  • now everthing is complete … you are ready to do great things !!!