File: testinitscript

package info (click to toggle)
syslog-ng 4.8.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,572 kB
  • sloc: ansic: 177,639; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (92 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (2)
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
#!/bin/sh


echo "First reboot the host to activate SystemV init system"
if [ -z "$ADT_REBOOT_MARK" ]
then
    apt install --assume-yes --allow-remove-essential sysvinit-core systemd-sysv- runit-init-
    cp /usr/share/sysvinit/inittab /etc/inittab
    sed -i "/ttyS0/ s/^#//" /etc/inittab
    /tmp/autopkgtest-reboot "fixinit"
else
    echo $ADT_REBOOT_MARK
fi

is_syslogng_run()
{
    LINES=$(ps uawx | grep "syslog-ng " | grep -v grep)
    echo $LINES | grep -q syslog-ng
    RET=$?
    return $RET
}

exit_with_comment()
{
    comment=$1
    exit_code=$2
    echo $comment
    ps uawx | grep syslog-ng | grep -v grep
    sleep 5
    ps uawx | grep syslog-ng | grep -v grep
    exit $exit_code
}

set -e
echo "Checking if syslog-ng was able to start"
is_syslogng_run || exit_with_comment "Syslog-ng is not running, cannot test" 0

echo "Testing stop parameter"
/etc/init.d/syslog-ng stop

is_syslogng_run && exit_with_comment "Syslog-ng cannot be stopped" 1

echo "Testing status when syslog-ng is not running"
/etc/init.d/syslog-ng status && exit_with_comment "Syslog-ng status returned with error"

echo "Testing start parameter"
/etc/init.d/syslog-ng start

is_syslogng_run || exit_with_comment "Syslog-ng cannot be started" 1

echo "Testing status when syslog-ng is running"
/etc/init.d/syslog-ng status || exit_with_comment "Syslog-ng status returned with error"

echo "Testing restart parameter"
PIDFILE1=$(cat /var/run/syslog-ng.pid)
/etc/init.d/syslog-ng restart

is_syslogng_run || exit_with_comment "Syslog-ng stopped during restart" 1
PIDFILE2=$(cat /var/run/syslog-ng.pid)

test $PIDFILE1 -ne $PIDFILE2 || exit_with_comment "Syslog-ng was not restarted" 1

echo "Stopping syslog-ng for the next test"
/etc/init.d/syslog-ng stop

is_syslogng_run && exit_with_comment "Syslog-ng cannot be stopped 2" 1

echo "Testing wether restart start syslog-ng or not"
/etc/init.d/syslog-ng restart

is_syslogng_run || exit_with_comment "Syslog-ng is not started by restart" 1

echo "Testing the try-restart parameter"
PIDFILE1=$(cat /var/run/syslog-ng.pid)
/etc/init.d/syslog-ng try-restart

is_syslogng_run || exit_with_comment "Syslog-ng stopped during restart" 1
PIDFILE2=$(cat /var/run/syslog-ng.pid)

test $PIDFILE1 -ne $PIDFILE2 || exit_with_comment "Syslog-ng was not restarted by try-restart" 1

echo "Stopping syslog-ng before the next test"
/etc/init.d/syslog-ng stop

is_syslogng_run && exit_with_comment "Syslog-ng cannot be stopped 3" 1

echo "try-restart should not start the daemon if it didn't run before"
/etc/init.d/syslog-ng try-restart

is_syslogng_run && exit_with_comment "Syslog-ng started by try-restart" 1

exit 0