cae32 ([info]cae32) wrote,
@ 2009-05-06 13:12:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Модифицировал рестартилку для jail
Теперь точно работает, проверено на одном продвинутом jail-хостинге.


#!/bin/sh
#
#    Copyright (C) 2009 Sergey A.Eremenko (eremenko.s@gmail.com)
#
#    Written for Eugene Gladchenko's eazy and improving FreeBSD jail hosting
#       Please contact thru hosting@gladchenko.ru
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: v1.3 $

# SYNOPSIS
# $ sudo crontab -u root -e
# add line
# */5 * * * * /usr/local/bin/ezjail_check_reboot
#
# DESCRIPTION
# Check for .need_ezjail_restart magic file in root directory of jail and
# restart this machine, remove magic file after restart (no check result)

if [ `id -u` != 0 ] ; then
        echo "You must be a root!"
        exit 2
fi

PATH=/sbin:/bin:/usr/sbin:/usr/bin
ezjail_prefix=/usr/local
ezjail_config_dir="${ezjail_prefix}/etc/ezjail/"
ezjail_restart_script=/usr/local/etc/rc.d/ezjail.sh
ezjail_magic_flag_for_restart=.need_ezjail_restart
ezjail_framework_log="/var/log/ezjail_framework.log"

. /etc/rc.subr

name=ezjail_check_reboot
rcvar=`set_rcvar`
load_rc_config ${name}

ezjail_enable=${ezjail_enable:-"NO"}

if ! checkyesno ezjail_enable; then
        return 0
fi

unset ezjail_list ezjail_pass ezjail_restart_files_for_rm

[ -d "${ezjail_config_dir}" ] && cd "${ezjail_config_dir}" && ezjail_list=`ls | xargs rcorder`

for ezjail in ${ezjail_list} ; do
        [ -f "${ezjail_config_dir}${ezjail}.norun" -o "${ezjail%.*}" != "${ezjail}" ] && continue

        [ ! -r "${ezjail_config_dir}${ezjail}" ] && continue

        . "${ezjail_config_dir}${ezjail}"

        eval ezjail_rootdir=\"\$jail_${ezjail}_rootdir\"

        [ ! -d "${ezjail_rootdir}" ] && continue

        [ ! -f "${ezjail_rootdir}/${ezjail_magic_flag_for_restart}" ] && continue

        ezjail_pass="${ezjail_pass:} ${ezjail}"
        ezjail_restart_files_for_rm="${ezjail_restart_files_for_rm} ${ezjail_rootdir}/${ezjail_magic_flag_for_restart}"
done

[ "${ezjail_pass}" ] && "${ezjail_restart_script}" restart ${ezjail_pass} | while read s ; do
        echo "`date +"%b %e %H:%M:%S %Z"` `hostname -s` `basename $0`[$$]" $s >> "${ezjail_framework_log}"
done

[ "${ezjail_restart_files_for_rm}" ] && rm -f ${ezjail_restart_files_for_rm}

Как всегда, забыл, что в кроне стрипаются пути ;-)



(1 comment) - (Post a new comment)


[info]cae32
2009-05-06 09:16 am UTC (link)
До кучи, то, что надо сделать внутри машины, но это может любой продвинутый хакер, начиная с 5 лет:

cae% more /usr/local/bin/ezjailreboot
#!/bin/sh

touch /.need_ezjail_restart
cae%

(Reply to this)


(1 comment) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…