not sure how to do it in python but for shell scripting would be easy to make apache2ctl a variable which is defined depending on Linux OS detected
for example with centos and default apache 2.2.15 in centos 6 with httpd
yum package would be something like
if apache was installed via httpd
yum package
yum -y install httpd httpd-devel
you will have apachectl at /usr/sbin/apachectl
query what httpd
package installed for binaries
rpm -ql httpd | grep sbin
/usr/sbin/apachectl
/usr/sbin/htcacheclean
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker
/usr/sbin/httxt2dbm
/usr/sbin/rotatelogs
/usr/sbin/suexec
then you'd check and assign variables
if debian and path to /PATH/TO/apache2ctl
exists then assign variable
if centos and path to /usr/sbin/apachectl
exists then assign variable
then just a matter of parsing the output
/usr/sbin/apachectl -V
Server version: Apache/2.2.15 (Unix)
Server built: Aug 24 2015 17:52:49
Server's Module Magic Number: 20051115:25
Server loaded: APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture: 64-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
OS checks
cat /etc/redhat-release
CentOS release 6.7 (Final)
cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
Check for installed version of Apache httpd
package
yum list installed -q | grep httpd
httpd.x86_64 2.2.15-47.el6.centos @updates
httpd-devel.x86_64 2.2.15-47.el6.centos @updates
httpd-tools.x86_64 2.2.15-47.el6.centos @updates
can get tricky as CentOS 6.x defaults to Apache 2.2.15 and CentOS 7.x defaults to Apache 2.4.6 and layout can differ
I'm guessing for the widest range of Apache compatibility, you will need to reach out to the following folks to get their input and information one how Apache is setup in their envionrments
- CentOS, Redhat, Fedora
- Cpanel/WHM
- DirectAdmin
- Odin/Plesk
- Virtualmin
- Webmin
- Ubuntu
- Amazon EC2 folks as Amazon AMI image uses Apache 2.2.31 custom RPM build