Dependency on Server at Boot

Mark GrantMark Grant
3 min read

Naming

The names and descriptions used in the package and this post are:-

Package name: server-dependency

Package description: Dependency on server at boot

Short name (used in some files / directories): dosab

Example environment used in this post

The simplest explanation is to use an example and this example probably represents the most common usage scenario.

You have a laptop which you use at home or in the office which uses services only available in this LAN setting. ie When away from this location these services cannot be accessed but a replacement configuration may be required. These services could be:-

  1. On your LAN you access an NFS share on an internal only server. Away from your LAN this setup must be skipped.

  2. On your LAN you access a local internal only software package repository (a Debian repo in this example). Away from your LAN this must be skipped.

Implementation

The server-dependency package works by installing a systemd service which runs at boot. This service checks connectivity with the server(s) in question and then either alters the configuration files of other packages or runs specified commands. So in this example we need to do the following:-

  1. Install the package.

  2. Specify the servers to check.

  3. Setup the share.

  4. Setup the LAN based repository.

  5. Reboot the machine.

Installation

Install the package. To prevent bitrot by unnecessary duplication of information, please follow the instructions on my GitHub wiki at:- https://github.com/m-grant-prg/server-dependency/wiki and choose the relevant installation method from the menu.

Servers to check

Inform the package with which servers we need to check connectivity. This involves editing the package server.list file and entering server names, 1 per line. The example shows vim as the editor but use your own preference.

Command to edit the server.list file.

Editing the server.list file.

Set up the share

Setting up the share involves 2 actions:-

  1. Add the command to mount the share if the server is available to the .available file (in this example hermes.available).

  2. Ensure that the share in fstab is not auto-mounted.

(We do not need to take any action if the server is unavailable as we are just omitting to mount it).

Command to edit the server available file.

Setting up the share in the server available file.

Command to edit the fstab file.

The screenshot below shows only the share entry, yours will, of course, have all your device entries in it.

Setting up the share in fstab.

Set up the LAN based repository

Setting up the LAN based repository requires 3 steps:-

  1. Create the APT XXXXX.list file for the repository.

  2. Edit the .available file to insert the required commands.

  3. Edit the .unavailable file to insert the required commands.

Command to edit hermes.list.

Setup the local repository list file.

Command to edit the server available file.

Setup the local repository in the server available file.

Command to edit the server unavailable file.

Remove the local repository in the server unavailable file.

And finally…

Please reboot the machine.

Authoritative sources

I shall attempt to keep this post accurate and updated, however, the ultimate repository of everything to do with this project is held on GitHub.

The code repository:- https://github.com/m-grant-prg/server-dependency

The wiki:- https://github.com/m-grant-prg/server-dependency/wiki

If you have any issues or discover a bug, please register it at:- https://github.com/m-grant-prg/server-dependency/issues

My Projects

0
Subscribe to my newsletter

Read articles from Mark Grant directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mark Grant
Mark Grant

I have spent many years in IT starting as a programmer in C and Basic then moving into general, data centre and infrastructure management. I am now back writing software mostly in bash and C. These are usually in the form of AutoTools projects which are often then packaged for various Linux distributions such as Debian, Raspbian, Ubuntu, Fedora and openSUSE.