tidying
[exim.git] / src / src / exiwhat.src
CommitLineData
059ec3d9 1#! /bin/sh
059ec3d9 2
0a49a7a4 3# Copyright (c) University of Cambridge, 1995 - 2007
059ec3d9
PH
4# See the file NOTICE for conditions of use and distribution.
5
6# Except when they appear in comments, the following placeholders in this
7# source are replaced when it is turned into a runnable script:
8#
9# CONFIGURE_FILE_USE_NODE
10# CONFIGURE_FILE
11# BIN_DIRECTORY
12# EXIWHAT_PS_CMD
13# EXIWHAT_PS_ARG
14# EXIWHAT_KILL_SIGNAL
15# EXIWHAT_EGREP_ARG
16# EXIWHAT_MULTIKILL_CMD
17# EXIWHAT_MULTIKILL_ARG
6d56f3f4 18# RM_COMMAND
059ec3d9
PH
19
20# PROCESSED_FLAG
21
22# Shell script for seeing what the exim processes are doing. It gets rid
23# of the old process log, then sends SIGUSR1 to all exim processes to get
24# them to write their state to the log. Then it displays the contents of
25# the log.
26
27# The following lines are generated from Exim's configuration file when
28# this source is built into a script, but you can subsequently edit them
29# without rebuilding things, as long are you are careful not to overwrite
30# the script in the next Exim rebuild/install. However, it's best to
31# arrange your build-time configuration file to get the correct values.
32
6d56f3f4 33rm=RM_COMMAND
34
059ec3d9
PH
35# Some operating systems have a command that finds processes that match
36# certain conditions (by default usually those running specific commands)
37# and sends them signals. If such a command is defined for your OS, the
38# following variables are set and used.
39
40multikill_cmd=EXIWHAT_MULTIKILL_CMD
41multikill_arg=EXIWHAT_MULTIKILL_ARG
42
43# In other operating systems, Exim has to use "ps" and "egrep" to find the
44# processes itself. In those cases, the next three variables are used:
45
46ps_cmd=EXIWHAT_PS_CMD
47ps_arg=EXIWHAT_PS_ARG
48egrep_arg=EXIWHAT_EGREP_ARG
49
50# In both cases, kill_arg is the argument for the (multi)kill command to send
51# SIGUSR1 (at least one OS requires a numeric value).
52
53signal=EXIWHAT_KILL_SIGNAL
54
55# See if this installation is using the esoteric "USE_NODE" feature of Exim,
56# in which it uses the host's name as a suffix for the configuration file name.
57
983da878
HSHR
58if test "x$1" = x--version
59then
60 echo "`basename $0`: $0"
61 echo "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION"
62 exit 0
63fi
64
059ec3d9
PH
65if [ "CONFIGURE_FILE_USE_NODE" = "yes" ]; then
66 hostsuffix=.`uname -n`
67fi
68
69# Now find the configuration file name. This has got complicated because
70# CONFIGURE_FILE may now be a list of files. The one that is used is the first
71# one that exists. Mimic the code in readconf.c by testing first for the
72# suffixed file in each case.
73
74set `awk -F: '{ for (i = 1; i <= NF; i++) print $i }' <<End
75CONFIGURE_FILE
76End
77`
78while [ "$config" = "" -a $# -gt 0 ] ; do
79 if [ -f "$1$hostsuffix" ] ; then
80 config="$1$hostsuffix"
81 elif [ -f "$1" ] ; then
82 config="$1"
83 fi
84 shift
85done
86
447de4b0
NM
87# check we have a config file
88if [ "$config" = "" -o ! -f "$config" ]; then
89 echo Config file not found.
90 exit 1
91fi
92
059ec3d9
PH
93# Determine where the spool directory is. Search for an exim_path setting
94# in the configure file; otherwise use the bin directory. Call that version of
95# Exim to find the spool directory. BEWARE: a tab character is needed in the
96# first command below. It has had a nasty tendency to get lost in the past. Use
97# a variable to hold a space and a tab. This is less likely to be touched.
98
99st=' '
100exim_path=`grep "^[$st]*exim_path" $config | sed "s/.*=[$st]*//"`
101if test "$exim_path" = ""; then exim_path=BIN_DIRECTORY/exim; fi
102spool_directory=`$exim_path -C $config -bP spool_directory | sed "s/.*=[ ]*//"`
103process_log_path=`$exim_path -C $config -bP process_log_path | sed "s/.*=[ ]*//"`
104
105# The file that Exim writes when sent the SIGUSR1 signal is specified by
106# the process_log_path option. If that is not defined, Exim uses the file
107# called "exim-process.info" in the spool directory.
108
109log=$process_log_path
110if [ "$log" = "" ] ; then
111 log=$spool_directory/exim-process.info
112fi
113
114# Now do the job.
115
6d56f3f4 116$rm -f ${log}
059ec3d9
PH
117if [ -f ${log} ]; then
118 echo "** Failed to remove ${log}"
119 exit 1
120fi
121
122# If there is a multikill command, use it. On some OS this command is called
123# "killall" (Linux, FreeBSD). On Solaris it is called "pkill". Note that on
124# Solaris, "killall" kills ALL processes - this is the System V version of this
125# command, and not what we want!
126
079cc20f 127if [ "$multikill_cmd" != "" ] && type "$multikill_cmd" >/dev/null 2>&1; then
059ec3d9
PH
128 $multikill_cmd $signal "$multikill_arg"
129
130# No multikill command; do it the hard way
131
132else
133 $ps_cmd $ps_arg | \
134 egrep "$egrep_arg" | \
135 awk "{print \"kill $signal \"\$1}" | \
136 uniq | sh
137fi
138
139sleep 1
140
141if [ ! -s ${log} ] ; then echo "No exim process data" ;
921b12ca 142 else sort -nu ${log} ; fi
059ec3d9
PH
143
144
145# End of exiwhat