1 #!/bin/sh 2 # 3 # Copyright (C) 2009, Cisco Systems Inc. 4 # Garrett Cooper, August 2009 5 # Copyright (C) 2012-2014 Linux Test Project 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License along 18 # with this program; if not, write to the Free Software Foundation, Inc., 19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 22 # running under systemd? 23 if command -v systemctl >/dev/null 2>&1; then 24 HAVE_SYSTEMCTL=1 25 else 26 HAVE_SYSTEMCTL=0 27 fi 28 29 # Check to see if syslogd, syslog-ng or rsyslogd exists 30 SYSLOG_DAEMON="" 31 if command -v syslogd >/dev/null 2>&1; then 32 SYSLOG_DAEMON="syslog" 33 elif command -v syslog-ng >/dev/null 2>&1; then 34 SYSLOG_DAEMON="syslog-ng" 35 elif command -v rsyslogd >/dev/null 2>&1; then 36 SYSLOG_DAEMON="rsyslog" 37 fi 38 39 # Check to see if cron or crond exists 40 CROND_DAEMON="" 41 if command -v crond >/dev/null 2>&1; then 42 CROND_DAEMON="crond" 43 elif command -v cron >/dev/null 2>&1; then 44 CROND_DAEMON="cron" 45 fi 46 47 start_daemon() 48 { 49 if [ $HAVE_SYSTEMCTL -eq 1 ]; then 50 systemctl start $1.service > /dev/null 2>&1 51 elif command -v service &> /dev/null; then 52 service $1 start > /dev/null 2>&1 53 else 54 /etc/init.d/$1 start > /dev/null 2>&1 55 fi 56 } 57 58 stop_daemon() 59 { 60 if [ $HAVE_SYSTEMCTL -eq 1 ]; then 61 systemctl stop $1.service > /dev/null 2>&1 62 elif command -v service &> /dev/null; then 63 service $1 stop > /dev/null 2>&1 64 else 65 /etc/init.d/$1 stop > /dev/null 2>&1 66 fi 67 } 68 69 status_daemon() 70 { 71 if [ $HAVE_SYSTEMCTL -eq 1 ]; then 72 systemctl status $1.service > /dev/null 2>&1 73 elif command -v service &> /dev/null; then 74 service $1 status > /dev/null 2>&1 75 else 76 /etc/init.d/$1 status > /dev/null 2>&1 77 fi 78 } 79 80 restart_daemon() 81 { 82 if [ $HAVE_SYSTEMCTL -eq 1 ]; then 83 systemctl restart $1.service > /dev/null 2>&1 84 elif command -v service &> /dev/null; then 85 service $1 restart > /dev/null 2>&1 86 else 87 /etc/init.d/$1 restart > /dev/null 2>&1 88 fi 89 } 90