summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/kolabctl115
1 files changed, 115 insertions, 0 deletions
diff --git a/sbin/kolabctl b/sbin/kolabctl
new file mode 100644
index 0000000..a3b7b6a
--- /dev/null
+++ b/sbin/kolabctl
@@ -0,0 +1,115 @@
+#!/bin/bash
+
+function usage() {
+ echo "Usage: $0 <status|start|stop|restart> [service]"
+ echo ""
+ echo "Restart, start or stop the services that concern Kolab Groupware."
+ echo ""
+ echo "Specify 'all' for service to restart, stop or start all services."
+ exit 1
+}
+
+if [ $# -lt 2 -o $# -gt 3 ]; then
+ usage
+fi
+
+debug=0
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ status|start|stop|restart)
+ action=$1
+ shift
+ ;;
+
+ --debug)
+ debug=1
+ shift
+ ;;
+
+ *)
+ service=$1
+ shift
+ ;;
+
+ esac
+done
+
+declare -a services
+declare -a service_providers
+
+services[${#services[@]}]="ldap"; service_providers[${#service_providers[@]}]="ldap"
+services[${#services[@]}]="ldap"; service_providers[${#service_providers[@]}]="dirsrv"
+
+services[${#services[@]}]="auth"; service_providers[${#service_providers[@]}]="saslauthd"
+
+services[${#services[@]}]="mta"; service_providers[${#service_providers[@]}]="postfix"
+services[${#services[@]}]="mta"; service_providers[${#service_providers[@]}]="sendmail"
+services[${#services[@]}]="mta"; service_providers[${#service_providers[@]}]="exim"
+services[${#services[@]}]="mta"; service_providers[${#service_providers[@]}]="qmail"
+
+services[${#services[@]}]="imap"; service_providers[${#service_providers[@]}]="cyrus"
+services[${#services[@]}]="imap"; service_providers[${#service_providers[@]}]="cyrus-imapd"
+services[${#services[@]}]="imap"; service_providers[${#service_providers[@]}]="kolab-cyrus-imapd"
+services[${#services[@]}]="imap"; service_providers[${#service_providers[@]}]="imapd"
+services[${#services[@]}]="imap"; service_providers[${#service_providers[@]}]="dovecot"
+
+services[${#services[@]}]="httpd"; service_providers[${#service_providers[@]}]="apache2"
+services[${#services[@]}]="httpd"; service_providers[${#service_providers[@]}]="httpd"
+
+services[${#services[@]}]="antispam"; service_providers[${#service_providers[@]}]="spamassassin"
+services[${#services[@]}]="antispam"; service_providers[${#service_providers[@]}]="spamd"
+services[${#services[@]}]="antispam"; service_providers[${#service_providers[@]}]="amavisd"
+
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="clamd"
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="clamd.amavisd"
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="clamav-daemon"
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="clamav"
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="freshclam"
+services[${#services[@]}]="antivirus"; service_providers[${#service_providers[@]}]="clamav-freshclam"
+
+services[${#services[@]}]="kolab"; service_providers[${#service_providers[@]}]="kolabd";
+
+service_num=0
+
+runlevel=`runlevel | awk '{print $2}'`
+
+while [ ${service_num} -lt ${#services[@]} ]; do
+
+ if [ "${service}" == "all" -o \
+ "${service}" == "${services[${service_num}]}" -o \
+ "${service}" == "${service_providers[${service_num}]}" \
+ ]; then
+
+ [ ${debug} -gt 0 ] && \
+ echo "Checking service ${services[${service_num}]}, provider ${service_providers[${service_num}]}..."
+
+ service_provider=${service_providers[${service_num}]}
+
+ if [ -x "/etc/rc.d/init.d/${service_provider}" ]; then
+ [ ${debug} -gt 0 ] && \
+ echo "Service ${services[${service_num}]} / provider ${service_providers[${service_num}]} found."
+
+ if [ "$action" == "start" -o "${action}" == "restart" ]; then
+ [ -x "$(which chkconfig 2>/dev/null)" ] && \
+ attempt_action=`chkconfig --list ${service_provider} 2>/dev/null | grep ${runlevel}:on`
+ else
+ attempt_action=1
+ fi
+
+ if [ ! -z "${attempt_action}" ]; then
+ /etc/rc.d/init.d/${service_provider} $action && \
+ echo "Service ${services[${service_num}]} $action executed succesfully through provider ${service_provider}" >> /var/log/kolab/kolabctl.log || \
+ echo "Service ${services[${service_num}]} $action execute FAILED through provider ${service_provider}" >2 | tee -a /var/log/kolab/kolabctl.log
+ else
+ [ ${debug} -gt 0 ] && \
+ echo "Service ${services[${service_num}]} / provider ${service_provider[${service_num}]} installed but not configured to start"
+ fi
+ else
+ [ ${debug} -gt 0 ] && \
+ echo "Service ${services[${service_num}]} / provider ${service_providers[${service_num}]} not installed."
+ fi
+ fi
+
+ let service_num++;
+done