fix layout of status output
[opensuse:build-service.git] / dist / obssrcserver
1 #! /bin/sh
2 # Copyright (c) 2007, Novell Inc.
3 #
4 # Author: adrian@suse.de
5 #
6 # /etc/init.d/obssrcserver
7 #   and its symbolic  link
8 # /usr/sbin/rcobssrcserver
9 #
10 ### BEGIN INIT INFO
11 # Provides:          obssrcserver
12 # Required-Start:    $time $syslog
13 # Required-Stop:     $null
14 # Should-Start:      $network $remote_fs obsstoragesetup slpd
15 # Should-Stop:       $none
16 # Default-Start:     3 5
17 # Default-Stop:      0 1 2 4 6
18 # Description:       openSUSE build service source repository server
19 ### END INIT INFO
20
21 . /etc/rc.status
22
23 . /etc/sysconfig/obs-server
24
25 # Determine the base and follow a runlevel link name.
26 base=${0##*/}
27 link=${base#*[SK][0-9][0-9]}
28
29 if [ -z "$OBS_RUN_DIR" ]; then
30         OBS_RUN_DIR="/srv/obs/run"
31 fi
32
33 if [ -z "$OBS_LOG_DIR" ]; then
34         OBS_LOG_DIR="/srv/obs/log"
35 fi
36
37 if [ -n "$OBS_BACKENDCODE_DIR" ]; then
38         obsdir="$OBS_BACKENDCODE_DIR"
39 else
40         obsdir=/usr/lib/obs/server/
41 fi
42 rundir="$OBS_RUN_DIR"
43 logdir="$OBS_LOG_DIR"
44
45 rc_reset
46 case "$1" in
47         start)
48                 echo -n "Initializing obssrcserver"
49                 mkdir -p "$rundir" "$logdir"
50                 chown obsrun:obsrun "$logdir" "$rundir"
51                 # FIXME: not nice, this should receive a proper daemon handling, 
52                 #        including real logging, pid file and startproc
53                 startproc -l "$logdir"/src_server.log "$obsdir"/bs_srcserver
54                 rc_status -v
55
56                 # FIXME:
57
58                 # We'd need to wait for the sockets to come up, or for
59                 # some other interaction between the server and the
60                 # start script, or the server should fork itself into
61                 # background _after_ the sockets are up and the server
62                 # is reachable.
63
64                 # until then a little ugly nap does the trick...
65                 sleep 4
66                 rc_status -v
67         ;;
68         stop)
69                 echo -n "Shutting down obssrcserver"
70                 killproc "$obsdir"/bs_srcserver 
71                 rc_status -v
72         ;;
73         restart)
74                 ## If first returns OK call the second, if first or
75                 ## second command fails, set echo return value.
76                 $0 status
77                 if test $? = 0; then
78                         touch "$rundir"/bs_srcserver.restart
79                 else
80                         $0 stop
81                         $0 start
82                 fi
83                 rc_status
84         ;;
85         try-restart)
86                 $0 status
87                 if test $? = 0; then
88                         $0 restart
89                 else
90                         rc_reset        # Not running is not a failure.
91                 fi
92                 # Remember status and be quiet
93                 rc_status
94         ;;
95         reload)
96                 $0 status
97                 if test $? = 0; then
98                         touch "$rundir"/bs_srcserver.restart
99                 fi
100                 rc_status
101         ;;
102         status)
103                 echo "Checking for obssrcserver and running processes: "
104                 "$obsdir"/bs_serverstatus "$OBS_RUN_DIR"/bs_srcserver.status
105                 checkproc "$obsdir"/bs_srcserver
106                 rc_status -v
107         ;;
108         *)
109                 echo "Usage: $0 {start|stop|status|try-restart|restart|reload}"
110                 exit 1
111         ;;
112 esac
113 rc_exit