Autor Tópico: Sample de arquivo rc  (Lida 6361 vezes)

atmozphera

  • Global Moderator
  • Hero Member
  • *****
  • Mensagens: 440
  • Karma: +0/-0
    • http://www.atmozphera.com.br
Sample de arquivo rc
« Online: Outubro 19, 2006, 10:26:40 pm »
Exemplo de um arquivo rc que fica em /etc/init.d/ como por exemplo:

/etc/init.d/rchttpd2

vamos fazer um arquivo rc para o serviço de FTP (ProFTPD) que irá rodar no servidor, lembrando que:

- é necessário dar permissão de execução para esse arquivo (chmod 744)
- cria-lo em /etc/init.d/ com o nome que você quiser apenas respeitando o rc, no caso:
- depois de pronto, copie-o também para /usr/sbin/ para que comando chkconfig seja possivel de coloca-lo no boot.

Citar
rcproftp

- você pode controla-lo com:

#rcproftp start
#rcproftp restart
#rcproftp stop
#rcproftp status


obs.: o rcproftp status é improvisado, vou pode (e deve) achar uma forma mais prescisa.


Citar
#! /bin/sh
# script RC para o ProFTPD
# Autor: Decio M. Vaz (atmozphera%gmail.com)

. /etc/rc.status

### BEGIN INIT INFO
# Provides: ftpd
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the ftpd daemon
### END INIT INFO


# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset
case "$1" in
    start)
   echo -n "Starting ProFTPD Server"
   ## Start daemon with startproc. If this fails
   ## the echo return value is set appropriate.

   #startproc /usr/sbin/foo
/usr/local/sbin/./proftp

   # Remember status and be verbose
   rc_status -v
   ;;
    stop)
   echo -n "Shutting Down ProFTPD Server"
   ## Stop daemon with killproc and if this fails
   ## set echo the echo return value.

/usr/bin/killall proftpd

   # Remember status and be verbose
   rc_status -v
   ;;
    restart)
   ## If first returns OK call the second, if first or
   ## second command fails, set echo return value.
   $0 stop  &&  $0 start

   # Remember status and be quiet
   rc_status
   ;;
    reload)
   ## Choose ONE of the following two cases:

   ## First possibility: A few services accepts a signal
   ## to reread the (changed) configuration.

   #echo -n "Reload service foo"
   #killproc -HUP /usr/sbin/foo
   #rc_status -v
   ## Exclusive possibility: Some services must be stopped
   ## and started to force a new load of the configuration.

   #$0 stop  &&  $0 start

   # Remember status and be verbose
   #rc_status -v
   ;;
    status)
   echo -n "Checking ProFTPD status: "
ps auwx | grep proftpd
        ## Check status with checkproc, if process is running
   ## checkproc will return with exit status 0.

   #checkproc /usr/sbin/foo && echo OK || echo No process
   ;;
    *)
   echo "Usage: $0 {start|stop|status}"
   exit 1
   ;;
esac
rc_exit
« Última modificação: Outubro 25, 2006, 07:04:08 pm por atmozphera »
"o silêncio preenche nossa insegurança"

Comunidade de Usuários do openSUSE

Sample de arquivo rc
« Online: Outubro 19, 2006, 10:26:40 pm »

Vinny

  • Global Moderator
  • Membro Jr.
  • *****
  • Mensagens: 41
  • Karma: +0/-0
  • -= SUSE Linux Brasil =-
Re: Sample de arquivo rc
« Responder #1 Online: Outubro 24, 2006, 07:47:02 pm »
Uma dica a respeito desde rc "padrão" (específico para SUSE):

Leia o README em /etc/init.d/README

Dentro do /etc/init.d existe o arquivo skeleton que é o arquivo base para a construção de qualquer arquivo de inicialização do SUSE que pode ser iniciado a partir do RunLevel e que pode ser adicionado a inicialização do sistema usando o checkconfig ou o insserv

Outra coisa importante é que o arquivo skeleton ja esta com as permissões setadas, basta fazer um cópia do mesmo com o nome do servico desejado

Citar
goku:/etc/init.d # cp skeleton seu_programa

Edite as opções nele, depois

Citar
goku:/etc/init.d # insserv -d seu_programa

Vai inserir nos níveis default (3 - modo de rede em texto e 5 - modo de rede com o ambiente X)

