-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #6476: Better rudder-server-root init script #635
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,11 @@ | |
# Required-Stop: $local_fs $remote_fs $network $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Rudder root server | ||
# Description: Rudder root server including all components required to run | ||
# Short-Description: Rudder server | ||
# Description: Rudder server including all components required to run | ||
### END INIT INFO | ||
# | ||
# Copyright (C) 2011 Normation | ||
# Copyright (C) 2011-2015 Normation | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
|
@@ -32,67 +32,188 @@ | |
|
||
# Variables | ||
|
||
## Init scripts | ||
APACHE2_INIT=/etc/init.d/apache2 | ||
if [ ! -x ${APACHE2_INIT} ] && [ -x /etc/init.d/httpd ]; then | ||
APACHE2_INIT=/etc/init.d/httpd | ||
## Colors configuration | ||
ECHO_BIN="/bin/echo -e" | ||
|
||
### Enable colors only if stdout is a terminal | ||
if [ -t 1 ]; then | ||
GREEN="\\033[1;32m" | ||
RED="\\033[1;31m" | ||
BLUE="\\033[1;34m" | ||
PINK="\\033[1;35m" | ||
WHITE="\\033[0;02m" | ||
WHITELIGHT="\\033[1;08m" | ||
YELLOW="\\033[1;33m" | ||
CYAN="\\033[1;36m" | ||
NORMAL="\\033[0;39m" | ||
COPYPASTE="${ECHO_BIN} ${GREEN}---8<---${NORMAL}" | ||
else | ||
GREEN="" | ||
RED="" | ||
BLUE="" | ||
PINK="" | ||
WHITE="" | ||
WHITELIGHT="" | ||
YELLOW="" | ||
CYAN="" | ||
NORMAL="" | ||
COPYPASTE="${ECHO_BIN} ---8<---" | ||
fi | ||
SLAPD_INIT=/etc/init.d/rudder-slapd | ||
JETTY_INIT=/etc/init.d/rudder-jetty | ||
RUDDER_AGENT_INIT=/etc/init.d/rudder-agent | ||
POSTGRESQL_INIT=/etc/init.d/postgresql | ||
|
||
## Active roles | ||
|
||
HAVE_SLAPD=0 | ||
HAVE_POSTGRESQL=0 | ||
HAVE_JETTY=0 | ||
HAVE_AGENT=1 | ||
|
||
### Check slapd's status if we are rudder-inventory-ldap | ||
[ -e /opt/rudder/etc/server-roles.d/rudder-inventory-ldap ] && HAVE_SLAPD=1 | ||
|
||
### Check PostgreSQL's status if we are rudder-db | ||
[ -e /opt/rudder/etc/server-roles.d/rudder-db ] && HAVE_POSTGRESQL=1 | ||
|
||
### Check Jetty's status if we are rudder-webapp or rudder-inventory-endpoint | ||
[ -e /opt/rudder/etc/server-roles.d/rudder-inventory-endpoint ] && HAVE_JETTY=1 | ||
[ -e /opt/rudder/etc/server-roles.d/rudder-webapp ] && HAVE_JETTY=1 | ||
|
||
## Service names | ||
APACHE2=apache2 | ||
if [ ! -x /etc/debian_version ] && [ ! -x /etc/SuSE-release ]; then | ||
# We are not on Debian or SuSE, assuming a RHEL-like system | ||
APACHE2=httpd | ||
fi | ||
RUDDER_SLAPD=rudder-slapd | ||
RUDDER_JETTY=rudder-jetty | ||
RUDDER_AGENT=rudder-agent | ||
POSTGRESQL=postgresql | ||
|
||
## PID files | ||
POSTGRESQL_PID_FILE=`find /var/lib -iname postmaster.pid` | ||
|
||
## Default return code | ||
RETURN=0 | ||
|
||
# Functions | ||
|
||
service_action() | ||
{ | ||
# Arguments: | ||
## Service name | ||
## Action to trigger (start/stop/...) | ||
## Is the role present on this machine (0/1) | ||
|
||
# If the role is present, run the action | ||
if [ ${3} -eq 1 ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use "${3}" to have an understandable message if there is no $3 |
||
service ${1} ${2} || RETURN=${?} | ||
else | ||
echo "Skipping ${1}: The role is not present on this machine." | ||
fi | ||
} | ||
|
||
service_status() | ||
{ | ||
# Arguments: | ||
## Service human-friendly name | ||
## Service name | ||
## String to search for in the service status as an "OK" condition | ||
## Is the role present on this machine (0/1) | ||
|
||
${ECHO_BIN} -n " * ${1}\t" | ||
if [ ${4} -ne 1 ];then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem |
||
# If the role is present, run the action | ||
echo "${YELLOW}Not installed${NORMAL}" | ||
elif service ${2} status 2>&1| grep -q "${3}"; then | ||
echo "${GREEN}OK${NORMAL}" | ||
else | ||
echo "${RED}Not running, please restart with \"service ${2} restart\" ${NORMAL}" | ||
RETURN=1 | ||
fi | ||
} | ||
|
||
service_details() | ||
{ | ||
# Arguments: | ||
## Service human-friendly name | ||
## Service name | ||
## Is the role present on this machine (0/1) | ||
|
||
${ECHO_BIN} -n "\n * ${BLUE}${1}${NORMAL}:" | ||
if [ ${3} -eq 1 ];then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem |
||
echo "" | ||
${COPYPASTE} | ||
service ${2} status || RETURN=${?} | ||
${COPYPASTE} | ||
else | ||
echo " ${YELLOW}Not installed${NORMAL}" | ||
fi | ||
} | ||
|
||
start_services() | ||
{ | ||
${SLAPD_INIT} start | ||
${POSTGRESQL_INIT}* start | ||
${RUDDER_AGENT_INIT} start | ||
${APACHE2_INIT} start | ||
${JETTY_INIT} start | ||
service_action ${RUDDER_SLAPD} start ${HAVE_SLAPD} | ||
service_action ${POSTGRESQL} start ${HAVE_POSTGRESQL} | ||
service_action ${RUDDER_JETTY} start ${HAVE_JETTY} | ||
service_action ${RUDDER_AGENT} start ${HAVE_AGENT} | ||
} | ||
|
||
stop_services() | ||
{ | ||
${APACHE2_INIT} stop | ||
${JETTY_INIT} stop | ||
${RUDDER_AGENT_INIT} stop | ||
${POSTGRESQL_INIT}* stop | ||
${SLAPD_INIT} stop | ||
service_action ${RUDDER_SLAPD} stop ${HAVE_SLAPD} | ||
service_action ${POSTGRESQL} stop ${HAVE_POSTGRESQL} | ||
service_action ${RUDDER_JETTY} stop ${HAVE_JETTY} | ||
service_action ${RUDDER_AGENT} stop ${HAVE_AGENT} | ||
} | ||
|
||
details_services() | ||
{ | ||
${ECHO_BIN} "${GREEN}Detailed component status:${NORMAL}" | ||
|
||
RETURN=0 | ||
|
||
service_details "Agent" ${RUDDER_AGENT} ${HAVE_AGENT} | ||
service_details "LDAP DB" ${RUDDER_SLAPD} ${HAVE_SLAPD} | ||
service_details "SQL DB" ${POSTGRESQL} ${HAVE_POSTGRESQL} | ||
service_details "Application" ${RUDDER_JETTY} ${HAVE_JETTY} | ||
|
||
exit ${RETURN} | ||
} | ||
|
||
status_services() | ||
{ | ||
${APACHE2_INIT} status | ||
${JETTY_INIT} check | tail -1 | ||
${RUDDER_AGENT_INIT} status | ||
# Add PostgreSQL PID to the output | ||
echo -n "postgres[`head -1 ${POSTGRESQL_PID_FILE}`]: " | ||
${POSTGRESQL_INIT}* status | ||
${SLAPD_INIT} status | ||
${ECHO_BIN} "${GREEN}Component status:${NORMAL}" | ||
|
||
RETURN=0 | ||
|
||
service_status "Agent" ${RUDDER_AGENT} "All configured CFEngine Community processes are running" ${HAVE_AGENT} | ||
service_status "LDAP DB" ${RUDDER_SLAPD} "Process rudder-slapd is running" ${HAVE_SLAPD} | ||
service_status "SQL DB" ${POSTGRESQL} ": online" ${HAVE_POSTGRESQL} | ||
service_status "Application" ${RUDDER_JETTY} "Jetty running" ${HAVE_JETTY} | ||
|
||
exit ${RETURN} | ||
} | ||
|
||
case "$1" in | ||
stop) | ||
stop_services | ||
;; | ||
start) | ||
start_services | ||
;; | ||
status) | ||
status_services | ||
;; | ||
restart) | ||
stop_services | ||
start_services | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
exit 1 | ||
;; | ||
start) | ||
start_services | ||
;; | ||
stop) | ||
stop_services | ||
;; | ||
restart) | ||
stop_services | ||
start_services | ||
;; | ||
status) | ||
status_services | ||
;; | ||
details) | ||
details_services | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status|details}" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 | ||
exit ${RETURN} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a distribution independent methods to detect this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. We used to check for the init.d script, but it would not work with non-sysvinit systems...
Do you have a suggestion for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe by checking the binary /usr/sbin/apache2 vs /usr/sbin/httpd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have it at all if you don't manage apache ?