3

Due to legacy (aka corporate) reasons, I have a number of servers running recent Debian versions (Debian 9, Debian 10) that also need to run older services such as MySQL 5.5. This is done via a (pre-existing) Debian Jessie schroot (that was built using this guide ) that has the services installed and copies the users from the host.

However, I have not been able to find a simple, trustable means to have the services living within that schroot to start at boot time when the schroot is from a user ie.: the schroot is run by one of its root-users, not necessarily by root.

We have a script to start the schroot:

#at /usr/local/bin/start-legacy.sh
schroot -b -c legacy_schroot -u root -n Session

(this can be run by the schroot's root-user user)

And a crontab to invoke at boot time:

#at the root-user user's crontab -e
@reboot /usr/local/bin/start-legacy.sh

However I can't seem to find a means to pass commands to this schroot session at boot time, so as to have it start the services. The following things all don't work:

1.- Pass the commands immediately during the startup script:

#at /usr/local/bin/start-legacy.sh
schroot -b -c legacy_schroot -u root -n Session
schroot -r Session -u root -- service mysql start

When done this way, it works perfectly when a user logins and runs the script manually, but when running from a crontab it only starts the session and doesn't pass the following commands. It doesn't seem to report an error either, or if it does I can't find it.

2a.- Adding the startup to the crontab

#at crontab -e
@reboot /usr/local/bin/start-legacy.sh
@reboot sleep 10 && bash -l -c 'schroot -r -c Session -u root -- service mysql start'

If I do this at crontab, the same effect as above: the script is started OK, but the startup commands are never passed.

2b.- Adding the startup scripts to a command at crontab

#at crontab -e
@reboot /usr/local/bin/start-legacy.sh
@reboot sleep 10 && bash -l -c '/usr/local/bin/start-legacy-mysql.sh'

(where the second script has the schroot -r command)

Same difference.

3.- Using /etc/rc.local

#at /etc/rc.local
su usuario -l -c '/usr/local/bin/start-legacy.sh'
su usuario -l -c '/usr/local/bin/start-legacy-mysql.sh'

exit 0

This only works without the 'su', making the schroot session be started by root; but I need to run the session as the normal user so users can connect to the schroot afterwards. With the su, it's giving a "Not Authorized" error that I can't fetch because I can't find the boot logs except for dmesg's and the screen clears during the boot.

Even if it worked, this requires root to setup, which the crontab solution doesn't. I personally don't mind, but I don't think the bosses will want to give root access to the technicians whose only task is to deal with MySQL to set this up.

tl;dr: I want to have during boot a number of commands to be run on behalf of a user to perform various tasks on a schroot of which the given user is root.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.