Skip to content

Commit

Permalink
Improve init.d and systemd services
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierayache committed Jan 20, 2018
1 parent 718d1b6 commit e6fc2a3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cassandra-repair-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
--> <dependency>
-->
<!-- <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependency>-->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>automaton-api</artifactId>
Expand Down Expand Up @@ -303,6 +304,7 @@
<mapper>
<type>perm</type>
<prefix>/etc/init.d</prefix>
<filemode>755</filemode>
</mapper>
</data>
<data>
Expand Down
2 changes: 1 addition & 1 deletion cassandra-repair-scheduler/src/deb/control/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Architecture: all
Maintainer: Olivier Ayache
Description: Cassandra administration tools
Distribution: development
Depends: default-jre (>= 1.8) | openjdk-8-jre-headless | oracle-java8-installer
Depends: default-jre (>= 1.8) | openjdk-8-jre-headless | oracle-java8-installer
8 changes: 8 additions & 0 deletions cassandra-repair-scheduler/src/deb/control/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
if [ $(cat /proc/1/comm) = "init" ]
then
update-rc.d cassandra-repair-scheduler defaults
elif [ $(cat /proc/1/comm) = "systemd" ]
then
systemctl enable cassandra-repair-scheduler.service
fi
5 changes: 5 additions & 0 deletions cassandra-repair-scheduler/src/deb/control/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
if [ $(cat /proc/1/comm) = "init" ]
then
update-rc.d cassandra-repair-scheduler remove
fi
8 changes: 8 additions & 0 deletions cassandra-repair-scheduler/src/deb/control/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
if [ $(cat /proc/1/comm) = "init" ]
then
invoke-rc.d cassandra-repair-scheduler stop
elif [ $(cat /proc/1/comm) = "systemd" ]
then
systemctl disable cassandra-repair-scheduler.service
fi
6 changes: 4 additions & 2 deletions cassandra-repair-scheduler/src/deb/filtered/init.d/service
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ do_stop()
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
Expand Down Expand Up @@ -150,4 +150,6 @@ case "$1" in
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
esac

exit 0
6 changes: 5 additions & 1 deletion cassandra-repair-scheduler/src/deb/filtered/systemd/service
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ WorkingDirectory=/var/lib/${artifactId}
EnvironmentFile=/etc/default/${artifactId}
Type=simple
ExecStart=/usr/bin/java -Dcassandra.lib.directory=/usr/share/${artifactId}/cassandralibs/ ${EXTRA_JAVA_OPTS} -jar /usr/share/${artifactId}/${project.build.finalName}.jar -jh ${JAXRS_HOST} -jp ${JAXRS_PORT}
Restart=on-failure
Restart=on-failure
SuccessExitStatus=143

[Install]
WantedBy=mutli-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
Expand Down Expand Up @@ -86,6 +88,13 @@ public static void main(String[] args) throws IOException, InterruptedException,
}
}
}

Runtime.getRuntime().addShutdownHook(new Thread("ShutDownHook-Thread"){
@Override
public void run() {
server.stop();
}
});
}

}

0 comments on commit e6fc2a3

Please sign in to comment.