Installing Spring Boot Services in Ubuntu as a systemd (II)

Spring manual for installing services in Unix/Linux is easy and straightforward to follow. Here you will find a resume and some tips for the most common errors I faced when installing. I highly encourage you to install it as systemd better than as init.d, if the server restarts the services will restart too.
  1. Create the file
    vim /etc/systemd/system/name.service
  2. Copy in the file the following, remember to update the names of the folder and the service, as well as the user
    [Unit]
    Description=name
    After=syslog.target
    
    [Service]
    User=user
    ExecStart=/var/name/name.jar
    SuccessExitStatus=143
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable the service
    systemctl enable name.service
  4. Launch the service
     systemctl start name.service
    or like with init.d
     service name start
  5. Check that the service is launched and/or the states. If it's running you should see the following:
    ps -ef |grep java
    >> root      57772  57740 22 02:19 ?        00:00:12 /usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /home/user/services/Name-1.1.jar
    or get more details typing:
     systemctl status name.service
    ● name.service - name
       Loaded: loaded (/etc/systemd/system/name.service; enabled; vendor preset: enabled)
       Active: active (running) since Tue 2018-06-05 02:19:00 UTC; 19min ago
     Main PID: 57740 (Name-1.1.jar)
    
If it is not running correctly these are some of the issues you may have:
  1. The file name for the service is not created correctly in the folder /etc/systemd/system/name.service
    Failed to start name.service: Unit name.service not found.
  2. The user name that is lunching the service does not match with the user name specified in the systemd file
    Jun 05 02:14:56 WT systemd[1]: Started name.
    Jun 05 02:14:56 WT systemd[57459]: name.service: Failed at step USER spawning /home/user/services/Name-1.1.jar: N
    Jun 05 02:14:56 WT systemd[1]: name.service: Main process exited, code=exited, status=217/USER
    Jun 05 02:14:56 WT systemd[1]: name.service: Unit entered failed state.
    Jun 05 02:14:56 WT systemd[1]: name.service: Failed with result 'exit-code'.
    
  3. Other issues: Check that your maven file is configured correctly to create the ‘fully executable’ jar.
    Jul 16 01:19:19 WT systemd[1]: Started name.
    Jul 16 01:19:20 WT systemd[28056]: name.service: Failed at step EXEC spawning /home/user/services/Name-1.1.jar: Exec format error
    Jul 16 01:19:20 WT systemd[1]: name.service: Main process exited, code=exited, status=203/EXEC
    Jul 16 01:19:20 WT systemd[1]: name.service: Unit entered failed state.
    Jul 16 01:19:20 WT systemd[1]: name.service: Failed with result 'exit-code'.
    

Comments