Wednesday, September 4, 2013

Notes on dealing with init.d and Upstart

An issue I've ran into of late, concerns the deployment of a standardized application across different Linux servers. There is no completely consistent method of causing a program to run across multiple distributions as a service.


There are two major versions of Upstart in use right now. One is version 0.6.5: its used in CentOS / RHEL 6.x , and Ubuntu 10.04 LTS. The other is version 1.4 or newer: its used from Ubuntu 12.04 LTS and onward.

The following is censored version of an upstart script I assembled from online resources: Upstart Cookbook & UpstartHowto. The idea is to invoke a second script to do all the application work: the function of the startup script should be just that. But for security reasons, I need that script to run as a specific user. If its an older Ubuntu, or a RHEL/CentOS system, I could uncomment the "exec sudo" line (and I still haven't tested that on RHEL/CentOS atm). If its a newer Ubuntu, I can uncomment the "setuid" and "exec" line without sudo.

description "Program"
start on runlevel [2345]
stop on runlevel [!2345]
env PROGDIR=/opt/program
#setuid proguser
#exec /opt/program/
#exec sudo -u proguser /opt/program/
end script


/etc/rc.d/init.d/functions competes with /lib/lsb/init-functions , depending on the distro. Scripts that use the former, can run on RHEL / CentOS 5.x and 6.x systems: these usually use "daemon" and "killproc".  Scripts that use the latter, appear to run on other distributions, and updated Debian/Ubuntu systems. But this difference is why when you install a program on your Linux system, its given startup script may not work: the distributions offer different functions.

No comments:

Post a Comment