|
Tomáš Mráz |
ca47f6 |
#!/bin/bash
|
|
Tomáš Mráz |
ca47f6 |
#
|
|
Tomáš Mráz |
d93958 |
# sshd Start up the OpenSSH server daemon
|
|
Tomáš Mráz |
ca47f6 |
#
|
|
Tomáš Mráz |
ca47f6 |
# chkconfig: 2345 55 25
|
|
Tomáš Mráz |
d93958 |
# description: SSH is a protocol for secure remote shell access. \
|
|
Tomáš Mráz |
d93958 |
# This service starts up the OpenSSH server daemon.
|
|
Tomáš Mráz |
ca47f6 |
#
|
|
Tomáš Mráz |
ca47f6 |
# processname: sshd
|
|
Tomáš Mráz |
ca47f6 |
# config: /etc/ssh/ssh_host_key
|
|
Tomáš Mráz |
ca47f6 |
# config: /etc/ssh/ssh_host_key.pub
|
|
Tomáš Mráz |
ca47f6 |
# config: /etc/ssh/ssh_random_seed
|
|
Tomáš Mráz |
ca47f6 |
# config: /etc/ssh/sshd_config
|
|
Tomáš Mráz |
ca47f6 |
# pidfile: /var/run/sshd.pid
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
d93958 |
### BEGIN INIT INFO
|
|
Tomáš Mráz |
d93958 |
# Provides: sshd
|
|
Tomáš Mráz |
d93958 |
# Required-Start: $local_fs $network $syslog
|
|
Tomáš Mráz |
d93958 |
# Required-Stop: $local_fs $syslog
|
|
Tomáš Mráz |
d93958 |
# Should-Start: $syslog
|
|
Tomáš Mráz |
d93958 |
# Should-Stop: $network $syslog
|
|
Tomáš Mráz |
d93958 |
# Default-Start: 2 3 4 5
|
|
Tomáš Mráz |
d93958 |
# Default-Stop: 0 1 6
|
|
Tomáš Mráz |
d93958 |
# Short-Description: Start up the OpenSSH server daemon
|
|
Tomáš Mráz |
d93958 |
# Description: SSH is a protocol for secure remote shell access.
|
|
Tomáš Mráz |
d93958 |
# This service starts up the OpenSSH server daemon.
|
|
Tomáš Mráz |
d93958 |
### END INIT INFO
|
|
Tomáš Mráz |
d93958 |
|
|
Tomáš Mráz |
ca47f6 |
# source function library
|
|
Tomáš Mráz |
ca47f6 |
. /etc/rc.d/init.d/functions
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
# pull in sysconfig settings
|
|
Tomáš Mráz |
ca47f6 |
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
RETVAL=0
|
|
Tomáš Mráz |
ca47f6 |
prog="sshd"
|
|
Tomáš Mráz |
d93958 |
lockfile=/var/lock/subsys/$prog
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
# Some functions to make the below more readable
|
|
Tomáš Mráz |
ca47f6 |
SSHD=/usr/sbin/sshd
|
|
Jan F |
d3542d |
XPID_FILE=/var/run/sshd.pid
|
|
Jan F |
d3542d |
PID_FILE=/var/run/sshd-s.pid
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
runlevel=$(set -- $(runlevel); eval "echo \$$#" )
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
do_restart_sanity_check()
|
|
Tomáš Mráz |
ca47f6 |
{
|
|
Tomáš Mráz |
ca47f6 |
$SSHD -t
|
|
Tomáš Mráz |
ca47f6 |
RETVAL=$?
|
|
Jan F. Chadima |
f013be |
if [ $RETVAL -ne 0 ]; then
|
|
Tomáš Mráz |
ca47f6 |
failure $"Configuration file or keys are invalid"
|
|
Tomáš Mráz |
ca47f6 |
echo
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Tomáš Mráz |
ca47f6 |
}
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
start()
|
|
Tomáš Mráz |
ca47f6 |
{
|
|
Tomáš Mráz |
d93958 |
[ -x $SSHD ] || exit 5
|
|
Tomáš Mráz |
d93958 |
[ -f /etc/ssh/sshd_config ] || exit 6
|
|
Tomáš Mráz |
ca47f6 |
# Create keys if necessary
|
|
Jan F |
5c8b5c |
/usr/sbin/sshd-keygen
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
echo -n $"Starting $prog: "
|
|
Tomáš Mráz |
ca47f6 |
$SSHD $OPTIONS && success || failure
|
|
Tomáš Mráz |
ca47f6 |
RETVAL=$?
|
|
Jan F. Chadima |
f013be |
[ $RETVAL -eq 0 ] && touch $lockfile
|
|
Jan F |
d3542d |
[ $RETVAL -eq 0 ] && cp -f $XPID_FILE $PID_FILE
|
|
Tomáš Mráz |
ca47f6 |
echo
|
|
Tomáš Mráz |
d93958 |
return $RETVAL
|
|
Tomáš Mráz |
ca47f6 |
}
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
stop()
|
|
Tomáš Mráz |
ca47f6 |
{
|
|
Jan F |
ef264f |
|
|
Tomáš Mráz |
ca47f6 |
echo -n $"Stopping $prog: "
|
|
Jan F |
d3542d |
if [ ! -f "$PID_FILE" ]; then
|
|
Jan F |
ef264f |
# not running; per LSB standards this is "ok"
|
|
Jan F |
ef264f |
action $"Stopping $prog: " /bin/true
|
|
Jan F |
ef264f |
return 0
|
|
Jan F |
ef264f |
fi
|
|
Jan F |
d3542d |
PID=`cat "$PID_FILE"`
|
|
Jan F |
ef264f |
if [ -n "$PID" ]; then
|
|
Jan F |
ef264f |
/bin/kill "$PID" >/dev/null 2>&1
|
|
Jan F |
ef264f |
RETVAL=$?
|
|
Jan F |
ef264f |
if [ $RETVAL -eq 0 ]; then
|
|
Jan F |
ef264f |
RETVAL=1
|
|
Jan F |
ef264f |
action $"Stopping $prog: " /bin/false
|
|
Jan F |
ef264f |
else
|
|
Jan F |
ef264f |
action $"Stopping $prog: " /bin/true
|
|
Jan F |
ef264f |
fi
|
|
Tomáš Mráz |
ca47f6 |
else
|
|
Jan F |
ef264f |
# failed to read pidfile
|
|
Jan F |
ef264f |
action $"Stopping $prog: " /bin/false
|
|
Jan F |
ef264f |
RETVAL=4
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Tomáš Mráz |
ca47f6 |
# if we are in halt or reboot runlevel kill all running sessions
|
|
Tomáš Mráz |
ca47f6 |
# so the TCP connections are closed cleanly
|
|
Tomáš Mráz |
ca47f6 |
if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
|
|
Tomáš Mráz |
ca47f6 |
trap '' TERM
|
|
Tomáš Mráz |
ca47f6 |
killall $prog 2>/dev/null
|
|
Tomáš Mráz |
ca47f6 |
trap TERM
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Jan F. Chadima |
f013be |
[ $RETVAL -eq 0 ] && rm -f $lockfile
|
|
Jan F |
d3542d |
rm -f "$PID_FILE"
|
|
Jan F |
ef264f |
return $RETVAL
|
|
Tomáš Mráz |
ca47f6 |
}
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
ca47f6 |
reload()
|
|
Tomáš Mráz |
ca47f6 |
{
|
|
Tomáš Mráz |
ca47f6 |
echo -n $"Reloading $prog: "
|
|
Tomáš Mráz |
ca47f6 |
if [ -n "`pidfileofproc $SSHD`" ] ; then
|
|
Tomáš Mráz |
ca47f6 |
killproc $SSHD -HUP
|
|
Tomáš Mráz |
ca47f6 |
else
|
|
Tomáš Mráz |
ca47f6 |
failure $"Reloading $prog"
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Tomáš Mráz |
ca47f6 |
RETVAL=$?
|
|
Tomáš Mráz |
ca47f6 |
echo
|
|
Tomáš Mráz |
ca47f6 |
}
|
|
Tomáš Mráz |
ca47f6 |
|
|
Tomáš Mráz |
d93958 |
restart() {
|
|
Tomáš Mráz |
d93958 |
stop
|
|
Tomáš Mráz |
d93958 |
start
|
|
Tomáš Mráz |
d93958 |
}
|
|
Tomáš Mráz |
d93958 |
|
|
Tomáš Mráz |
d93958 |
force_reload() {
|
|
Tomáš Mráz |
d93958 |
restart
|
|
Tomáš Mráz |
d93958 |
}
|
|
Tomáš Mráz |
d93958 |
|
|
Tomáš Mráz |
d93958 |
rh_status() {
|
|
Jan F. Chadima |
f013be |
status -p $PID_FILE openssh-daemon
|
|
Tomáš Mráz |
d93958 |
}
|
|
Tomáš Mráz |
d93958 |
|
|
Tomáš Mráz |
d93958 |
rh_status_q() {
|
|
Tomáš Mráz |
d93958 |
rh_status >/dev/null 2>&1
|
|
Tomáš Mráz |
d93958 |
}
|
|
Tomáš Mráz |
d93958 |
|
|
Tomáš Mráz |
ca47f6 |
case "$1" in
|
|
Tomáš Mráz |
ca47f6 |
start)
|
|
Tomáš Mráz |
d93958 |
rh_status_q && exit 0
|
|
Tomáš Mráz |
ca47f6 |
start
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
ca47f6 |
stop)
|
|
Jan F. Chadima |
f013be |
if ! rh_status_q; then
|
|
Jan F. Chadima |
f013be |
rm -f $lockfile
|
|
Jan F. Chadima |
f013be |
exit 0
|
|
Jan F. Chadima |
f013be |
fi
|
|
Tomáš Mráz |
ca47f6 |
stop
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
ca47f6 |
restart)
|
|
Tomáš Mráz |
d93958 |
restart
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
ca47f6 |
reload)
|
|
Tomáš Mráz |
d93958 |
rh_status_q || exit 7
|
|
Tomáš Mráz |
ca47f6 |
reload
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
d93958 |
force-reload)
|
|
Tomáš Mráz |
d93958 |
force_reload
|
|
Tomáš Mráz |
d93958 |
;;
|
|
Jan F. Chadima |
f013be |
condrestart|try-restart)
|
|
Tomáš Mráz |
d93958 |
rh_status_q || exit 0
|
|
Tomáš Mráz |
d93958 |
if [ -f $lockfile ] ; then
|
|
Tomáš Mráz |
ca47f6 |
do_restart_sanity_check
|
|
Jan F. Chadima |
f013be |
if [ $RETVAL -eq 0 ] ; then
|
|
Tomáš Mráz |
ca47f6 |
stop
|
|
Tomáš Mráz |
ca47f6 |
# avoid race
|
|
Tomáš Mráz |
ca47f6 |
sleep 3
|
|
Tomáš Mráz |
ca47f6 |
start
|
|
Tomáš Mráz |
d93958 |
else
|
|
Tomáš Mráz |
d93958 |
RETVAL=6
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Tomáš Mráz |
ca47f6 |
fi
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
ca47f6 |
status)
|
|
Tomáš Mráz |
d93958 |
rh_status
|
|
Tomáš Mráz |
ca47f6 |
RETVAL=$?
|
|
Jan F. Chadima |
f013be |
if [ $RETVAL -eq 3 -a -f $lockfile ] ; then
|
|
Jan F. Chadima |
f013be |
RETVAL=2
|
|
Jan F. Chadima |
f013be |
fi
|
|
Tomáš Mráz |
ca47f6 |
;;
|
|
Tomáš Mráz |
ca47f6 |
*)
|
|
Tomáš Mráz |
d93958 |
echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
|
|
Tomáš Mráz |
d93958 |
RETVAL=2
|
|
Tomáš Mráz |
ca47f6 |
esac
|
|
Tomáš Mráz |
ca47f6 |
exit $RETVAL
|