I want to do a nightly "hotclone" of server A to server B. It's recommended that server B be running minimal daemons during this action so I want to create a "minimal" runlevel which pretty much only runs sshd and switch to/from that runlevel in mid-script, ie:
# do some stuff ...
# take services down
telinit 2
# do backup ...
# bring services back up
telinit 3
# do post-backup stuff ...
I want to do a runlevel switch rather than explicitly starting/stopping services so I can use the same script on a number of differently configured machines (different services, some on systemv-init some on systemd). I want to keep it all in one script for maintainability rather than creating a bunch of new initd/systemd start/stop scripts.
So the nature of the question is: * Will telinit stop the script (assume that cron is in both runlevels)? * Does telinit wait for completion or return immediately? * If the above works is it "safe" to do or are the potential problems with the approach? * Is there a better way available using a single script (again I'd prefer to avoid installing a bunch of new init scripts so this thing is largely "self-contained" and portable)