From cb7ee90cf52594e9499b80c8599f924c587ac525 Mon Sep 17 00:00:00 2001 From: yvoinov Date: Wed, 27 Mar 2019 20:51:36 +0600 Subject: [PATCH] Solaris SMF Closes #18. --- util/smf/README | 25 ++++++++ util/smf/endlessh.conf | 21 +++++++ util/smf/endlessh.xml | 96 +++++++++++++++++++++++++++++ util/smf/init.endlessh | 137 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 util/smf/README create mode 100644 util/smf/endlessh.conf create mode 100644 util/smf/endlessh.xml create mode 100644 util/smf/init.endlessh diff --git a/util/smf/README b/util/smf/README new file mode 100644 index 0000000..e9feaf8 --- /dev/null +++ b/util/smf/README @@ -0,0 +1,25 @@ +Solaris SMF installation +======================== + +Before installing SMF: + +1. Put endlessh binary to /usr/local/bin +2. Edit endlessh.conf and put it to /usr/local/etc + +To install SMF: + +1. Put endlessh.xml to /var/svc/manifest/network +2. Run svccfg import endlessh.xml +3. Put init.endlessh to /lib/svc/method +4. Run svcadm enable endlessh + +Note: Log will write to /var/log/endlessh.log by default. + +To uninstall SMF: + +1. Run svcadm disable endlessh +2. rm -f /lib/svc/method/init.endlessh +3. svccfg delete svc:/network/endlessh:default +4. rm -f /var/svc/manifest/network/endlessh.xml + +Enjoy! :) \ No newline at end of file diff --git a/util/smf/endlessh.conf b/util/smf/endlessh.conf new file mode 100644 index 0000000..a33e192 --- /dev/null +++ b/util/smf/endlessh.conf @@ -0,0 +1,21 @@ +# The port on which to listen for new SSH connections. +Port 22 + +# The endless banner is sent one line at a time. This is the delay +# in milliseconds between individual lines. +Delay 10000 + +# The length of each line is randomized. This controls the maximum +# length of each line. Shorter lines may keep clients on for longer if +# they give up after a certain number of bytes. +MaxLineLength 32 + +# Maximum number of connections to accept at a time. Connections beyond +# this are not immediately rejected, but will wait in the queue. +MaxClients 4096 + +# Set the detail level for the log. +# 0 = Quiet +# 1 = Standard, useful log messages +# 2 = Very noisy debugging information +LogLevel 1 diff --git a/util/smf/endlessh.xml b/util/smf/endlessh.xml new file mode 100644 index 0000000..fe4e803 --- /dev/null +++ b/util/smf/endlessh.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/util/smf/init.endlessh b/util/smf/init.endlessh new file mode 100644 index 0000000..c254bb9 --- /dev/null +++ b/util/smf/init.endlessh @@ -0,0 +1,137 @@ +#!/sbin/sh + +# +# Control Method for endlessh (/lib/svc/method/init.endlessh) +# Written by Yuri Voinov (C) 2007,2019 +# +# ident "@(#)endlessh.sh 1.8 19/27/03 YV" +# + +############# +# Variables # +############# + +# Base installation directory +BASE_DIR="/usr/local" +BASE_CONFIG_DIR=$BASE_DIR"/etc" + +# endlessh files paths +ENDLESSH_PATH="$BASE_DIR""/bin" +ENDLESSH_CONF_PATH="$BASE_CONFIG_DIR" + +# endlessh files +ENDLESSH_BIN_FILE="endlessh" +ENDLESSH_CONF_FILE=$ENDLESSH_BIN_FILE".conf" + +# Daemon settings +ENDLESSH_CONF="$ENDLESSH_CONF_PATH/$ENDLESSH_CONF_FILE" + +# Log +LOG_DIR="/var/log" +LOGFILE=$LOG_DIR/$ENDLESSH_BIN_FILE".log" + +# +# OS Commands location variables +# +CUT=`which cut` +ECHO=`which echo` +KILL=`which kill` +PGREP=`which pgrep` +UNAME=`which uname` + +# OS release +OS_VER=`$UNAME -r|$CUT -f2 -d"."` +OS_NAME=`$UNAME -s|$CUT -f1 -d" "` + +############### +# Subroutines # +############### + +check_endlessh () +{ + # Check endlessh installed + program=$1 + if [ ! -f "$ENDLESSH_PATH/$program" -a ! -x "$ENDLESSH_PATH/$program" ]; then + $ECHO "ERROR: endlessh not found!" + $ECHO "Exiting..." + exit 1 + fi +} + +check_os () +{ + # Check OS version + if [ ! "$OS_NAME" = "SunOS" -a ! "$OS_VER" -lt "10" ]; then + $ECHO "ERROR: Unsupported OS $OS_NAME $OS_VER" + $ECHO "Exiting..." + exit 1 + fi +} + +checkconf () +{ +# Check endlessh config file + config=$1 + if [ -f "$ENDLESSH_CONF_PATH"/"$config" ]; then + $ECHO "1" + else + $ECHO "0" + fi +} + +startproc() +{ +# Start endlessh daemon + program=$1 + if [ "`checkconf $ENDLESSH_CONF_FILE`" != "1" ]; then + $ECHO "ERROR: Config file $ENDLESSH_CONF_PATH/$ENDLESSH_CONF_FILE not found." + $ECHO "Exiting..." + exit 2 + else + $ENDLESSH_PATH/$program -f $ENDLESSH_CONF_PATH/$ENDLESSH_CONF_FILE -v >$LOGFILE & + fi +} + +stopproc() +{ +# Stop endlessh daemon + program=$1 + if [ "`checkconf $ENDLESSH_CONF_FILE`" != "1" ]; then + $ECHO "ERROR: Config file $ENDLESSH_CONF_PATH/$ENDLESSH_CONF_FILE not found." + $ECHO "Exiting..." + exit 2 + else + $KILL -s TERM `$PGREP $program`>/dev/null 2>&1 + fi +} + +############## +# Main block # +############## + +# Check endlessh installed +check_endlessh $ENDLESSH_BIN_FILE + +# Check OS version +check_os + +case "$1" in +"start") + startproc $ENDLESSH_BIN_FILE + ;; +"stop") + stopproc $ENDLESSH_BIN_FILE + ;; +"refresh") + $KILL -s HUP `$PGREP $ENDLESSH_BIN_FILE`>/dev/null 2>&1 + ;; +"restart") + stopproc $ENDLESSH_BIN_FILE + startproc $ENDLESSH_BIN_FILE + ;; +*) + $ECHO "Usage: $0 { start | stop | restart | refresh }" + exit 1 +esac + +exit 0