Initscript to start user-level services

3 posts / 0 new
Last post
#1 Thu, 01/26/2006 - 02:24
Joe's picture

Initscript to start user-level services

Hi all,

I've just created a little initscript for the Virtualmin system that runs, and I thought it might be handy for others. I'm planning to add it to the stock Virtualmin Professional installer in a week or two, after I've had a chance to run it by Jamie and some other folks to be sure there are no security issues with this code (I've certainly thought of the obvious issues, symbolic links in particular, but I wouldn't suggest installing this on a system with untrusted users until it's had more than a few minutes testing and more eyes looking at it than my two).

Anyway, what this script does is pulls out a list of home directories from /etc/passwd, strips out the system users (anything below UID 500), and looks to see if there is an ~/etc/init.d directory containing executable files. If so, it executes each one with an appropriate argument (start|stop). It expects standard shell return values for success/failure and will print out a nice green OK or red FAILED on Red Hat-based systems (I'll expand this to use SUSE style ok/failure messages, etc., before including it in the installer). The scripts thus need to handle start/stop (the script handles restarting using start/stop) input. It allows you to allow your users to run "always on" processes and know that in the event of a server reboot, their services will come back up without user intervention. Most of you don't want that, but if you're hosting high-dollar application server users, they'll appreciate the convenience of this...since otherwise, they might have to resort to clever cronjobs to keep an eye on their processes.

Without further ado, you can get the script here:

It's very nearly wholly untested, and I'm not calling it ready for primetime, but I thought folks might find it interesting. And if you're reading the Hacks forums, you've got to be up for a little adventure now and then.

Installation consists of dropping it into /etc/init.d and setting the executable bit.

And just about any script in any language that accepts a single argument of "start" or "stop", and returns 0 for success and non-zero for failure, will work fine in the user's ~/etc/init.d directory. The script should not provide any additional output to the console as it will really clutter up bootup and shutdown, but logging to the users home directory logs dir would work fine (each script is executed as the user). I'll probably redirect console results for each script to /dev/null, or a standardized log location in the users home directory before calling this script done. In the short term, I just needed something that worked and was clean and reasonably secure.

Thu, 12/28/2006 - 17:30

ohhh now this is nice :)

Can be used for almost anything, not just VM or

Mon, 01/01/2007 - 18:28 (Reply to #2)
Joe's picture

Hey Scott,

Yeah, I thought it was pretty clever. But nobody ever asked any questions or commented on it, so I left it alone for a while and focused on other stuff. I figured I had an oddball situation in needing such functionality on my Virtualmin "real world" system.

Looking at the code, I see a lot of ways I can improve it (I've gotten a lot better at sh scripting since it was originally written, as it has become one of my primary languages due to I've gotten all caught up on mail and bugs, and gotten unpacked (I just moved to California) I'll run through it and clean it up a bit. It definitely works, as is, though. It's been in use for months without incident.

Holler if you have any trouble making it spin. I think I forgot to mention that you need to chkconfig it:

chkconfig --add user.init
chkconfig --level 345 user.init on

Ought to do it.


Check out the forum guidelines!

Topic locked