Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 50

Thread: Шаблон скриптов инициализации init.d

  1. #16
    Quote Originally Posted by djet View Post
    О вкусах не спорят, у вас другой шелл? И скрипты у меня всё равно ни фига не кросс-платформенные.
    у меня /bin/sh для всех скриптов (и дело не во вкусе).
    vim имеет два режима - бибикать и все портить (с) не мое

  2. #17
    + $2 в качестве источника вызова
    + убрал bash, пока без него всё работает
    + добавлены проверки на успешность запуска и останова, улучшена логика работы
    + простой вариант дейсвтий reconfigure и kill
    + примитивный вариант запуска нескольких демонов из одного конфига ($PROC -> $PROCS, например, PROCS="smbd nmbd"). Как лучше реализовать передачу нескольких наборов переменных в скрипте?

    Практически все скрипты привёл к стандартному виду, остались только syslog и rtorrent.

    Как это выглядит сейчас:

    Code:
    [routah:init.d] time /opt/etc/init.d/rc.unslung stop
    Stopping rtorrent: rtorrent.
    Checking asterisk...            alive.
    Shutting down asterisk...               done.
    Checking upnp...                alive.
    Shutting down upnp...           done.
    Checking udpxy...               alive.
    Shutting down udpxy...          done.
    Checking httpd...               alive.
    Shutting down busybox_httpd...          done.
    Checking atd...                 alive.
    Shutting down atd...            done.
    Checking xinetd...              alive.
    Shutting down xinetd...                 done.
    Checking cron...                alive.
    Shutting down cron...           done.
    Checking samba...               alive.
    Shutting down smbd...           done.
    Checking samba...               alive.
    Shutting down nmbd...           done.
    Checking dnsmasq...             alive.
    Shutting down dnsmasq...                done.
    Checking syslog-ng...           alive.
    Shutting down syslog-ng...              done.
    
    real    0m9.727s
    user    0m1.210s
    sys     0m4.280s
    
    [routah:init.d] time /opt/etc/init.d/rc.unslung start
    Starting syslog-ng...           done.
    Starting dnsmasq...             done.
    Starting samba...               done.
    Starting samba...               done.
    Starting cron...                done.
    Starting xinetd...              done.
    Starting atd...                 done.
    Starting httpd...               done.
    Starting udpxy...               done.
    Starting upnp...                done.
    Starting asterisk...            done.
    
    real    0m6.947s
    user    0m1.310s
    sys     0m4.260s
    
    [routah:init.d] time /opt/etc/init.d/rc.unslung kill
    Checking syslog-ng...           alive.
    Killing syslog-ng...            done.
    Checking dnsmasq...             alive.
    Killing dnsmasq...              done.
    Checking samba...               alive.
    Killing smbd...                 done.
    Checking samba...               alive.
    Killing nmbd...                 done.
    Checking cron...                alive.
    Killing cron...                 done.
    Checking xinetd...              alive.
    Killing xinetd...               done.
    Checking atd...                 alive.
    Killing atd...          done.
    Checking httpd...               alive.
    Killing busybox_httpd...                done.
    Checking udpxy...               alive.
    Killing udpxy...                done.
    Checking upnp...                alive.
    Killing upnp...                 done.
    Checking asterisk...            alive.
    Killing asterisk...             done.
    Usage: /etc/init.d/ {start|manualstart|stop|manualrestart|restart|force-reload}
    
    real    0m5.157s
    user    0m1.380s
    sys     0m3.600s
    
    [routah:init.d] time /opt/etc/init.d/rc.unslung start
    Starting syslog-ng...           done.
    Starting dnsmasq...             done.
    Starting samba...               done.
    Starting samba...               done.
    Starting cron...                done.
    Starting xinetd...              done.
    Starting atd...                 done.
    Starting httpd...               done.
    Starting udpxy...               done.
    Starting upnp...                done.
    Starting asterisk...            done.
    
    real    0m6.572s
    user    0m1.260s
    sys     0m3.850s
    
    [routah:init.d] time /opt/etc/init.d/rc.unslung start
    Starting syslog-ng...           already running.
    Starting dnsmasq...             already running.
    Starting samba...               already running.
    Starting samba...               already running.
    Starting cron...                already running.
    Starting xinetd...              already running.
    Starting atd...                 already running.
    Starting httpd...               already running.
    Starting udpxy...               already running.
    Starting upnp...                already running.
    Starting asterisk...            already running.
    
    real    0m2.469s
    user    0m0.600s
    sys     0m1.850s
    Last edited by djet; 29-02-2008 at 00:29.

  3. #18
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    рекомендую проверить следующее:

    добавить в pre-shutdown:

    PHP Code:
    /opt/etc/init.d/rc.unslung stop

    /opt/bin/ps aux > /opt/pre-shutdown.log 
    Я наблюдаю странную картину, что если при ручном запуске stop процессы нормально завершаются, то из pre-shutdown многие вместо завершения переходят в состояние <defunct>. Любопытно почему.

  4. #19
    Действительно, не убиваются, дажё kill'ом..

    Code:
    /opt/etc/init.d/rc.unslung stop ${SCRIPTNAME}
    /opt/bin/ps aux > /opt/pre-shutdown.log
    /opt/etc/init.d/rc.unslung kill
    /opt/bin/ps aux > /opt/pre-shutdown2.log
    lsof -t /opt | xargs kill -9
    /opt/bin/ps aux > /opt/pre-shutdown3.log
    [routah:root] grep defu /opt/pre-shutdown3.log
    djet 234 0.0 0.0 0 0 ? Zs 01:58 0:00 [pppd] <defunct>
    djet 238 0.0 0.0 0 0 ? Z 01:58 0:00 [pptp] <defunct>
    djet 303 0.0 0.0 0 0 ? Z 01:58 0:00 [pptp] <defunct>
    djet 3584 0.0 0.0 0 0 ? Zs 03:13 0:02 [syslog-ng] <defunct>
    nobody 3592 0.0 0.0 0 0 ? Z 03:13 0:00 [dnsmasq] <defunct>
    djet 3603 0.0 0.0 0 0 ? Zs 03:13 0:00 [smbd] <defunct>
    djet 3612 0.0 0.0 0 0 ? Zs 03:13 0:03 [nmbd] <defunct>
    djet 3621 0.0 0.0 0 0 ? Zs 03:13 0:00 [cron] <defunct>
    djet 3632 0.0 0.0 0 0 ? Zs 03:13 0:00 [xinetd] <defunct>
    nobody 3642 0.0 0.0 0 0 ? Z 03:13 0:00 [atd] <defunct>
    djet 3653 0.0 0.0 0 0 ? Z 03:13 0:00 [busybox_httpd] <defunct>
    djet 3664 0.0 0.0 0 0 ? Z 03:13 0:00 [udpxy] <defunct>
    djet 3675 0.0 0.0 0 0 ? Z 03:13 0:07 [upnp] <defunct>
    djet 3686 0.0 0.0 0 0 ? Z< 03:13 0:00 [asterisk] <defunct>

  5. #20
    Quote Originally Posted by al37919 View Post
    рекомендую проверить следующее:

    добавить в pre-shutdown:

    PHP Code:
    /opt/etc/init.d/rc.unslung stop

    /opt/bin/ps aux > /opt/pre-shutdown.log 
    Я наблюдаю странную картину, что если при ручном запуске stop процессы нормально завершаются, то из pre-shutdown многие вместо завершения переходят в состояние <defunct>. Любопытно почему.
    Кажется, нашлось объяснение:
    Defunct (or zombie) process is a process that has terminated (either because it has been killed by a signal or because it has called exit()) and whose parent process has not yet received notification of its termination by executing (some form of) the wait() system call.

    A zombie process exists solely as a process table entry and consumes no other resources. This entry is retained to hold the child's exit status until the parent process wants to retrieve it. The parent can also be notified asynchronously via a signal of the child's termination.

    So this process doesn't consume any resources other than one entry in the process table. As jools already pointed out, there is no reason to worry about this process unless you have many defunct processes. If you have many defunct processes process table can get filled and you won't be able to start new processes.
    Похоже, всё в порядке. lsof показывает, что все ресурсы освобождены после первого же stop.

  6. #21
    + немного косметики

  7. #22

    Пуско-останавливатель для transmission

    djet, спасибо большущее!
    Воспользовался шаблонами. Все замечательно работает.
    Есть у меня одна просьбочка...
    Помогите, плиз, сделать пуско-остановочный скрипт для transmission (что-то типа S77transmission).
    Для меня проблема в том, что для transmission-а запускать надо transmission_watchdog, а останавливать transmissiond.
    Т.е. не хватает одной PROCS. Надо как-то ее разбить на PROCS_STRT и PROCS_STP

  8. #23
    Добавил также флажок $CRITICAL - используется у меня в проверках состояния критически важных процессов из cron'a.

  9. #24

    Question S95samba

    Для запуска samba3 использую скрипт S95samba:
    Code:
    PROCS="smbd nmbd"
    ARGS="-D"
    PREARGS=""
    DESC=$PROCS
    PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    При рестарте выводит:
    Code:
    [init.d]$ ./rc.unslung restart
    Shutting down smbd...              done.
    Starting smbd nmbd...              done.
    Shutting down nmbd...              done.
    Starting smbd nmbd...              done.
    Shutting down vsftpd...              done.
    Starting vsftpd...              done.
    Starting rsync...              done.
    Shutting down cron...              done.
    Starting cron...              done.
    Starting syslog-ng...              done.
    Меня несколько смущает, что после этого висит несколько демонов smbd.

    Code:
    [init.d]$ ps -A | grep bd
     1330 ?        00:00:00 smbd
     1346 ?        00:00:00 nmbd
     1362 ?        00:00:00 smbd
    Так и должно быть?

  10. #25

    Question Syslog-ng

    Попробовал запустить syslog-ng как описано в http://wl500g.info/showthread.php?t=...ight=syslog-ng

    Думает секунд 10, потом выдаёт.
    Code:
    Starting syslog-ng...              failed.
    Привожу S01syslog-ng

    Code:
    #!/bin/sh
    #
    # Startup script for syslog-ng
    #
    
    PROCS=syslog-ng
    ARGS=""
    PREARGS="/opt/etc/init.d/log-ng"
    DESC=$PROCS
    PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/etc/init.d
    
    . /opt/etc/init.d/rc.func
    Т.к. предполагается, что перед запуском должен отработать ещё один скрипт то я его выделил в отдельный файл "/opt/etc/init.d/log-ng".

    log-ng:
    Code:
    #!/bin/sh
    #
    # Startup script for syslog-ng
    #
    
    # copy content of original syslogd to new syslog.
    cat /tmp/syslog.log >> /opt/var/log/syslog-ng.log
    # remove old syslog.log
    rm /tmp/syslog.log
    
    ln -s /opt/var/log/syslog-ng.log /tmp/syslog.log

  11. #26

    init.d и rc.unslung

    Почему-то не запускается rc.unslung.
    # ls /opt/etc/init.d
    S01syslog-ng S95samba rc.unslung
    все файлы chmod +x
    соответственно не грузятся Syslog-ng и samba 3
    [admin@Server init.d]$ cat rc.unslung
    #!/bin/sh
    for i in /opt/etc/init.d/S??* ;do
    [ ! -f "$i" ] && continue
    case "$i" in
    *.sh)
    (
    trap - INT QUIT TSTP
    set start
    . $i
    )
    ;;
    *)
    $i start
    ;;
    esac
    [admin@Server init.d]$ cat S01syslog-ng
    #!/bin/sh
    #
    # Startup script for syslog-ng
    #

    # Stop syslogd if running
    if [ -n "`pidof syslogd`" ]; then
    killall syslogd 2>/dev/null
    sleep 1
    fi
    if [ -n "`pidof klogd`" ]; then
    killall klogd 2>/dev/null
    sleep 1
    fi
    # copy content of original syslogd to new syslog.
    cat /tmp/syslog.log >> /opt/var/log/syslog-ng.log
    # remove old syslog.log
    rm /tmp/syslog.log
    ln -s /opt/var/log/syslog-ng.log /tmp/syslog.log
    # Stop itself if running
    if [ -n "`pidof syslog-ng`" ]; then
    killall syslog-ng 2>/dev/null
    sleep 2
    fi

  12. #27
    в S01syslog-ng нет команд запуска демона.
    И зачем-то в конце скрипта команда на останов syslog-ng:
    Code:
    .....
    # Stop itself if running
    if [ -n "`pidof syslog-ng`" ]; then
    killall syslog-ng 2>/dev/null
    sleep 2
    fi

  13. #28
    Quote Originally Posted by kodmis View Post
    в S01syslog-ng нет команд запуска демона.
    И зачем-то в конце скрипта команда на останов syslog-ng:
    Code:
    .....
    # Stop itself if running
    if [ -n "`pidof syslog-ng`" ]; then
    killall syslog-ng 2>/dev/null
    sleep 2
    fi
    Извиняюсь, просто не захватилась эта строчка. А так - все есть. Последний киллалл служит для выгрузки сислога, если он уже запущен (на момент запуска скрипта), что бы 2 раза не запустить сислог.

    Мое предположение - надо куда-то вписать запуск rc.unslung. В ручную запускается все по этому скрипту, а при перезагрузке - нет. Т.е. тупо не стартует.
    Last edited by Heavy; 13-11-2008 at 21:11.

  14. #29
    Конечно надо вписать
    в post-mount его

  15. #30
    Quote Originally Posted by kodmis View Post
    Конечно надо вписать
    в post-mount его
    тогда какой смысл от syslog-ng, если он запустится только после монтирования всех устройств? Надо же видеть лог загрузки системы,а не лог того, что после загрузки.Ну, например надо видеть как монтируются устройства, как запускается самба, и т.п. Че за бред...? Какой тогда смысл менять стандартный логгер на этот?

Page 2 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •