Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Тихий выход из init-скрипта /etc/init.d/blabla
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Russian
View previous topic :: View next topic  
Author Message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Sun Oct 15, 2006 9:58 am    Post subject: Тихий выход из init-скрипта /etc/init.d/b Reply with quote

Допустим, при старте скрипта выполняется проверка на условие (существование файла, к примеру).
Как по тихому выйти из скрипта, если условие не выполняется?
"По тихому", значит без сообщений об ошибке, и без занесения скрипта в список "started".
Back to top
View user's profile Send private message
Roger Enrasson
n00b
n00b


Joined: 08 Oct 2006
Posts: 9
Location: Minsk, Bielarus

PostPosted: Sun Oct 15, 2006 11:58 am    Post subject: Reply with quote

а можно скрипт посмотреть?
_________________
...Far Above The Clouds...
Back to top
View user's profile Send private message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Sun Oct 15, 2006 3:41 pm    Post subject: Reply with quote

Ну, в общем, в данный момент он выглядит примерно так:
Code:
#!/sbin/runscript

depend() {
        use net
        after logger
}

check() {

if [ -z "$MYFILE" ] ; then
        eerror "You need to setup  MYFILE in /etc/conf.d/blabla first"
        return 1
fi

if [ ! -e $MYFILE ] ; then
        return 1
fi
}

start() {
        check || return 1
        ebegin "Starting my-service"
        start-stop-daemon --start --quiet --exec /usr/sbin/my-programm
        eend $?
}

stop() {
        ebegin "Stopping my-service"
        start-stop-daemon --stop --quiet --exec /usr/sbin/my-programm
        eend $?
}


В упрощенном виде, - так:
Code:
#!/sbin/runscript

depend() {
        use net
        after logger
}

start() {
        ebegin "Starting my-service"
        if [ -e $MYFILE ] ; then
        start-stop-daemon --start --quiet --exec /usr/sbin/my-programm
        fi
        eend $?
}

stop() {
        ebegin "Stopping my-service"
        start-stop-daemon --stop --quiet --exec /usr/sbin/my-programm
        eend $?
}


Если, в первом случае, выдается ошибка старта, то во втором скрипт вносится в список "started".
Back to top
View user's profile Send private message
ArtSh
Apprentice
Apprentice


Joined: 05 Aug 2006
Posts: 178
Location: Казань, Россия

PostPosted: Sun Oct 15, 2006 6:29 pm    Post subject: Reply with quote

попробуйте
Code:

start() {
        ebegin "Starting my-service"
        if [ -e $MYFILE ] ; then
        start-stop-daemon --start --quiet --exec /usr/sbin/my-programm
        eend $?
        fi
        eend 1 "file not found"
}


Вобщем самое важное -- eend 1
Back to top
View user's profile Send private message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Sun Oct 15, 2006 8:03 pm    Post subject: Reply with quote

ArtSh wrote:
Вобщем самое важное -- eend 1

Попробовал, даёт "ERROR: ... failed to start"
Можно было бы, запускать этот скрипт из другого, после проверки условия, но это слишком сложно, нужно провернуть как можно проще.
Back to top
View user's profile Send private message
ova
Retired Dev
Retired Dev


Joined: 06 Nov 2003
Posts: 120
Location: Russia, Moscow

PostPosted: Wed Oct 18, 2006 11:27 am    Post subject: Re: Тихий выход из init-скрипта /etc/init Reply with quote

gtlinuxman wrote:
Допустим, при старте скрипта выполняется проверка на условие (существование файла, к примеру).
Как по тихому выйти из скрипта, если условие не выполняется?
"По тихому", значит без сообщений об ошибке, и без занесения скрипта в список "started".


Честно говоря я не очень понимаю в чём смысл. Зачем так надо?

Если пользователь добавил нечно на runlevel, значит пользователь хочет чтобы оно стартовало.

А так. Вам просто нужно выйти из скрипта вернув 1. Что-то типа
Code:

checkconfig() {
        [ -f /etc/config ] || return 1
}

start() {
        checkconfig ||  return 1
}


Или другими словами уберите в вашем скрипте eerror и скрипт не будет писать ошибок :)
Back to top
View user's profile Send private message
Galchonok
Tux's lil' helper
Tux's lil' helper


Joined: 15 May 2006
Posts: 99
Location: Н.Новгород

PostPosted: Wed Oct 18, 2006 12:05 pm    Post subject: Reply with quote