Citar
goku:/etc/init.d # ls -l rc3.d/*seu_programa
lrwxrwxrwx  1 root root 8 2006-10-24 19:53 rc3.d/K05seu_programa -> ../seu_programa
lrwxrwxrwx  1 root root 8 2006-10-24 19:53 rc3.d/S19seu_programa -> ../seu_programa

goku:/etc/init.d # ls -l rc5.d/*seu_programa
lrwxrwxrwx  1 root root 8 2006-10-24 19:53 rc5.d/K05seu_programa -> ../seu_programa
lrwxrwxrwx  1 root root 8 2006-10-24 19:53 rc5.d/S19seu_programa -> ../seu_programa

Agora vamos gerar o "rc" dentro do patch do sistema

Citar
goku:/etc/init.d # ln -s /etc/init.d/seu_programa /usr/sbin/rcseu_programa

Criou-se o link simbólico para você poder executar rcseu_programa [start|stop|restart]

Citar
goku:/etc/init.d # ls -l /usr/sbin/rcseu_programa
lrwxrwxrwx  1 root root 17 2006-10-24 19:54 /usr/sbin/rcseu_programa -> /etc/init.d/seu_programa

Prontinho, agora você tem seu programa rodando como uma aplicação "SUSE" =P

# /etc/init.d/README

Citar
INIT.D(7)                    The SuSE boot concept                   INIT.D(7)

NAME
       INIT.D - The SuSE boot concept

