Is it doable to get a clean reboot from in an init script?

My init script may change other init scripts, including the numbered S/K script symlinks typically found in /etc/rcN.d in many Linux distros. The script will be coded to know what and where. This will run in an AWS EC2 instance from a custom AMI, so my script will be there at first boot and other init scripts can be already have been made inactive, by having only K links or no links at all...

So there is no need to bring other apps back down, the objective is to load a unique new /etc with its particular init scripts and have it all run and startup as changed.


Yes you can reboot the system from an init script, at least on Ubuntu 12.04, but I see no reason why other systems could not.

While experimenting, just be extra careful that you don't get into a continuous reboot loop. When I did this I first made an init script that exited prematurely if a particular file did not exists, and deleted that file, directly after the check, if it did exist. And tested that before proceeding.

You should stop the scripts before you change their K links, but you probably already do. If you also start processes for which you make S links, in theory it is not necessary to reboot, but I can imagine that the changes are better checked directly for correctness, than after some future reboot.

  • yes, i will check to avoid a reboot loop. deleting my script can do that i think. – Skaperen Feb 21 '15 at 12:11
  • the plan is that the AMI i build will not, on its own, start anything except maybe sshd in the test versions. – Skaperen Feb 21 '15 at 12:13
  • @Skaperen I would think deleting should do the job, or deleting the S/K links to the init script. – Anthon Feb 21 '15 at 12:15
  • in most cases my script will replace all of /etc from an S3 object (in tar.xz format) or attach a new root volume from EBS. – Skaperen Feb 21 '15 at 13:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.