chiark / gitweb /
wip manpage
[innduct.git] / scripts / rc.news.in
1 #! /bin/sh
2 # fixscript will replace this line with code to load innshellvars
3
4 ##  $Revision: 7435 $
5 ##  News boot script.  Runs as "news" user.  Requires inndstart be
6 ##  setuid root.  Run from rc.whatever as:
7 ##     su news -c /path/to/rc.news >/dev/console
8 ##
9 ##  Or to stop INN:
10 ##     su news -c '/path/to/rc.news stop'
11
12 waitforpid()
13 {
14     i=12
15     while [ $i -gt 0 ];
16     do
17         kill -0 $1 2>/dev/null || break
18         sleep 5
19         printf "."
20         i=`expr $i - 1`
21     done
22     printf "\n"
23 }
24
25 case X"$1" in
26 Xstop)
27     # Stop cnfsstat (if running)
28     if [ -f ${PATHRUN}/cnfsstat.pid ]; then
29         kill `cat ${PATHRUN}/cnfsstat.pid`
30         rm -f ${PATHRUN}/cnfsstat.pid
31     fi
32
33     # Stop innwatch (if running)
34     if [ -f $WATCHPID ]; then
35         kill `cat $WATCHPID`
36         rm -f $WATCHPID
37     fi
38
39     printf "Stopping innd: "
40     ${PATHBIN}/ctlinnd throttle 'rc.news stop'
41     ${PATHBIN}/ctlinnd shutdown 'rc.news stop'
42
43     # wait for innd to exit (up to 60 sec)
44     pid=`cat ${SERVERPID} 2>/dev/null`
45     if [ "$pid" != "" ]; then
46         waitforpid $pid
47     else
48         printf "\n"
49     fi
50
51     # Turn off ovdb support procs, and close the DB environment
52     if [ "$OVMETHOD" = "ovdb" -a -f ${PATHRUN}/ovdb_server.pid ]; then
53         pid=`cat ${PATHRUN}/ovdb_server.pid 2>/dev/null`
54         if [ "$pid" != "" ]; then
55             printf "Stopping ovdb_server: "
56             kill $pid
57             waitforpid $pid
58         fi
59     fi
60     if [ "$OVMETHOD" = "ovdb" -a -f ${PATHRUN}/ovdb_monitor.pid ]; then
61         pid=`cat ${PATHRUN}/ovdb_monitor.pid 2>/dev/null`
62         if [ "$pid" != "" ]; then
63             printf "Stopping ovdb_monitor: "
64             kill $pid
65             waitforpid $pid
66         fi
67     fi
68
69     if [ -f ${PATHBIN}/rc.news.local ]; then
70         ${PATHBIN}/rc.news.local stop
71     fi
72
73     # Delete all of the PID files that we know about to avoid having them
74     # stick around after a fresh start.
75     rm -f ${PATHRUN}/cnfsstat.pid $WATCHPID $SERVERPID
76     rm -f ${PATHRUN}/ovdb_server.pid ${PATHRUN}/ovdb_monitor.pid
77
78     exit 0
79 ;;
80 esac
81
82 ##  Pick ${INND} or ${INNDSTART}
83 WHAT=${INNDSTART}
84
85 MAIL="${MAILCMD} -s 'Boot-time Usenet warning on `hostname`' ${NEWSMASTER}"
86
87 ##  RFLAG is set below; set INNFLAGS in inn.conf(5)
88 RFLAG=""
89
90 ##  Clean shutdown or already running?
91 if [ -f ${SERVERPID} ] ; then
92     if kill -0 `cat ${SERVERPID}` 2>/dev/null; then
93         echo 'INND is running'
94         exit 0
95     fi
96     echo 'INND:  PID file exists -- unclean shutdown!'
97     RFLAG="-r"
98 fi
99
100 if [ ! -f ${PATHDB}/.news.daily ] ; then
101     case `find ${PATHBIN}/innd -mtime +1 -print 2>/dev/null` in
102     "")
103         ;;
104     *)
105         echo 'No .news.daily file; need to run news.daily?' | eval ${MAIL}
106         ;;
107     esac
108 else
109     case `find ${PATHDB}/.news.daily -mtime +1 -print 2>/dev/null` in
110     "")
111         ;;
112     *)
113         echo 'Old .news.daily file; need to run news.daily?' | eval ${MAIL}
114         ;;
115     esac
116 fi
117
118 ##  Active file recovery.
119 if [ ! -s ${ACTIVE} ] ; then
120     if [ -s ${NEWACTIVE} ] ; then
121         mv ${NEWACTIVE} ${ACTIVE}
122     else
123         if [ -s ${OLDACTIVE} ] ; then
124             cp ${OLDACTIVE} ${ACTIVE}
125         else
126             echo 'INND:   No active file!'
127             exit 1
128         fi
129     fi
130     RFLAG="-r"
131     # You might want to rebuild the DBZ database, too:
132     #cd ${PATHDB} \
133     #           && makehistory -r \
134     #           && mv history.n.dir history.dir \
135     #           && mv history.n.index history.index \
136     #           && mv history.n.hash history.hash
137 fi
138
139 ##  Remove temporary batchfiles and lock files.
140 ( cd ${BATCH} && rm -f bch* )
141 ( cd ${LOCKS} && rm -f LOCK* )
142 ( cd ${TEMPSOCKDIR} && rm -f ${TEMPSOCK} )
143 rm -f ${NEWSCONTROL} ${NNTPCONNECT} ${SERVERPID}
144
145 ## Initialize ovdb.  Must be done before starting innd.
146 if [ "$OVMETHOD" = "ovdb" ]; then
147     echo 'Starting ovdb.'
148     ovdb_init || {
149         echo "Can't initialize ovdb (check news.err for OVDB messages)"
150         exit 1
151     }
152     sleep 1
153 fi
154
155 ##  Start the show.
156 echo 'Starting innd.'
157 eval ${WHAT} ${RFLAG} ${INNFLAGS}
158
159 # Gee, looks like lisp, doesn't it?
160 ${DOINNWATCH} && {
161     echo "Scheduled start of ${INNWATCH}."
162     ( sleep 60 ; ${INNWATCH} ) > /dev/null &
163 }
164
165 ${DOCNFSSTAT} && {
166     echo "Scheduled start of cnfsstat."
167     ( sleep 60 ; ${PATHBIN}/cnfsstat -s -l -P ) > /dev/null &
168 }
169
170 RMFILE=${MOST_LOGS}/expire.rm
171 for F in ${RMFILE} ${RMFILE}.*; do
172     if [ -f $F -a -s $F ] ; then
173         echo "Removing articles from pre-downtime expire run (${F})."
174         (
175             echo 'System shut down during expire.' \
176                 'Unlinking articles listed in'
177             echo ${F}
178         ) | eval ${MAIL}
179         ${PATHBIN}/expirerm ${F}
180     fi
181 done &
182
183 # Run any additional local startup commands.
184 if [ -f ${PATHBIN}/rc.news.local ] ; then
185     ${PATHBIN}/rc.news.local start
186 fi