Operating System - HP-UX
1830944 Members
2207 Online
110017 Solutions
New Discussion

Startup/Shutdown script for OpenSSH

 
SOLVED
Go to solution
Kent Pirkle
Occasional Contributor

Startup/Shutdown script for OpenSSH

Does anyone have a good startup/shutdown script for OpenSSH?

Thanks!
4 REPLIES 4
Helen French
Honored Contributor
Solution

Re: Startup/Shutdown script for OpenSSH

Check this thread and Michael's answer:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x627e42308663d611abdb0090277a778c,00.html

Life is a promise, fulfill it!
Craig Rants
Honored Contributor

Re: Startup/Shutdown script for OpenSSH

Here's what I use.

PATH=/usr/sbin:/usr/bin:/sbin
export PATH

# NOTE: If your script executes in run state 0 or state 1, then /usr might
# not be available. Do not attempt to access commands or files in
# /usr unless your script executes in run state 2 or greater. Other
# file systems typically not mounted until run state 2 include /var
# and /opt.

rval=0

# Check the exit value of a command run by this script. If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
x=$?
if [ $x -ne 0 ]; then
echo "EXIT CODE: $x"
rval=1 # script FAILed
fi
}



case $1 in
'start_msg')
# Emit a _short_ message relating to running this script with
# the "start" argument; this message appears as part of the checklist.
# the following line was the standard line. replaced by the next line.
# echo "Starting the subsystem"
echo "Starting the Secure Shell Daemon"
;;

'stop_msg')
# Emit a _short_ message relating to running this script with
# the "stop" argument; this message appears as part of the checklist.
# echo "Stopping the subsystem"
echo "Stopping the Secure Shell Daemon"
;;

'start')

# source the system configuration variables
if [ -f /etc/rc.config.d/sshd ] ; then
. /etc/rc.config.d/sshd
else
echo "ERROR: /etc/rc.config.d/sshd defaults file MISSING"
fi

# Check to see if this script is allowed to run...
if [ $SSHD != 1 ]; then
rval=2
else
echo "Starting Secure Shell Daemon"
/opt/openssh2/sbin/sshd
set_return
fi
;;

'stop')
# source the system configuration variables
if [ -f /etc/rc.config.d/sshd ] ; then
. /etc/rc.config.d/sshd
else
echo "ERROR: /etc/rc.config.d/sshd defaults file MISSING"
fi

# Check to see if this script is allowed to run...
if [ $SSHD != 1 ]; then
rval=2
else
echo "Stopping Secure Shell Daemon"
KSSH=`cat /var/run/sshd.pid`
kill -9 $KSSH
set_return
:
# Execute the commands to stop your subsystem

fi
;;

*)
echo "usage: $0 {start|stop}"
rval=1
;;
esac

exit $rval


GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Darrell Allen
Honored Contributor

Re: Startup/Shutdown script for OpenSSH

Hi Kent,

Copy the attached file to /sbin/init.d/sshd (based on HP's template for rc files /sbin/init.d/template):

Create /etc/rc.config.d/sshd with the following contents:
#!/sbin/sh
#
# OpenSSH daemon configuration
#
# SSH_ENABLED: Set to 1 to enable starting of OpenSSH daemon
#
SSH_ENABLED=1

Create symlinks in the rc directories for starting and stopping sshd:
ln -s /sbin/init.d/sshd /sbin/rc3.d/S050sshd
ln -s /sbin/init.d/sshd /sbin/rc2.d/K950sshd

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Kent Pirkle
Occasional Contributor

Re: Startup/Shutdown script for OpenSSH

Thanks for all of your assistance, OpenSSH is now working for me over reboot.