а в /etc/conf.d/local,start
ваш скрипт прописать (вписать) ?
и все ... тихо мирно все запустится и отработает :]

собственно local.start для такого как я понимаю и сделан :]
Back to top
View user's profile Send private message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Wed Oct 18, 2006 4:07 pm    Post subject: Re: Тихий выход из init-скрипта /etc/init Reply with quote

Volkov_Peter wrote:

Если пользователь добавил нечно на runlevel, значит пользователь хочет чтобы оно стартовало.

Надо, чтобы оно стартовало ТОЛЬКО при определённом условии, а если условие не выполнилось, то тихо убраться с глаз долой, не выдёргивая юзера из gensplash, к примеру.
Volkov_Peter wrote:

Или другими словами уберите в вашем скрипте eerror и скрипт не будет писать ошибок :)

неее, ошибка всё равно будет, о провале старта :)

Galchonok, на данный момент так оно и есть :)

Хорошо, вот взгляните зачем это надо.
Один Друг надумал Приёмы работы с UDEV
Back to top
View user's profile Send private message
ova
Retired Dev
Retired Dev


Joined: 06 Nov 2003
Posts: 120
Location: Russia, Moscow

PostPosted: Wed Oct 18, 2006 4:20 pm    Post subject: Re: Тихий выход из init-скрипта /etc/init Reply with quote

gtlinuxman wrote:

неее, ошибка всё равно будет, о провале старта :)


:?: В какой момент?

Вот скрипт:

Code:

*chroot* ~ $ cat /etc/init.d/foo
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

chkconfig() {
        [ -f /etc/file_not_exist ] || return 1
}

start() {
        chkconfig || return 1
        return 0
}

stop() {
        :
}


А вот я его запускаю:
Code:

*chroot* ~ $ /etc/init.d/foo start
*chroot* ~ $ /etc/init.d/foo start
*chroot* ~ $


Никаких сообщений об ошибках...
Back to top
View user's profile Send private message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Thu Oct 19, 2006 7:40 am    Post subject: Re: Тихий выход из init-скрипта /etc/init Reply with quote

Volkov_Peter wrote:
Никаких сообщений об ошибках...

Code:
# /etc/init.d/foo start
 * Service foo starting
 * ERROR:  foo failed to start

ы у Вас другой Gentoo? В /etc/confd.d/rc RC_VERBOSE="no" :(
Back to top
View user's profile Send private message
ova
Retired Dev
Retired Dev


Joined: 06 Nov 2003
Posts: 120
Location: Russia, Moscow

PostPosted: Thu Oct 19, 2006 9:01 am    Post subject: Re: Тихий выход из init-скрипта /etc/init Reply with quote

gtlinuxman wrote:

Code:
# /etc/init.d/foo start
 * Service foo starting



Посмотрите сорцы. Отличие у нас с вами в том, что у вас стоит RC_PARALLEL="yes" а у меня "no".

Но есть возможность добавить RC_QUIET="yes" в /etc/conf.d/rc. Тогда сообщения тоже не будет. Но эта опция не документирована, может иметь побочные эффекты (смотрите сорцы :wink: ) и возможно будет в убрана в следующей версии. Я уточню...

Между прочим из командной строки можно делать так:
Code:
# /etc/init.d/foo --quiet start
 * Service foo starting
Back to top
View user's profile Send private message
ova
Retired Dev
Retired Dev


Joined: 06 Nov 2003
Posts: 120
Location: Russia, Moscow

PostPosted: Thu Oct 19, 2006 10:04 am    Post subject: Reply with quote

И вот ответ от uberlord'а разработчика baselayout:
Quote:

Service messages are always printed. It's a side effect of parallel startup.
The good news is that baselayout-1.13 has this fixed by buffering e* output.

So if that's a must, then they must use baselayout-1.13 or just turn off
parallel startup :)


Так что думаю всё ясно :D
Back to top
View user's profile Send private message
gtlinuxman
n00b
n00b


Joined: 15 Oct 2006
Posts: 10

PostPosted: Thu Oct 19, 2006 11:21 am    Post subject: Reply with quote

Volkov_Peter wrote:
Так что думаю всё ясно :D

Да, теперь ясно. Большое спасибо, Volkov_Peter, передайте мою благодарность uberlord:)

Думаю, что в таких случаях, дополнительный скрипт проверки (в local.start, или отдельный) в данный момент остается лучшим выходом.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Russian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum