1

I have installed distribution packages of Redis and Tomcat on Ubuntu 18.04. I'm trying to start the Tomcat only after a successful start of Redis, but so far no luck.

  • The tomcat8 package has sysv init script in /etc/init.d/tomcat8 and I see the generated /run/systemd/generator.late/tomcat8.service.

  • Redis-server package has the service unit in /lib/systemd/system/redis-server.service

I have created a symlink to redis-server in these directories:

ln -s /lib/systemd/system/redis-server.service  /etc/systemd/system/tomcat8.service.requires/redis-server.service
ln -s /lib/systemd/system/redis-server.service  /etc/systemd/system/tomcat8.service.after/redis-server.service

However if I purposedly provoke that Redis fails to start, Tomcat starts anyway. I want Tomcat to not to start in case Redis fails.

I see this output of the Tomcats' service status command, with "Dependency failed for LSB", but Tomcat started anyway:

root@elkarel:/home/elkarel# service tomcat8 status
  tomcat8.service - LSB: Start Tomcat.
   Loaded: loaded (/etc/init.d/tomcat8; generated)
   Active: active (running) since Mon 2019-07-01 14:57:51 CEST; 2min 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 690 ExecStart=/etc/init.d/tomcat8 start (code=exited, status=0/SUCCESS)
    Tasks: 44 (limit: 2340)
   CGroup: /system.slice/tomcat8.service
           └─737 /usr/lib/jvm/java-8-oracle/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.head

Jul 01 14:57:45 elkarel systemd[1]: Starting LSB: Start Tomcat....
Jul 01 14:57:45 elkarel systemd[1]: Dependency failed for LSB: Start Tomcat..
Jul 01 14:57:45 elkarel systemd[1]: tomcat8.service: Job tomcat8.service/start failed with result 'dependency'.
Jul 01 14:57:46 elkarel tomcat8[690]:  * Starting Tomcat servlet engine tomcat8
Jul 01 14:57:51 elkarel tomcat8[690]:    ...done.

I execute systemctl daemon-reload every time I make any change.

I didn't alter the package files and I don't want to, but now I doubt if is it even possible to declare such dependency only with symlinks.

elkarel
  • 121
  • 5
  • Can you write a proper systemd unit for Tomcat? Where did the ancient sysv script come from anyway? – Michael Hampton Jul 01 '19 at 18:05
  • Hi MIchael, I could, but the "ancient" sysv script comes directly from the official Ubuntu Tomcat .deb package, so I thought there might be a cleaner way to do it. Besides I'm not familiar with systemd yet. – elkarel Jul 01 '19 at 19:35

0 Answers0