File: restart.sh

package info (click to toggle)
wwwconfig-common 0.3.0
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • sloc: sh: 952; makefile: 5
file content (61 lines) | stat: -rwxr-xr-x 2,396 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# File:		restart.sh
# Changes:
#	20010219 Ola Lundqvist <opal@debian.org>
#	20010430 Ola Lundqvist <opal@debian.org>
#		Removed bash specific issues.
#	20011022 Luca De Vitis <luca@debian.org>
#		Introduced the error variable.
#	20020116 Ola Lundqvist <opal@debian.org>
#		Documented the error variable.
#       20020126 Ola Lundqvist <opal@debian.org>
#		Better error handing for this one.
#	20020317 Ola Lundqvist <opal@debian.org>
#		Applied simple patch from
#		"Luca - De Whiskey's - De Vitis" <luca@debian.org>
#       20061118 Ola Lundqvist <opal@debian.org>
#               Applied patch from Frederic Schutz <schutz@mathgen.ch>
#               to make sure that restart failure do not break postinst.
#       20080611 Ola Lundqvist <opal@debian.org>
#               Now uses invoke-rc.d instead if available.
# Needs:	$servers - the servers to check for.
#		$restart - where it searches for if it exists.
# Description:	Restarts a server if it is found in the restart variable.
# Sets:		$status = {error, nothing, restart}
#	 	$restarted = the ones that are restarted in order.
#		$error = error message (if $status = error)
# Note:		$restart can be somthing like this: "apache exim"

status="nothing"
error=""
if [ -z "$servers" ] ; then
    status="error"
    error="No servers specified in restart.sh."
else
    restart=" $restart "
    for A in $servers ; do
	verify=$(echo "$restart" | sed -e "s| $A ||g;")
	if [ "$verify" != "$restart" ] ; then
	    log="${log}$A needs to be restarted."
	    if [ -x /usr/sbin/invoke-rc.d ] && [ -x /etc/init.d/$A ] ; then
		if ! /usr/sbin/invoke-rc.d $A restart >/dev/null 2>&1 3>&1 4>&1 5>&1; then
		    status="error"
		    error="ERROR! /usr/sbin/invoke-rc.d $A restart, returned an error. $A could not be restarted."
		fi
	    elif [ -x /etc/init.d/$A ] ; then
		if ! /etc/init.d/$A restart >/dev/null 2>&1 3>&1 4>&1 5>&1; then
		    status="error"
		    error="ERROR! /etc/init.d/$A returned an error. $A could not be restarted."
		fi
	    elif [ -x /usr/sbin/invoke-rc.d ] ; then
		if ! /usr/sbin/invoke-rc.d $A restart >/dev/null 2>&1 3>&1 4>&1 5>&1; then
		    status="error"
		    error="ERROR! /usr/sbin/invoke-rc.d $A restart, returned an error. $A could not be restarted."
		fi
	    else
		status="error"
		error="ERROR! /etc/init.d/$A or /usr/sbin/invoke-rc.d is not installed (or not executable)."
	    fi
	fi
    done
fi