3 # autosshd autossh system service
5 # chkconfig: 2345 30 60
7 # description: autosshd run autossh as system service
11 startname
="/usr/share/autosshd/autossh-conf" #need for export var, because start shell by root and run autossh by _autossh user
12 # processname: $processname
15 # Do not load RH compatibility interface.
18 # Source function library.
19 .
/etc
/init.d
/functions
21 # Source networking configuration.
22 SourceIfNotEmpty
/etc
/sysconfig
/network
24 # AutoSSHDaemon configuration
25 SYSCONFIGFILE
="/etc/sysconfig/autosshd"
26 SourceIfNotEmpty
$SYSCONFIGFILE
27 # Load AutoSSHD variables and init_autossh function
28 SourceIfNotEmpty
"$startname"
31 ###========= Functions =========
32 #===== help message =====
36 Usage: ${0##*/} ACTION [CHANNEL]
37 ACTION - requested action of all or given AutoSSH channel
38 CHANNEL - optional name of AutoSSH channel (with corresponding
39 CHANNEL.* files in $CONFIGDIR)
42 start - start all configured channels except listed
43 in AUTOSTART variable in $CONFIGDIR/CHANNEL.conf file
44 stop - stop all running channels
45 restart - restart channels that are configured for autostart
46 reload - restart only running channels
47 list - print list of configured channels
48 status - print status of running channels
49 help - print this message.
50 testssh - test connection configuration by ssh.
62 # skip if in AUTOSTART mode
63 is_yes
"$AUTOSTART" ||
return 0
65 [ -e "$AUTOSSH_LOCKFILE" ] && echo "autossh to $(basename $1 .conf) service is already running." && return 1
67 start_daemon
--lockfile "$AUTOSSH_LOCKFILE" \
68 --user $AUTOSSHUSER --displayname "autossh to ${HOST}" -- $startname $1 "${AUTOSSH_OPTIONS}"
73 echo "Configuration file $1 not found"
83 if [ -s $AUTOSSH_PIDFILE ]; then
84 stop_daemon
--pidfile "$AUTOSSH_PIDFILE" --lockfile "$AUTOSSH_LOCKFILE" \
85 --expect-user $AUTOSSHUSER --name $processname --displayname "autossh to ${HOST}" -- $processname
89 msg_not_running
"autossh for `basename $1 .conf`"
93 echo "Configuration file $1 not found"
103 [ -n "$CHANNELS" ] || running_channels
105 if [ -z "$CHANNELS" ]; then
106 msg_not_running autossh
110 for CHANNEL
in $CHANNELS; do
112 status
--pidfile "$PIDFILEDIR/$CHANNEL.pid" --lockfile "$LOCKFILEDIR/$CHANNEL.lck" \
113 --expect-user $AUTOSSHUSER --name $processname --displayname "autossh to $CHANNEL" -- $processname
114 RETVAL
=$
(( $RETVAL + $?
))
122 # run only listed channels
123 if [ -n "$CHANNELS" ] ; then
124 for i
in $CHANNELS; do
125 do_run_one
$CONFIGDIR/$i.conf
131 # run all scheduled channels
132 CHANNELS
=$
(get_channels_list
)
133 for config
in $CHANNELS; do
142 [ -n "$CHANNELS" ] || running_channels
144 for config
in $CHANNELS; do
145 SourceIfNotEmpty
$config
147 do_stop_one
$CONFIGDIR/$config.conf
154 /bin
/ls $CONFIGDIR/*.conf
2>/dev
/null
#returns only filenames
159 LIST
=$
(get_channels_list
)
160 echo "Configured channels:"
161 for config
in $LIST; do
162 SourceIfNotEmpty
$config
163 echo " `basename $config .conf`. AUTOSTART: ${AUTOSTART} "
170 LIST
=`/bin/ls $PIDFILEDIR/*.pid 2>/dev/null`
172 for proc
in $LIST; do
173 CHANNELS
="$CHANNELS`basename $proc .pid` "
185 is_yes
"$NETWORKING" ||
return 0
187 # See how we were called.
202 if [ -n $CHANNELS ] ; then
216 su
- -s /bin
/sh
-c "autosshd-ssh $1" _autossh
219 msg_usage
"${0##*/} {start|stop|reload|condrestart|condstop|restart|status|list|help|testssh}"