-1

I want to run an Spring Boot application as a service in Ubuntu 16.04. I created a symbolic link to my executable JAR file

$ sudo ln -s /home/canperis/core-price-update/menu-core-prices-update-0.0.1-SNAPSHOT.jar \
    /etc/init.d/menu-core-prices-update

$ sudo service menu-core-prices-update start

but I have this error:

Failed to start menu-core-prices-update.service: Unit menu-core-prices-update.service not found.

slm
  • 369,824
en Peris
  • 361
  • If you're on a more recent distro you should be creating a systemd unit file, not a SysV init script. – slm Jul 20 '18 at 19:30

1 Answers1

1

Since you mentioned Ubuntu, most newer versions now support systemd. To set something like this up using systemd you'd create a systemd unit file and then enable it.

1. Software

First decide where you want to locate your software. I'd recommend /opt/core-price-update.

Something like this:

$ tree /opt/menu-core-prices-update/
/opt/menu-core-prices-update/
├── application.conf
└── menu-core-prices-update-0.0.1-SNAPSHOT.jar

0 directories, 2 files

2. systemd unit file

Next create a systemd unit file like this:

$ cat /etc/systemd/system/menu-core-prices-update.service
[Unit]
Description=Menu Core Prices Update Daemon
After=network.target

[Service]
Environment="APP_CP=/opt/menu-core-price-update"
Environment="JAVA_HOME=/usr/java/latest"
Environment="APP_NAME=com.myapps.MenuCorePriceUpdate"
Environment="APP_NAME_JPROP=appname=menu-core-price-update"
Environment="CONFIG_FILE=/opt/menu-core-price-update/application.conf"
Environment="LOGPATH=/var/log/menu-core-price-update"
ExecStartPre=/bin/mkdir -pm 0755 ${LOGPATH}
ExecStart=/bin/bash -c "$JAVA_HOME/bin/java -D${APP_NAME_JPROP} -cp ${APP_CP} ${APP_NAME}"
PIDFile=/run/core-price-update/menu-core-price-update%i.pid
Restart=on-abort
RuntimeDirectory=menu-core-price-update
RuntimeDirectoryMode=755
WorkingDirectory=/opt/menu-core-price-update

[Install]
WantedBy=multi-user.target

3. Enable service

To enable this service to run between reboots:

$ sudo systemctl enable --now menu-core-prices-update

References

slm
  • 369,824