/etc/init.d/hylafax is in hylafax-server 3:6.0.6-8.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | #!/bin/sh
# Start or stop HylaFAX
#
# This script start and stop hylafax daemons.
# It is driven by a configuration file sourced by this shell
# and called /etc/default/hylafax.
### BEGIN INIT INFO
# Provides: hylafax
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs $network iaxmodem
# Should-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the hylafax server
# Description: Start hylafax daemons. Otherwise stop all
# hylafax daemons except for daemon started
# by init.
### END INIT INFO
# 28-Dec-2003 Ross Boylan
# Add "init" option to USE_FAXGETTY
# This will cause this script to assume that faxgetty is already
# running from the inittab file
# 19-sep-2006 Giuseppe Sacco
# Added support for lsb message handling
# 10-may-2009 Giuseppe Sacco
# Added support for mounting /etc/hylafax on /var/spool/hylafax/etc
# Currently this script use the "bind" option only when the
# system support it and only when no daemon is run via init.
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HYLAFAX_HOME=/var/spool/hylafax
FAXGETTY=/usr/sbin/faxgetty
FAXMODEM=/usr/sbin/faxmodem
PIDFILE=/var/run/hfaxd.pid
NEWPROT=
SNPP=
RUN_HYLAFAX=0
test -x /usr/sbin/faxq || exit 0
test -x /usr/sbin/hfaxd || exit 0
if [ -f /etc/hylafax/setup.cache ];
then
#
# Check if old protocol should be started
grep -qE "^HFAXD_OLD_PROTOCOL='(1|yes)'" /etc/hylafax/setup.cache
if [ $? -eq 0 ];
then
echo "Hylafax old protocol is not available anymore starting from hylafax 6.0.0" >&2
exit 1
fi
#
# Check if new protocol server should be started
grep -qE "^HFAXD_SERVER='(1|yes)'" /etc/hylafax/setup.cache
if [ $? -eq 0 ];
then
NEWPROT="-i 4559"
fi
#
# Check if SNPP server should be started
grep -qE "^HFAXD_SNPP_SERVER='(1|yes)" /etc/hylafax/setup.cache
if [ $? -eq 0 ];
then
SNPP="-s 444"
fi
else
echo "ERROR: You must run faxsetup before starting hylafax." 1>&2
exit 1
fi
if [ -z "$NEWPROT$SNPP" -a "$1" != stop ]
then
if [ -z "$HFAXD_FROM_INET" -o "$HFAXD_FROM_INET" != true ]
then
echo "You must specify at least one protocol NEW or SNPP in"
echo "/etc/hylafax/setup.cache using the command faxsetup,"
echo "otherwise you might only run hylafax via inetd."
exit 1
fi
fi
if [ -r /etc/default/hylafax ]; then
. /etc/default/hylafax
fi
if [ "$RUN_HYLAFAX" -ne 1 -a "$1" = "start" ]; then
echo "Hylafax is disabled, see /etc/default/hylafax"
exit 0
fi
# This function print on stdout all devices used by
# hylafax. It enumerated the devices based on all
# configuration files found in /etc/hylafax
echo_fax_devices()
{
for device in config.*
do
if [ "$device" != 'config.*' ]
then
dev=${device##config.}
# the next line is a patch included in #283111 for
# handling devfs file names.
dev=$(echo "$dev"|sed 's,_,/,g')
if [ \( -f "$device" -a -e "/dev/$dev" \) -o \
\( "$dev" = faxCAPI -a -e /dev/capi20 \) ]
then
echo "$dev"
fi
fi
done
}
# This function check if this kernel and the mount command
# support the option "bind"
# This is a separate function because it should support
# different commands when running on different kernels
# like hurd and *bsd
check_for_mount_bind()
{
supported=0
TMPD=`mktemp -d /tmp/hylafax.XXXXXXXXXX` || return $supported
mkdir "$TMPD/directory"
mkdir "$TMPD/directory2"
touch "$TMPD/directory/file"
mount --bind "$TMPD/directory" "$TMPD/directory2"
if [ -f "$TMPD/directory2/file" ]
then
supported=1
umount "$TMPD/directory2"
fi
rm "$TMPD/directory/file"
rmdir "$TMPD/directory" "$TMPD/directory2" "$TMPD"
echo $supported
}
# mount the /etc/hylafax filesystem on /var/spool/hylafax/etc
# This is a separate function because it should support
# different commands when running on different kernels
# like hurd and *bsd
mountbind()
{
mount --bind "$1" "$2"
}
# umount the /etc/hylafax filesystem from /var/spool/hylafax/etc
# This is a separate function because it should support
# different commands when running on different kernels
# like hurd and *bsd
#
# Note: in some upgrade corner cases, the volume is monted many times
# on the same mount point. So, this is a loop that umount all of them.
umountbind()
{
if type findmnt >/dev/null 2>&1
then
while [ 0 -lt $(findmnt --noheadings --target "$1" | grep -Fc '[/etc/hylafax]') ]
do
umount "$1"
done
else
umount "$1" 2>/dev/null || true
fi
}
# This function may be used for debugging: it prints a command
# on stderr and then execute it. Comment out the first line to
# avoid "debugging information". Do not touch the last line
# since it execute the command
x()
{
echo + "$@" 1>&2
eval "$@"
}
# Check for updated files in /etc/hylafax and copy them
# to /var/spool/hylafax/etc .
# Updates on authorizations and ownership are also
# copied.
update_dir()
{
# This function won't copy dot-files.
for src in "$1/"*
do
if [ "$src" != "${src%%\~}" ] || [ "$src" != "${src%%.bak}" ]
then
continue
fi
dst="$2/"$(basename $src)
if [ ! -e "$dst" ] ;
then
x /bin/cp -a "\"$src\"" "\"$dst\""
else
if [ -d "$dst" ];
then
update_dir "$src" "$dst"
else
if [ -L "$dst" -a \
'(' ! -L "$src" -o x$(readlink "$dst") != x$(readlink "$src") ')' ];
then
x /bin/rm -f "\"$dst\""
x /bin/cp -a "\"$src\"" "\"$dst\""
else
if [ "$src" -nt "$dst" ];
then
# The configuration file has been changed in $src
x /bin/cp -p "\"$src\"" "\"$dst\""
else
if [ "$dst" -nt "$src" ];
then
# The configuration file has been changed in $dst
echo "ERROR: $dst is newer than $src" 1>&2
echo "Please send a bug report on the hylafax-server package" 1>&2
exit 1
else
# in some cases, user change ownership/access right to files in /etc/hylafax.
# this will copy these rights to files in /var/spool/hylafax/etc
chmod --reference="$src" "$dst"
chown --reference="$src" "$dst"
fi
fi
fi
fi
fi
done
# remove all files from /var/spool/hylafax/etc that have been deleted
# in /etc/hylafax (see #514950)
for src in "$2/"*
do
if [ "$src" != "${src%%\~}" ] || [ "$src" != "${src%%.bak}" ]
then
continue
fi
dst="$1/"$(basename $src)
if [ ! -e "$dst" ]
then
x /bin/rm "$src"
fi
done
}
# mount using bind option only if kernel support it and only if faxgetty is
# not run via init or, if it is run via init but no devices are
# configured
mountbind_or_updatedir()
{
devices="`echo_fax_devices`"
if [ $(check_for_mount_bind) -eq 1 ] && [ "${USE_FAXGETTY}" != "init" -o -z "$devices" ]
then
mountbind $1 $2
else
update_dir $1 $2
fi
}
# This function is called when starting the hylafax server.
# It clone the /etc directory into the chroot() directory
copy_slash_etc()
{
SPOOL=$(awk -F= '$1=="SPOOL" { gsub(/'"'"'/,"",$2); print $2; exit}' /etc/hylafax/setup.cache)
if [ -z "$SPOOL" ];
then
echo "ERROR: You must run faxsetup before starting hylafax" 1>&2
echo "and be sure to check that the SPOOL variable is assigned." 1>&2
exit 1
fi
if [ -d "$SPOOL/etc" ];
then
mountbind_or_updatedir "/etc/hylafax" "$SPOOL/etc"
else
echo "Can't find directory $SPOOL/etc" 1>&2
exit 1
fi
}
# Stop all daemons, except for what executed via init
daemon_stop()
{
log_daemon_msg "Stopping HylaFAX" faxq
p=$(env PS_PERSONALITY=linux ps --no-headers -C faxq -o pid)
if [ -n "$p" ]
then
start-stop-daemon --stop --exec /usr/sbin/faxq
sleep 1
p=$(env PS_PERSONALITY=linux ps --no-headers -C faxq -o pid)
[ -n "$p" ] && kill $p
fi
log_progress_msg "hfaxd"
p=$(env PS_PERSONALITY=linux ps --no-headers -C hfaxd -o pid)
if [ -n "$p" ]
then
start-stop-daemon --stop --exec /usr/sbin/hfaxd --pidfile $PIDFILE -- $BINDTO $NEWPROT $SNPP
sleep 1
p=$(env PS_PERSONALITY=linux ps --no-headers -C hfaxd -o pid)
[ -n "$p" ] && kill $p
fi
if [ ${USE_FAXGETTY} = "yes" ]; then
log_progress_msg "faxgetty"
killall faxgetty 2> /dev/null || true
fi
# wait maximum sixty seconds for server processes to shutdown
try=0
while [ $try -lt 60 ] && [ 0 -lt $(env PS_PERSONALITY=linux ps --no-headers -Chfaxd,faxq | wc -l) ]
do
sleep 1
try=$(($try+1))
done
umountbind $(awk -F= '$1=="SPOOL" { gsub(/'"'"'/,"",$2); printf("%s/etc",$2); exit}' /etc/hylafax/setup.cache)
if [ 0 -eq "$(env PS_PERSONALITY=linux ps --no-headers -Chfaxd,faxq | wc -l)" ]
then
log_end_msg 0
else
log_end_msg 1
fi
}
# Start all daemons, except for what executed via init
daemon_start()
{
if [ ${USE_FAXGETTY} = "yes" ]
then
count=$(env PS_PERSONALITY=linux ps --no-headers -Chfaxd,faxq,faxgetty | wc -l)
else
count=$(env PS_PERSONALITY=linux ps --no-headers -Chfaxd,faxq | wc -l)
fi
if [ $count -eq 0 ];
then
log_daemon_msg "Starting HylaFAX" "syncing directories..."
copy_slash_etc
log_progress_msg "faxq"
start-stop-daemon --start --exec /usr/sbin/faxq
if [ -z "$HFAXD_FROM_INET" -o "$HFAXD_FROM_INET" != true ]
then
log_progress_msg "hfaxd"
start-stop-daemon --start --exec /usr/sbin/hfaxd \
--make-pidfile --pidfile $PIDFILE \
--background -- -d $BINDTO $NEWPROT $SNPP
fi
cd ${HYLAFAX_HOME}/etc
devices="`echo_fax_devices`"
if [ ${USE_FAXGETTY} = "yes" ] && [ -n "$devices" ]; then
log_progress_msg "faxgetty"
for device in $devices none; do
[ "$device" = none ] && continue
${FAXGETTY} $FAXGETTYARGS `echo $device | cut -d . -f 2` &
done
elif [ ${USE_FAXGETTY} != "init" ] && [ -n "$devices" ]; then
log_progress_msg "faxmodem"
for device in $devices none; do
[ "$device" = none ] && continue
${FAXMODEM} `echo $device | cut -d . -f 2` >/dev/null 2>&1 </dev/null &
done
fi
# do nothing for "init"
else
echo "Not starting HylaFAX daemons since they are already running." 1>&2
exit 0
fi
log_end_msg 0
}
case "$1" in
start)
daemon_start
;;
stop)
daemon_stop
;;
restart|force-reload)
daemon_stop
sleep 1
daemon_start
;;
status)
# test if user is root. If not root then exit with "unknown"
if [ `id -u` -ne 0 ]
then
echo Status can be checked only by root user.
# 4: program or service status is unknown
exit 4
fi
SPOOL=$(awk -F= '$1=="SPOOL" { gsub(/'"'"'/,"",$2); print $2; exit}' /etc/hylafax/setup.cache)
if [ -p $SPOOL/FIFO ] && fuser $SPOOL/FIFO >/dev/null 2>&1
then
echo running
# 0: program is running or service is OK
exit 0
else
echo stopped
# 3: program is not running
exit 3
fi
;;
*)
echo "Usage: /etc/init.d/hylafax {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0
|