# Start-stop-daemon pour un serveur PHP

**URL:** <https://www.debian-fr.org/t/start-stop-daemon-pour-un-serveur-php/58762>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 5:59 UTC](https://www.debian-fr.org/t/start-stop-daemon-pour-un-serveur-php/58762 "2016-02-21T17:59:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThinkTank](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@ThinkTank](https://www.debian-fr.org/u/ThinkTank)\
**Post date:** [Février 21, 2016, 5:59 UTC](https://www.debian-fr.org/t/start-stop-daemon-pour-un-serveur-php/58762/1 "2016-02-21T17:59:04Z")

</div>

Bonjour,  
je travail actuellement sur un serveur de socket écrit en PHP.  
Cette partie du travail fonctionne bien. (je l’ai testé avec nohup, pas de problème.)

Cependant j’ai un problème pour le lancer.  
En effet, j’ai écrit un script utilisant `start-stop-daemon` mais celui-ci ne fonctionne pas.  
Pour ce script, je me suis basé sur l’exemple suivant :  
[http://till.klampaeckel.de/blog/archives/94-start-stop-daemon,-Gearman-and-a-little-PHP.html](http://till.klampaeckel.de/blog/archives/94-start-stop-daemon,-Gearman-and-a-little-PHP.html)

Merci d’avance pour votre aide !

```auto

#! /bin/sh
 
### BEGIN INIT INFO
# Provides: ServerTicket
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts ServerTicket
# Description: starts ServerTicket using start-stop-daemon
### END INIT INFO

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/zend/bin/php
DAEMON_OPTS="/var/www/server/consultpilot/ServerTicket.php"
NAME=server-ticket
DESC="Daemon for the Server Ticket from DiffMed"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"
QUIET="--quiet"
START_OPTS="--start ${QUIET} --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"

# START_OPTS="${DAEMON} ${DAEMON_OPTS} &> ${LOGFILE}2>&1&"
# STOP_OPTS="--stop --pidfile ${PIDFILE}"
 
test -x $DAEMON || exit 0
 
set -e
 
case "$1" in
	start)
		echo -n "Starting $DESC: "
		start-stop-daemon $START_OPTS >> "${LOGFILE}" 2>> "${LOGFILE}" </dev/null		
                echo "result : ${?}"
		echo "$NAME."
		;;
	stop)
		echo -n "Stopping $DESC: "
		start-stop-daemon $STOP_OPTS
		echo "$NAME."
		rm -f $PIDFILE
		;;
	restart|force-reload)
		echo -n "Restarting $DESC: "
		start-stop-daemon $STOP_OPTS
		sleep 1
		start-stop-daemon $START_OPTS
		echo "$NAME."
		;;
*)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac
 
exit 0

```

Pour information, voilà ce qu’il se passe quand je lance puis stop le script.  
Le result 0 correspond a la valeur retournée par le

```auto

    root:/var/run$ service server-ticket start
    Starting Daemon for the Server Ticket from DiffMed: result : 0
    server-ticket.
    root:/var/run$ service server-ticket stop
    Stopping Daemon for the Server Ticket from DiffMed: start-stop-daemon: warning: failed to kill 5772: No such process
    1 pids were not killed
    No process in pidfile '/var/run/server-ticket.pid' found running; none killed.

```

---

<div class="post-metadata">

**Author:** ![Mimoza](https://www.debian-fr.org/user_avatar/www.debian-fr.org/mimoza/32/3858_2.png) [@Mimoza](https://www.debian-fr.org/u/Mimoza)\
**Post date:** [Février 21, 2016, 5:59 UTC](https://www.debian-fr.org/t/start-stop-daemon-pour-un-serveur-php/58762/2 "2016-02-21T17:59:06Z")

</div>

Ton script a l’air pas mal mais la prochaine fois part du fichier d’exemple qui se trouve là : «&nbsp;/init.d/skeleton&nbsp;»

Sinon il faudrait que tu fasse un (h)top ou tout autre «&nbsp;ps&nbsp;» pour voir quel est le PID de ton processus démon. Là j’ai l’impression que ton PHP exécute un script qui va créer un autre processus qui lui tourne en démon. Alors qu’il faut absolument que le PID du processus lancé soit identique au processus à tuer.

> [@](#):
>
> failed to kill 5772: No such process

Ce message le dit clairement.

Ton script dans init.d lance le processus A qui lance le processus B, A se termine, B continue de tourner sans problème et quand tu fait «&nbsp;STOP&nbsp;» le script essaye d’arrêter A qui est déjà terminer. Si tu dois obligatorement passer par un sous processus il doit exister une commande qui laisse la place au suivant sans changer de PID, genre «&nbsp;exec&nbsp;».
