logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

#1 08-10-2013 15:29:23

lamoule74
Membre
Distrib. : Debarm (Debian arrangé pour un processeur ARM)
Noyau : Linux 2.6.38 (oldstable)
(G)UI : aucun
Inscription : 30-04-2013

faire son propre service/daemon

Bonjour à tous, j'essaye de faire un script de démarrage qui lance 2 applications et je suis en train de le tester pour voir si simplement le start et le stop fonctionnent:

Je souhaite lancer un exécutable compilé avec gcc et le logiciel mjpg streamer. Du coup j'ai suivi un tuto qui conseillait de récupérer le fichier d'exemple "skeleton"
mais je rencontre des petits soucis...

1. je dois passer les arguments :

-i "/root/mjpg-streamer/input_uvc.so -f 13 -r 640x480" -o "/root/mjpg-streamer/output_http.so -w /root/mjpg-streamer/www"



(tels quels dans le terminal) mais je n'arrive pas les passer dans la variable DAEMON_ARGS_2, par contre j'y arrive en y écrivant en dur... (en dé-commentant la ligne 61)

2.je n'obtiens pas les message de démarrage et d'arrêt du script.. (lignes 112 et 120, pas essayé les autres )

Je vous le mets en dessous pour que vous puissiez comprendre ce que je souhaite faire...


     1  #! /bin/sh
     2  ### BEGIN INIT INFO
     3  # Provides:   skeleton
     4  # Required-Start: $remote_fs $syslog
     5  # Required-Stop:  $remote_fs $syslog
     6  # Default-Start:  2 3 4 5
     7  # Default-Stop:   0 1 6
     8  # Short-Description:  Example initscript
     9  # Description:    This file should be used to construct scripts to be
    10  #     placed in /etc/init.d.
    11  ### END INIT INFO
    12 
    13  # Author: OB
    14 
    15  # Do NOT "set -e"
    16 
    17  # PATH should only include /usr/* if it runs after the mountnfs.sh script
    18  PATH=/sbin:/usr/sbin:/bin:/usr/bin
    19  DESC="firefighter robot's program"
    20  NAME=shm_datas
    21  NAME_2=mjpg_streamer
    22  DAEMON=/root/Programmes/$NAME
    23  DAEMON_2=/root/mjpg-streamer/$NAME_2
    24  DAEMON_ARGS=""
    25  DAEMON_ARGS_2="-i '/root/mjpg-streamer/input_uvc.so -f 13 -r 640x480' -o '/root/mjpg-streamer/output_http.so -w /root/mjpg-streamer/www'"
    26  PIDFILE=/var/run/$NAME.pid
    27  PIDFILE_2=/var/run/$NAME_2.pid
    28  SCRIPTNAME=/etc/init.d/firefighter
    29 
    30  # Exit if the package is not installed
    31  [ -x "$DAEMON" ] || exit 0
    32  [ -x "$DAEMON_2" ] || exit 0
    33 
    34  # Read configuration variable file if it is present
    35  [ -r /etc/default/$NAME ] && . /etc/default/$NAME
    36  [ -r /etc/default/$NAME_2 ] && . /etc/default/$NAME_2
    37 
    38  # Load the VERBOSE setting and other rcS variables
    39  . /lib/init/vars.sh
    40 
    41  # Define LSB log_* functions.
    42  # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
    43  # and status_of_proc is working.
    44  . /lib/lsb/init-functions
    45 
    46  #
    47  # Function that starts the daemon/service
    48  #
    49  do_start()
    50  {
    51    # Return
    52    #   0 if daemon has been started
    53    #   1 if daemon was already running
    54    #   2 if daemon could not be started
    55    start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON --test > /dev/null && \
    56    start-stop-daemon --start --quiet --background --pidfile $PIDFILE_2 --exec $DAEMON_2 --test > /dev/null \
    57      || return 1
    58    start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- \
    59      $DAEMON_ARGS && \
    60    start-stop-daemon --start --quiet --background --pidfile $PIDFILE_2 --exec $DAEMON_2 -- \
    61      #-i "/root/mjpg-streamer/input_uvc.so -f 13 -r 640x480" -o "/root/mjpg-streamer/output_http.so -w /root/mjpg-streamer/www" \
    62      $DAEMON_ARGS_2 \
    63      || return 2
    64    # Add code here, if necessary, that waits for the process to be ready
    65    # to handle requests from services started subsequently which depend
    66    # on this one.  As a last resort, sleep for some time.
    67  }
    68 
    69  #
    70  # Function that stops the daemon/service
    71  #
    72  do_stop()
    73  {
    74    # Return
    75    #   0 if daemon has been stopped
    76    #   1 if daemon was already stopped
    77    #   2 if daemon could not be stopped
    78    #   other if a failure occurred
    79    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    80    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE_2 --name $NAME_2
    81    RETVAL="$?"
    82    [ "$RETVAL" = 2 ] && return 2
    83    # Wait for children to finish too if this is a daemon that forks
    84    # and if the daemon is only ever run from this initscript.
    85    # If the above conditions are not satisfied then add some other code
    86    # that waits for the process to drop all resources that could be
    87    # needed by services started subsequently.  A last resort is to
    88    # sleep for some time.
    89    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    90    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON_2
    91    [ "$?" = 2 ] && return 2
    92    # Many daemons don't delete their pidfiles when they exit.
    93    rm -f $PIDFILE $PIDFILE_2
    94    return "$RETVAL"
    95  }
    96 
    97  #
    98  # Function that sends a SIGHUP to the daemon/service
    99  #
   100  do_reload() {
   101    #
   102    # If the daemon can reload its configuration without
   103    # restarting (for example, when it is sent a SIGHUP),
   104    # then implement that here.
   105    #
   106    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
   107    return 0
   108  }
   109 
   110  case "$1" in
   111    start)
   112    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME & $NAME_2"
   113    do_start
   114    case "$?" in
   115      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
   116      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   117    esac
   118    ;;
   119    stop)
   120    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME & $NAME_2"
   121    do_stop
   122    case "$?" in
   123      0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
   124      2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
   125    esac
   126    ;;
   127    status)
   128         status_of_proc "$DAEMON" "$NAME & $NAME_2" && exit 0 || exit $?
   129         ;;
   130    #reload|force-reload)
   131    #
   132    # If do_reload() is not implemented then leave this commented out
   133    # and leave 'force-reload' as an alias for 'restart'.
   134    #
   135    #log_daemon_msg "Reloading $DESC" "$NAME"
   136    #do_reload
   137    #log_end_msg $?
   138    #;;
   139    restart|force-reload)
   140    #
   141    # If the "reload" option is implemented then remove the
   142    # 'force-reload' alias
   143    #
   144    log_daemon_msg "Restarting $DESC" "$NAME & $NAME_2"
   145    do_stop
   146    case "$?" in
   147      0|1)
   148      do_start
   149      case "$?" in
   150        0) log_end_msg 0 ;;
   151        1) log_end_msg 1 ;; # Old process is still running
   152        *) log_end_msg 1 ;; # Failed to start
   153      esac
   154      ;;
   155      *)
   156      # Failed to stop
   157      log_end_msg 1
   158      ;;
   159    esac
   160    ;;
   161    *)
   162    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
   163    exit 3
   164    ;;
   165  esac





