Setting up the dockerized IGWEB service

Setting up the systemd service for the dockerized igweb is pretty straightforward. Here are the contents of the igweb-docker.service file, which should be placed in the production system's /etc/systemd/system directory:

[Unit]
Description=Dockerized IGWEB
After=docker.service
Requires=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/igb/igweb
ExecStart=/usr/bin/docker-compose -f /opt/igb/igweb/docker-compose.yml up -d
ExecStop=/usr/bin/docker-compose -f /opt/igb/igweb/docker-compose.yml down

[Install]
WantedBy=multi-user.target

In the [Unit] section, we have set the After directive with the value docker.service. This indicates that the docker unit must be started before the igweb-docker unit. The Requires directive has also been set with the value docker.service. This indicates that the igweb-docker unit is dependent on the docker unit to successfully run. Failure to start the docker unit will result in a failure to start the igweb-docker unit.

In the [Service] section, we have set the Type directive to oneshot. This indicates that the executable we are launching is short-lived. It makes sense to use it because we will be running docker-compose up with the -d flag specified (detached mode) so that the containers run in the background.

We have specified the RemainAfterExit directive in conjunction with the Type directive. By setting the RemainAfterExit directive to yes, we indicate that the igweb-docker service should be considered active even after the docker-compose process exits.

Using the ExecStart directive, we start the docker-compose process in detached mode. We have specified the ExecStop directive to indicate the command that is needed to stop the service.

In the [Install] section by setting the value for the WantedBy directive to multi-user.target, we specify that this service has a system runlevel of 3 (multi-user mode).

Recall that after placing the igweb-docker.service file in the /etc/systemd/system directory, we must reload the systemd daemon like so:

$ systemctl daemon-reload

Now, we can start the dockerized igweb application:

$ systemctl start igweb-docker

You may use the systemctl enable command to specify that igweb-docker should be started on system startup.

We can take down the service by issuing the following command:

$ systemctl stop igweb-docker

At this point, we've demonstrated how to run the igweb application as a multi-container Docker application hosted on the Linode cloud. Again, although we are using Linode, the procedure that we have demonstrated can be replicated on your preferred cloud provider of choice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36