Debian – Is /etc/rc.local a good place to run a script before any (normal) user can log in

bootdebianUbuntu

I have a Ubuntu 14.04 Server which, during boot, should sync some stuff over the network before any normal user can log in (over ssh).

I was wondering whether calling the script from /etc/rc.local is the right place?

Looking at the comment of this script:

This script is executed at the end of each multiuser runlevel.

It looks like it is called after the system is ready to accept logins from users.

This is how I understand the "at the end of each multiuser runlevel".

I have seen the answer here: Purpose and Typical Usage of /etc/rc.local, I still found it a little ambiguous.

UPDATE

A little more context is appropriated: It is an automated process, where user are actually many machines polling the server to log in….

Best Answer

Usually /etc/rc.local is the valid option, but it also depends on the amount of work that is involved in "syncing some stuff" and how important it is that users cannot login before this action has completed.

If you want to make sure that the syncing has completed before users login, you can consider one of two "nologin" options.

  1. Write a script that sets the login shell (of a particular group of users) to /usr/sbin/nologin before syncing and restores it after syncing.

  2. Create an empty /etc/nologin file before syncing using touch /etc/nologin and remove it after syncing. Note that this option may easily lock you out if you disabled logging in as root over SSH, since it prevents all non-root accounts from logging in.

Related Question