fix layout of status output
[opensuse:build-service.git] / dist / obsrepserver
1 #! /bin/sh
2 # Copyright (c) 2007, Novell Inc.
3 #
4 # Author: adrian@suse.de
5 #
6 # /etc/init.d/obsrepserver
7 #   and its symbolic  link
8 # /usr/sbin/rcobsrepserver
9 #
10 ### BEGIN INIT INFO
11 # Provides:          obsrepserver
12 # Required-Start:    $time $syslog $network $remote_fs
13 # Should-Start:      obssigner obsstoragesetup slpd
14 # Should-Stop:       $none
15 # Required-Stop:     $null
16 # Default-Start:     3 5
17 # Default-Stop:      0 1 2 4 6
18 # Description:       openSUSE build service 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 obsrepserver"
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"/rep_server.log "$obsdir"/bs_repserver
54                 rc_status -v
55         ;;
56         stop)
57                 echo -n "Shutting down obsrepserver"
58                 killproc "$obsdir"/bs_repserver 
59                 rc_status -v
60         ;;
61         restart)
62                 ## If first returns OK call the second, if first or
63                 ## second command fails, set echo return value.
64                 $0 status
65                 if test $? = 0; then
66                         touch "$rundir"/bs_repserver.restart
67                 else
68                         $0 stop
69                         $0 start
70                 fi
71                 rc_status
72         ;;
73         try-restart)
74                 $0 status
75                 if test $? = 0; then
76                         $0 restart
77                 else
78                         rc_reset        # Not running is not a failure.
79                 fi
80                 # Remember status and be quiet
81                 rc_status
82         ;;
83         reload)
84                 $0 status
85                 if test $? = 0; then
86                         touch "$rundir"/bs_repserver.restart
87                 fi
88                 rc_status
89         ;;
90         status)
91                 echo "Checking for obsrepserver and running processes: "
92                 "$obsdir"/bs_serverstatus "$OBS_RUN_DIR"/bs_repserver.status
93                 checkproc "$obsdir"/bs_repserver
94                 rc_status -v
95         ;;
96         *)
97                 echo "Usage: $0 {start|stop|status|try-restart|restart|reload}"
98                 exit 1
99         ;;
100 esac
101 rc_exit