Vert.x 3 init.d Script

Let’s say you have a Vert.x 3 ap­pli­ca­tion you want to in­stall 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 pro­poses an init.d script that you can use to start/stop/restart a Vert.x 3 ap­pli­ca­tion.

Prerequisites

The pro­posed script as­sumes your ap­pli­ca­tion is pack­aged as a fat jar. So, your ap­pli­ca­tion is going to be launched using java -jar your-fat-jar ....

The script

The init.d scripts have to reply to a set of com­mands:

  • start : starts the ap­pli­ca­tion (if not yet started)
  • stop : stops the ap­pli­ca­tion (if started)
  • status : let you know if the ap­pli­ca­tion is started or not
  • restart : restart the ap­pli­ca­tion

These com­mands are in­voked using:

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

In gen­eral, ser­vice scripts are hooked in the boot and shut­down se­quences to start and stop au­to­mat­i­cally dur­ing the sys­tem starts and stops.

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

...waiting for Gist...

Using the script

First down­load the script from the here.

You need to set a cou­ple of vari­ables lo­cated at the be­gin­ning 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 vari­ables based on your en­vi­ron­ment, move the file to /etc/init.d and set it as ex­e­cutable:

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

Then, you should be able to start your ap­pli­ca­tion using:

sudo service my-vertx-application start

De­pend­ing to your op­er­at­ing sys­tem, adding the hooks to the boot and shut­down se­quence dif­fers. For in­stance on Ubuntu you need to use the update-rc.d com­mand while on Cen­tOS chkconfig is used

That’s all, enjoy !

Next post

Vert.x 3 and PostgreSQL JSON type

One of the interesting features of NoSQL databases is their schema-less mode of operation. This feature is very useful during project prototyping and early development since at early the stages of development of projects all data structures are not clear or have been defined yet.

Read more
Previous post

Vert.x 3 Web easy as Pi

Vert.x Web distinguishes itself from traditional application servers like JavaEE by just being a simple extension toolkit to Vert.x, which makes it quite lightweight and small but nevertheless very powerful.

Read more
Related posts

Unit and Integration Tests

Let’s refresh our mind about what we developed so far in the introduction to vert.x series. We forgot an important task. We didn’t test the API.

Read more

Things to keep in mind concerning CSRF attacks

Eclipse Vert.x like most frameworks provides an anti-CSRF defense. However, no framework can prevent all attack vectors that exist in the web. Therefore, developers need to be aware of some dangers and common attack vectors concerning CSRF defenses.

Read more

Some Rest with Vert.x

This post is part of the Introduction to Vert.x series. Let’s go a bit further this time and develop a CRUD-ish application

Read more