SYNOPSIS
       /etc/init.d/*

       /etc/sysconfig

DESCRIPTION
       The scripts for controlling the system are placed in /etc/init.d/ (they
       have been moved according to the Linux Standard Base  (LSB)  specifica-
       tion).    These   scripts   are  executed  directly  or  indirectly  by
       /sbin/init,  the  father  of  all  processes.  The   configuration   of
       /sbin/init is given by the file /etc/inittab (see inittab(5)).

       At  boot  time, the boot level master script /etc/init.d/boot is called
       to initialise the system (e.g. file system check, ...).  It  also  exe-
       cutes some hardware init scripts linked into /etc/init.d/boot.d/.  Then
       it calls /etc/init.d/boot.local, which executes the local commands.

       After system startup, /sbin/init will normally switch  on  the  default
       run  level given in /etc/inittab.  It calls the run level master script
       /etc/init.d/rc to start or stop services provided by the other  scripts
       under /etc/init.d/.

       Both  scripts,  then  boot level master script /etc/init.d/boot and the
       the run level master script /etc/init.d/rc starts  all  other  boot  or
       runlevel  scripts  either  sequential  or partial parallel within their
       dependencies order.

       To control the services of a run level, the corresponding  scripts  are
       linked   into   run   level   directories  /etc/init.d/rc<X>.d/,  where
       <X>=0,1,2,3,4,5,6,S is the run level number.

       There are two kinds of symbolic link: start  links,  which  are  called
       when  entering a run level, and stop links, which are called when leav-
       ing a run level.  Note that each service in the run levels 2, 3, 4, and
       5 consists of a start and a stop link.  Within SuSE boot concept a dif-
       ferential link scheme is used to be able to change a runlevel  in  com-
       parision with the former level.

       If  parallel executing of the boot scripts is enabled (see /etc/syscon-
       fig/boot variable RUN_PARALLEL) then both master scripts uses the  pro-
       gram  startpar(8)  which starts or stops multiple services in parallel.
       Startpar(8)  will  look   for   the   files   /etc/init.d/.depend.boot,
       /etc/init.d/.depend.start, and   /etc/init.d/.depend.stop  to  get  the
       dependencies for each service.  The files will be written,  beside  the
       symbolic  links  in  the  boot and runlevel directories, by the program
       insserv(8).

       To avoid redundant starts when changing run levels, only those services
       are started which have no start link in the previous run level.  And to
       avoid redundant stops when changing run levels, only those services are
       stopped  which have no start link in the current level. To control this
       behaviour, the names of the scripts are added on the names of the start
       and stop links.

       To  control  the  order of service starts and stops, the start and stop
       links include a number in their link name.

       The system configuration files in /etc/sysconfig contain  most  of  the
       variables  used  to  configure the installed services.  These variables
       can easily be changed by YaST or by using an  editor.  After  using  an
       editor,  the  script  /sbin/SuSEconfig must be called to distribute the
       settings into the system.

   Some details
       The script /etc/init.d/lpd starts or stops the line printer daemon  for
       the printing service, according to the flag used:

              /etc/init.d/lpd start
       and
              /etc/init.d/lpd stop

       To  do  this  automatically  in run level 3, this script is linked into
       /etc/init.d/rc3.d/ with these two symbolic links

              /etc/init.d/rc3.d/S20lpd -> ../lpd
       and
              /etc/init.d/rc3.d/K20lpd -> ../lpd

       The corresponding link with the letter S is used to  start  a  service.
       For  the  printing service the number between the letter S and the name
       should be greater than the number of the start link of the network ser-
       vice.   The corresponding link with the letter K is used to stop a ser-
       vice. The number of the stop link for the printing  service  should  be
       less  than  that  of  the stop link for the network service so that the
       printer daemon is stopped before shutting down the network service.

   Run levels and their services
       0      This level is used for halting the system. The only  valid  ser-
              vice  for  this  level  is the script halt, which is linked into
              /etc/init.d/rc0.d/.      The      script      halt      executes
              /etc/init.d/halt.local.   Special  system  issues  for  halt  or
              reboot should be added there.

       6      This level is used for rebooting the system. The only valid ser-
              vice  for  this level is the script reboot, which is linked into
              /etc/init.d/rc6.d/.      The     script     reboot      executes
              /etc/init.d/halt.local.   Specials  system  issues  for  halt or
              reboot should be added there.

       S      This mode is used to switch from boot  phase  into  single  user
              mode.   The  last valid service for this mode is the script sin-
              gle, which is linked into /etc/init.d/rcS.d/.  In this mode  you
              have only one console.

       1      According  to  the  Linux Standard Base (LSB) specification this
              runlevel is used to switch from normal runlevel into single user
              mode.  This is different from former SuSE Linux versions!

       2      The  run level 2 is without remote networking. Note that on some
              other systems this is identical with the single user mode.  This
              run level can have more than one virtual console.

       3      The  run  level  3 is with network. This run level is for server
              stations not automatically running X.

       5      The level 5 is with network and xdm(1).  You should have a  con-
              figured and perfectly running X Window System for this work sta-
              tion run level.

       4      The run level 4 is not (yet) used.

       /etc/init.d/skeleton
              This script is a model  for  writing  your  own.   You  can  use
              insserv(8) to include your own script into a run level.

FILES
       /etc/init.d/*
       /etc/init.d/boot
       /etc/init.d/boot.local
       /etc/init.d/halt
       /etc/init.d/halt.local
       /etc/init.d/rc
       /etc/init.d/reboot
       /etc/init.d/skeleton
       /etc/init.d/single
       /etc/init.d/boot.d/S[0-9][0-9]*
       /etc/init.d/rc0.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc1.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc2.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc3.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc4.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc5.d/{K,S}[0-9][0-9]*
       /etc/init.d/rc6.d/{K,S}[0-9][0-9]*
       /etc/init.d/rcS.d/{K,S}[0-9][0-9]*
       /etc/init.d/.depend.boot
       /etc/init.d/.depend.start
       /etc/init.d/.depend.stop
       /etc/inittab
       /etc/sysconfig/boot
       /etc/sysconfig

SEE ALSO
       insserv(8),  startpar(8), init(8), inittab(5), and the SuSE Linux hand-
       book, chapter The SuSE boot concept.

COPYRIGHT
       1996-2005 SuSE Linux AG, Nuernberg, Germany.

AUTHORS
       Florian   La   Roche   <http://www.suse.de/feedback>,    Werner    Fink
       <werner@suse.de>, Burchard Steinbild <http://www.suse.de/feedback>.

4.4 Berkeley Distribution        Nov 15, 2000                        INIT.D(7)
« Última modificação: Outubro 24, 2006, 08:05:40 pm por viniciuskawakami »
Vinny
viniciuskawakami@gmail.com
     _
    °v°      Registered User # 204020
   /(_)\     Registration created 2001-01-31
    ^ ^     Linux/Unix - The O.S.

Powered by SUSE Linux 10.1 Professional
Powered by OpenSolaris