Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
#!/bin/sh
2
### BEGIN INIT INFO
3
# Provides:          JatsBuildDaemon
4
# Required-Start:    $all
5
# Required-Stop:
6
# Default-Start:     3 4 5
7
# Default-Stop:      0 1 6
8
# X-Interactive:     true
9
# Short-Description: Jats Build Deamon
10
# Description:       The Jats Build Daemon provides automated build services
11
### END INIT INFO
12
 
13
#set -x
14
#
15
# Start, stop buildtool
16
#
17
# Note: This must be a 'sh' compatible script
18
#       Solaris8 uses sh to source the script. It is not run at startup
19
#
20
# Note: This file should be installed into /etc/init.d
21
#
22
# Note: Use /etc/init.d/buildtool setup
23
#        to perform additional setup of adding files to setup sequence
24
#
25
#set -x
26
BUILDUSR=buildadm
27
WRAPPERSCRIPT=/work/buildtool/abtwrapper
28
 
29
 
30
pid=0
31
#pid null if not running, pid if running
32
#   Get the process group of the wrapper script
33
check_running() {
34
        pid=`pgrep abtwrapper`
35
        [ -n "$pid" ] && pid=`ps -o pgid= -p $pid`
36
}
37
 
38
#
39
# Start daemons.
40
#
41
start() {
42
    check_running
43
    if [ "$pid" ]; then
44
          echo 'Running'
45
    else
46
          echo 'Starting'
47
          if [ "$USER" != "$BUILDUSR" ]; then SU="su - ${BUILDUSR} -c "; else SU="/bin/sh -c"; fi
48
          $SU "${WRAPPERSCRIPT}" &
49
    fi
50
}
51
 
52
#
53
# Stop daemons.
54
#   Terminate the process group of the controlling script
55
#
56
stop() {
57
    check_running
58
    echo "check_running returned $pid"
59
 
60
    if [ "$pid" ]; then
61
        for kpid in $pid ; do
62
            echo "Killing $kpid"
63
            kill -9 -$kpid 2>/dev/null 1>&2
64
        done
65
    else
66
        echo 'Not running'
67
    fi
68
}
69
 
70
#
71
#   Status the daemons
72
#
73
status() {
74
    check_running
75
 
76
    if [ "$pid" ]; then
77
          echo 'buildtool running'
78
    else
79
          echo 'buildtool not running'
80
    fi
81
}
82
 
83
#
84
#   Setup init levels
85
#   Linux and Solaris are different
86
#
87
setup() {
88
    if [ ! -f /etc/init.d/buildtool ] ; then
89
        echo "Error: /etc/init.d/buildtool does not exist"
90
        exit 1
91
    fi
92
 
93
    mtype=`uname`
94
    if [ -x /usr/sbin/update-rc.d ] ; then mtype=Ubuntu; fi
95
 
96
    case "$mtype" in
97
    Ubuntu)
98
        /usr/sbin/update-rc.d -f buildtool remove
99
        /usr/sbin/update-rc.d buildtool defaults
100
        ;;
101
 
102
    Linux)
103
        for ii in 2 3 4 5; do
104
            file=/etc/rc.d/rc$ii.d/S80buildtool
105
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
106
        done
107
 
108
        for ii in 0 1 6 ; do 
109
            file=/etc/rc.d/rc$ii.d/K30buildtool
110
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
111
        done
112
        ;;
113
 
114
    SunOS)
115
        for ii in 3; do
116
            file=/etc/rc$ii.d/S80buildtool
117
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
118
        done
119
 
120
        for ii in 0 1 S ; do 
121
            file=/etc/rc$ii.d/K30buildtool
122
            [ -f $file ] || ln -s /etc/init.d/buildtool $file
123
        done
124
        ;;
125
 
126
    *)
127
        echo "$0 setup - Unknown machine type: $mtype"
128
        exit 1
129
        ;;
130
    esac        
131
}
132
 
133
#
134
#   Determine user command
135
#
136
case "$1" in
137
  start)    start
138
            ;;
139
  stop)     stop
140
            ;;
141
  status)   status
142
            RETVAL=$?
143
            ;;  
144
  restart)  stop
145
            start
146
            ;;
147
  setup)    setup
148
            ;;   
149
  *)        echo "Usage: $0 {start|stop|restart|status|setup}"
150
            exit 1
151
            ;;
152
esac
153
 
154
exit $RETVAL
155