Merci d'avance.


Ubuntu est un mot africain qui signifie, je n'ai pas réussi à configurer ma Debian.

Hors ligne

#2 09-10-2013 10:47:26

lamoule74
Membre
Distrib. : Debarm (Debian arrangé pour un processeur ARM)
Noyau : Linux 2.6.38 (oldstable)
(G)UI : aucun
Inscription : 30-04-2013

Re : faire son propre service/daemon

bon le premier problème est résolu en créant un tableau, j'ai remplacé la 1ère ligne par

#!/bin/bash


la 25ème par

DAEMON_ARGS_2=( -i '/root/mjpg-streamer/input_uvc.so -f 13 -r 640x480' -o '/root/mjpg-streamer/output_http.so -w /root/mjpg-streamer/www' )


j'ai supprimé la 61 (le commentaire foutai le bronx a cause du retour à la ligne)
et la 62ème je l'aie modifiée également par

"${DAEMON_ARGS_2[@]}" \



Par contre je ne comprends toujours pas pourquoi les messages de start et de stop ne fonctionnent pas... (je suppose que reload etc.. non plus, j'ai pas essayé...) neutral


Ubuntu est un mot africain qui signifie, je n'ai pas réussi à configurer ma Debian.

Hors ligne

#3 13-11-2013 08:33:21

lamoule74
Membre
Distrib. : Debarm (Debian arrangé pour un processeur ARM)
Noyau : Linux 2.6.38 (oldstable)
(G)UI : aucun
Inscription : 30-04-2013

Re : faire son propre service/daemon

up neutral

Ubuntu est un mot africain qui signifie, je n'ai pas réussi à configurer ma Debian.

Hors ligne

Pied de page des forums