Vert.x 3 init.d Script

Let’s say you have a Vert.x 3 application you want to install on a Linux server. But you want the old school way (I mean not the Docker way ☺). So, in other words, you need an init.d script. This post proposes an init.d script that you can use to start/stop/restart a Vert.x 3 application.

Prerequisites

The proposed script assumes your application is packaged as a fat jar. So, your application is going to be launched using java -jar your-fat-jar ....

The script

The init.d scripts have to reply to a set of commands:

  • start : starts the application (if not yet started)
  • stop : stops the application (if started)
  • status : let you know if the application is started or not
  • restart : restart the application

These commands are invoked using:

service my-service-script start
service my-service-script stop
service my-service-script status
service my-service-script restart

In general, service scripts are hooked in the boot and shutdown sequences to start and stop automatically during the system starts and stops.

So, enough talks, let’s look at the script:

Using the script

First download the script from the here.

You need to set a couple of variables located at the beginning of the file:

# The directory in which your application is installed
APPLICATION_DIR="/opt/my-vertx-app"
# The fat jar containing your application
APPLICATION_JAR="maven-verticle-3.0.0-fat.jar"
# The application argument such as -cluster -cluster-host ...
APPLICATION_ARGS=""
# vert.x options and system properties (-Dfoo=bar).
VERTX_OPTS=""
# The path to the Java command to use to launch the application (must be java 8+)
JAVA=/opt/java/java/bin/java

The rest of the script can stay as it is, but feel free to adapt it to your needs. Once you have set these variables based on your environment, move the file to /etc/init.d and set it as executable:

sudo mv my-vertx-application /etc/init.d
sudo chmod +x my-vertx-application

Then, you should be able to start your application using:

sudo service my-vertx-application start

Depending to your operating system, adding the hooks to the boot and shutdown sequence differs. For instance on Ubuntu you need to use the update-rc.d command while on CentOS chkconfig is used

That’s all, enjoy !

Posted on 2 July 2015
in guides
2 min read

Related posts