Project

General

Profile

Bug #4395 » testdep.sh

Jim Klimov, 2013-12-15 01:30 PM

 
1
#!/bin/bash
2

    
3
cd /tmp
4

    
5
INST=test
6
case "$SMF_FMRI" in
7
    *master*) INST=master;;
8
    *slave*) INST=slave;;
9
esac
10
LOCK="/tmp/testdep.lock.$INST"
11

    
12
do_daemon() (
13
    echo "`date`: $INST: Starting daemon loop with lockfile '$LOCK'"
14
    touch "$LOCK"
15
    trap "" 0 1
16
    trap 'echo "`date`: $INST: Exiting $SMF_FMRI soon..."; sleep 10; exit 0;' 2 3 15
17
    while [ -f "$LOCK" ]; do
18
	sleep 3
19
    done
20
    trap 'echo "`date`: $INST: Exiting $SMF_FMRI soon..."; sleep 10; exit 0;' 0 1 2 3 15
21
    echo "`date`: $INST: Ending daemon loop"
22
)
23

    
24
case "$1" in
25
start)
26
    ### Lengthy startup
27
    echo "`date`: $INST: Init (sleeping) $SMF_FMRI"
28
    sleep 30
29
    echo "`date`: $INST: Init completed: $SMF_FMRI"
30

    
31
    do_daemon &
32

    
33
    echo "`date`: $INST: Launched daemon: $SMF_FMRI: PID: $!"
34

    
35
    sleep 3
36
    ;;
37
stop)
38
    ### Lengthy stop
39
    echo "`date`: $INST: Stop-Init (sleeping) $SMF_FMRI"
40
    sleep 8
41
    echo "`date`: $INST: Stop-Init completed: $SMF_FMRI"
42

    
43
    rm -f "$LOCK"
44
    
45
    echo "`date`: $INST: Post-stop sleep"
46
    sleep 5
47
    ;;
48
esac
(1-1/4)