Posts
Search
Contact
Cookies
About
RSS

OpenRC stacked runlevels - (for different usage modes)

Added 20 Aug 2015, 10:44 p.m. edited 18 Jun 2023, 1:12 a.m.
I've recently installed an Apache Mysql Php stack on my laptop, and you can only imagine my horror at the extra second or so its added to the less than 5 second boot time! Lets face it with modern hardware boot time if a fairly moot issue (even with multiple containers - but thats another devisive issue!) but I'm of the habbit of switching stuff off while I'm not using, its not every day I'm writing C or Java code and likewise its not everyday I'm trying out some web app experiment - Even although its all configured to only serve to itself its still using resources and could be a theoretical security hole as its running developing applications, so its useful to be able to put the machine into "web development mode" and also importantly to switch the same off. While at the moment I only have Apache and Mysql running its likely I may other services to add later. Open-rc allows you to "stack" or include other run-levels within another run-level. This means you can have a run-level just mentioning the additional services you want and include the "default" run-level. Creating the new run-level is very simple
install -d /etc/runlevels/webdev
so now we can (again very simply) add our services
rc-update add apache2 webdev
 * service apache2 added to runlevel webdev
rc-update add mysql webdev
 * service mysql added to runlevel webdev
Of course if you've previously added them to the default run-level you will want to remove them
rc-update delete apache2 default
 * service apache2 removed from runlevel default
rc-update delete mysql default
 * service mysql removed from runlevel default
and now to stack the default run-level onto our new run-level
rc-update -s add default webdev
 * runlevel default added to runlevel webdev
and thats it, it really is that simple! A quick test (assuming apache and mysql are stopped)
rc webdev
 * Checking mysqld configuration for mysql ... [ ok ]
 * Starting mysql ... [ ok ]
 * Starting apache2 ... [ ok ]
changing from default --> webdev only the two services that aren't already started get started... ...and after out web app creation session
rc default
 * Stopping apache2 ... [ ok ]
 * Stopping mysql ... [ ok ]
and again only the two different services are effected. Of course if you decide you're going to be busy for a month or so with web development you can always add
softlevel=webdev
to your kernel command line parameters in grubs config, you could even have two seperate selections in grub, although there is nothing stopping you changing run-levels at any time you want. shock horror no source code for you to download this time!