0

I'm new to Ubuntu, and I want to run a (java maven) command which starts a web server embedded with my web application, on a remote Ubuntu server.

I can run it with following bash command (typed directly to remote console):

#!/bin/bash
cd /path/to/mywebapp-dir
mvn exec:java >> /opt/mywebapp.log

My web application keeps alive UNTIL I enter some key OR log out from console.

I want to keep it alive after I log out, so I made a following systemctl service:

[Unit]
Description = mywebapp daemon

[Service]
ExecStart = /opt/mywebapp.sh # bash from above
Restart = no
Type = simple # also tried "forking", but couldn't get rid of PID file error.

[Install]
WantedBy = multi-user.target

But when I start the service, it seems to be shutting down right after the maven command has been successfully completed, and won't keep the web application (which I assume to be a child process) alive.

How can I make it happen?

  • Create a pid file and let systemd monitor it. – Gerald Schneider Mar 05 '18 at 13:50
  • @GeraldSchneider Thanks, I tryed but got "PID file is not readable (yet)" error. I changed service type to "forking", added "PIDFile" key and value, created the empty pid file, chmod 666, and reloaded systemd settings. – Hirofumi Okino Mar 05 '18 at 14:55
  • What is in that shell script? You generally should not call shell scripts from a systemd unit; you should put that logic in the unit and then call the application directly. – Michael Hampton Mar 05 '18 at 15:39
  • @MichaelHampton Thanks, shell script mywebapp.sh has exactly the same command as I was typing directly (which are: cd , mvn). I was convinced that the "shell script" itself is equal to "systemd unit" but you sound different. Is systemd unit equal to the service file? It would be great if you can show me the full example. And I realized that the empty pid file (in fact) causes a "invalid argument" error, and the pid file is deleted, then the 2nd "start" will cause the "not readable (yet)" error. I'm totally in a wonderland. – Hirofumi Okino Mar 05 '18 at 15:59

0 Answers0