3 # autosshd autossh system service
5 # chkconfig: 2345 30 60
7 # description: autosshd run autossh as system service
12 # Do not load RH compatibility interface.
15 # Source function library.
16 .
/etc
/init.d
/functions
23 #FIX call in cycle for all conf
25 AUTOSSH_PIDFILE
=${PIDFILEDIR}/$
(basename $1 .conf
).pid
26 AUTOSSH_LOCKFILE
=$LOCKFILEDIR/$
(basename $1 .conf
).lck
27 AUTOSSH_LOGFILE
=/var
/lib
/autosshd
/$
(basename $1 .conf
).log
30 # Source networking configuration.
31 SourceIfNotEmpty
/etc
/sysconfig
/network
33 # AutoSSHDaemon configuration
34 SYSCONFIGFILE
="/etc/sysconfig/autosshd"
35 SourceIfNotEmpty
$SYSCONFIGFILE
38 ###========= Functions =========
39 #===== help message =====
43 Usage: ${0##*/} ACTION [CHANNEL]
44 ACTION - requested action of all or given AutoSSH channel
45 CHANNEL - optional name of AutoSSH channel (with corresponding
46 CHANNEL.* files in $CONFIGDIR)
49 start - start all configured channels except listed
50 in MANUAL variable in $CONFIGDIR/CHANNEL.conf file
51 stop - stop all running channels
52 restart - restart channels that are configured for autostart
53 reload - restart only running channels
54 list - print list of configured channels
55 status - print status of running channels
56 help - print this message.
64 /bin
/ls $CONFIGDIR/*.conf
2>/dev
/null
69 LIST
=$
(get_channels_list
)
70 echo "Configured channels:"
71 for config
in $LIST; do
72 SourceIfNotEmpty
$config
73 echo " `basename $config .conf`. Manual: ${MANUAL} "
80 LIST
=`/bin/ls $PIDFILEDIR/*.pid 2>/dev/null`
83 CHANNELS
="$CHANNELS`basename $proc .pid` "
93 # skip if in manual mode
94 is_no
$MANUAL ||
return 0
96 start_daemon
--pidfile "$AUTOSSH_PIDFILE" --make-pidfile --lockfile "$AUTOSSH_LOCKFILE" --user $AUTOSSHUSER --name autossh
--displayname "autossh to ${HOST}" -- autossh
${AUTOSSH_OPTIONS}
100 # strange hack: overwrite pidfile??
101 #ps ax | grep -v grep | grep ${AUTOSSH_PORT} | awk {'print $1'} > "$AUTOSSH_PIDFILE"
104 echo "Configuration file $1 not found"
114 if [ -s $AUTOSSH_PIDFILE ]; then
115 #ParentPID=${PIDFILEDIR}/${HOST}.pid
116 #ps ax | grep -v grep | grep "parent of $(cat $AUTOSSH_PIDFILE)" | awk {'print $1'} > $ParentPID
117 stop_daemon
--pidfile "$AUTOSSH_PIDFILE" --lockfile "$AUTOSSH_LOCKFILE" --expect-user $AUTOSSHUSER --name autossh
--displayname "autossh to ${HOST}" -- autossh
119 rm -f "$AUTOSSH_PIDFILE"
123 msg_not_running
"autossh for `basename $1 .conf`"
127 echo "Configuration file $1 not found"
137 [ -n "$CHANNELS" ] || running_channels
139 if [ -z "$CHANNELS" ]; then
140 msg_not_running autossh
144 for CHANNEL
in $CHANNELS; do
145 status
--pidfile "$PIDFILEDIR/$CHANNEL.pid" --lockfile "$LOCKFILEDIR/$CHANNEL.lck" --expect-user $AUTOSSHUSER --name ssh --displayname "autossh to $CHANNEL" -- autossh
146 RETVAL
=$
(( $RETVAL + $?
))
154 # run only listed channels
155 if [ -n "$CHANNELS" ] ; then
156 for i
in $CHANNELS; do
158 do_run_one
$CONFIGDIR/$i.conf
163 # run all scheduled channels
164 CHANNELS
=$
(get_channels_list
)
165 for config
in $CHANNELS; do
166 SourceIfNotEmpty
$config
175 [ -n "$CHANNELS" ] || running_channels
177 for config
in $CHANNELS; do
178 SourceIfNotEmpty
$config
180 do_stop_one
$CONFIGDIR/$config.conf
194 is_yes
"$NETWORKING" ||
return 0
196 # See how we were called.
224 msg_usage
"${0##*/} {start|stop|reload|restart|status|list|help}"