summaryrefslogtreecommitdiff
path: root/source3/script/tests/functions
blob: 0981d9e29e149770853ac3060b22576a6cb29ff5 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
##
## library file for test functions
##


SMBCONTROL="smbcontrol -t 3"

##
## start/stop smbd daemon
##
check_smbd_running()
{
	## the smbcontrol ping will return a 0 on success
	$SMBCONTROL $CONFIGURATION smbd ping 2>&1 > /dev/null
}

start_smbd()
{
	echo "Starting smbd...."

	smbd $CONFIGURATION || return $?

	sleep 1

	$SMBCONTROL $CONFIGURATION `cat $PIDDIR/smbd.pid` ping 2>&1 > /dev/null || return $?
}

stop_smbd()
{
	smbd_pid=`cat $PIDDIR/smbd.pid`
	echo "Shutting down smbd (pid $smbd_pid)..."

	## belt and braces; first kill and then send a shutdown message

	kill -TERM $smbd_pid
	$SMBCONTROL $CONFIGURATION smbd shutdown

	## check to see if smbd is already running
	check_smbd_running
	if test $? == 0; then
		echo "Unable to stop smbd!"
		exit 2
	fi
}

check_ret_value()
{
	ret=$@

	if test $ret != 0; then
		stop_smbd
		exit $ret
	fi
}

##
## start/stop nmbd daemon
##
check_nmbd_running()
{
	## the smbcontrol ping will return a 0 on success
	$SMBCONTROL $CONFIGURATION nmbd ping 2>&1 > /dev/null
}

start_nmbd()
{
	echo "Starting nmbd...."

	nmbd $CONFIGURATION || return $?

	sleep 1

	# smbcontrol $CONFIGURATION `cat $PIDDIR/nmbd.pid` ping 2>&1 > /dev/null || return $?
	kill -0 `cat $PIDDIR/nmbd.pid`
}

stop_nmbd()
{
	nmbd_pid=`cat $PIDDIR/nmbd.pid`
	echo "Shutting down nmbd (pid $nmbd_pid)..."

	## belt and braces; first kill and then send a shutdown message

	kill -TERM $nmbd_pid 2> /dev/null
	sleep 1

	## check to see if smbd is already running
	kill -0 $nmbd_pid 2> /dev/null
	if test $? == 0; then
		echo "Unable to stop nmbd!"
		exit 2
	fi
}