This morning we had an awesome question on the Singularity list about “motd.” The idea was simple, and given the potential for fun and helping users to understand containers, I was excited.

What is motd?

If you’ve ever logged into a linux cluster, or played a computer game like Half Life or World of Warcraft, you might be greeted a “message of the day” (motd). There is a bit of history behind it. In short, we print a message to the terminal for the user to see when he or she first logs into a shell.

How can we use motd with containers?

In the context of a container, we might want to give the user a friendly message if they shell inside. The simplest use case is to greet the user. A more useful use case is to provide some help for how to interact with the container, or where to find documentation. In this case, the message of the day becomes a powerful tool for interacting with the user.

How do we add motd to Singularity containers?

If we are creating a Singularity container, we can’t just echo a message in the runscript, because this gets executed on a shell or a run. We need to edit the /.singularity.d/actions/shell script that is executed only on a shell.



Singularity MOTDs

If you want to jump right into code, see the singularityhub/motd repository. Here I have created some getting started examples for you to learn from. For the remainder of this post, I’ll show you what they look like! You can also just watch the asciicast below:

Greeting

The simplest greeting can echo something to the terminal:


$ singularity shell greeting.sif
Singularity: Invoking an interactive shell within container...

Hello, vanessa!

Singularity greeting.sif:~/Documents/Dropbox/Code/singularity/motd/greeting>


Asciiart

This is one of my favorite because it’s relatively simple to install (and then call) figlet.


t$ singularity shell asciiart.sif 
Singularity: Invoking an interactive shell within container...

                                      _ 
__   ____ _ _ __   ___  ___ ___  __ _| |
\ \ / / _` | '_ \ / _ \/ __/ __|/ _` | |
 \ V / (_| | | | |  __/\__ \__ \ (_| |_|
  \_/ \__,_|_| |_|\___||___/___/\__,_(_)
                                        
fwoop! ...you are in a container...

To generate the above, I take advantage of the $USER environment variable, and add a fwoop. See the asciiart folder for the full recipe.

Fortune

I like the command “fortune” because you never know what kind of wisdom is going to pop up.


$ singularity shell fortune.sif
Singularity: Invoking an interactive shell within container...

In India, "cold weather" is merely a conventional phrase and has come into
use through the necessity of having some way to distinguish between weather
which will melt a brass door-knob and weather which will only make it mushy.
		-- Mark Twain

Interesting! We can also throw in some lolcat and cowsay magic to make, of course, lolcow.

https://raw.githubusercontent.com/singularityhub/motd/master/fortune/lolcow.png

See the fortune folder for the recipes used to generate the above.

Help Message

Okay, here is a more useful container example. With Singularity, a few years ago I added the %help section to the singularity recipe. The idea was that if you wrote this section in your Singularity recipe, the user could ask your container for help!


%help

Oh, hi there! This is the help section. Here is how to run the container:
    singularity run <container>

Here is how to shell into the container:
    singularity shell <container>

Here is how to execute a custom command
    singularity exec <container> ls /


But there is one problem here, we are still relying on the user to type that command in the first place! This is a great use case for message of the day

  • we can show this same help script when the user shells into the container! Here is what that looks like:

$ singularity shell helpme.sif 
Singularity: Invoking an interactive shell within container...

Oh, hi there! This is the help section. Here is how to run the container:
    singularity run <container>

Here is how to shell into the container:
    singularity shell <container>

Here is how to execute a custom command
    singularity exec <container> ls /


Singularity helpme.sif:~/Documents/Dropbox/Code/singularity/motd/help> 

It would be appropriate to have paths or other usage that a user shelling into the container might need. This is your opportunity to talk to the user of your container - use it.

Graphic

And for the grand finale (and this example is a bit excessive, but I wanted to have it anyway) we can also show the user a graphic. We use gotermimg to greet the user with a colored image.

https://raw.githubusercontent.com/singularityhub/motd/master/graphic/graphic.png

Clearly, many of these examples are for fun, and others are better for communicating information. I’m of the firm belief that we should aspire for both. Check out the repository for all the recipes, and please post an issue or open a pull request if you have a question or want to contribute.




Suggested Citation:
Sochat, Vanessa. "Message of the Day: Singularity Containers." @vsoch (blog), 24 Jan 2019, https://vsoch.github.io/2019/motd/ (accessed 16 Apr 24).