title: Spring Boot (Tomcat) based application as daemon - howto stop?
body: <p>I wrote a <strong>Spring Boot</strong> webservice that uses an <strong>embedded tomcat</strong> as container.</p>
  
  <p>In case the system reboots I want to backup some information to a mysql database. </p>
  
  <p>In my webservice I use <code>@Scheduled()</code> and <code>@PreDestroy</code> to run the backup. </p>
  
  <p>This goes well when I stop the server with ^C. </p>
  
  <p>But when I kill the process with an <strong>sysV skript</strong> (<code>/etc/init.d</code>) and the kill command - even though the daemon has a dependency on mysql, the mysql server is shut down before the backup is finished (resulting in SQL Exceptions in my log). </p>
  
  <p>The reason for this is of course, that kill only sends a signal to stop the process. </p>
  
  <p>How can I (from my sysv skript) synchroneously stop the running spring boot tomcat server? </p>