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