Précédent   Forum des professionnels en informatique > Systèmes > Linux > Distributions > Debian
Debian Vos questions sur la distribution Debian
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
Vieux 09/11/2009, 14h26   #1
Membre éprouvé
 
Avatar de paissad
 
Homme
Étudiant
Inscription : avril 2006
Messages : 316
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2006
Messages : 316
Points : 444
Points : 444
Envoyer un message via Skype™ à paissad
Par défaut problème script init.d sur debian

bonjour,
je voudrais faire un script init.d et le problème est qu'il ne marche pas pour start, je n'ai pas encore fini de le programmer pour pour restart|reload etc ...
Voici le script complet
http://pastebin.com/f36a3b47c
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/sh
#
# init script for the ps3 media server for linux : pms-server
 
# Author: paissad
 
### BEGIN INIT INFO
# Provides:          pms-linux
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Media server for the playstation 3 
### END INIT INFO
 
# Author: Torsten Landschoff <torsten@debian.org>
 
NAME="pms-linux"
version="1.10.5"  # Version du logiciel 
DAEMON="/usr/bin/java"
OPTIONS="-jar /opt/$NAME/$NAME-$version/pms.jar"
DESC="Playstation 3 Media Server"
CONFIG_FILE="/etc/PMS.conf" # fichier de conf par défaut
CONFIG_DIR="`dirname "$CONFIG_FILE"`"
USERID="paissad"
PIDFILE="/var/run/$NAME.pid"
 
. /lib/lsb/init-functions
 
#set -x
 
# On vérifie que le fichier de conf PMS.conf est bien dans le repertoire /etc
if [ ! -e "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration /etc/PMS.conf est inexistant !" 
	exit 1
fi
 
if [ ! -r "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration PMS.conf n'est pas disponible en lecture !"
	exit 1
fi
 
is_running(){
	pid=`pgrep -f '^[^ ]*java .*-jar.*pms.jar'`
	if [ -n "$pid" ]; then
		return 1 # pms.jar tourne
	fi
	pid=0
	return 0 # pms.jar qui est le serveur est pas lancé, ni manuellment ni par le init.d
}
is_running
echo "pid -> $pid"
 
case "$1" in 
#--------------------------------------------------------------------------
	start)
	if [ ! $pid -eq 0 ]; then
		echo "pms-linux-server is already running !"
		exit 0
	fi
	log_daemon_msg "Starting $DESC : $NAME"
	echo
	#start-stop-daemon --start --quiet --background --chdir "$CONFIG_DIR" --exec $DAEMON $OPTIONS 
	start-stop-daemon --start --quiet --background --user "$USERID:$USERID" --chdir "$CONFIG_DIR" --exec $DAEMON $OPTIONS 
	echo "$pid" > $PIDFILE
	;;
#--------------------------------------------------------------------------
	stop)
	if [ $pid -eq 0 ]; then
		echo "pms-linux-server is not running !"
		exit 0
	fi
	log_daemon_msg "Stopping $DESC : $NAME"
	echo
	kill -9 $pid
	`rm -f "$PIDFILE"`
	;;
#--------------------------------------------------------------------------
	restart|reload|force-reload)
	log_daemon_msg "Restarting $DESC : $NAME"
	echo
	start-stop-daemon --stop --quiet --exec $DAEMON
	sleep 5
	start-stop-daemon --start --quiet --exec $DAEMON
	;;
#--------------------------------------------------------------------------
	status)
	if [ ! $pid -eq 0 ]; then
		echo "pms-linux-server is running ! (PID -> $pid)"
		exit 0
	fi
	echo "pms-linux-server is not running !"
	;;
#--------------------------------------------------------------------------
	*)
	echo "Usage: /etc/init.d/$NAME-server {start|stop|restart|reload|force-reload|status}"
	exit 1
#--------------------------------------------------------------------------
esac
 
exit 0
je l'ai testé pour stop et status, ça marche bien ...
mais il a fallu que je démarre manuellement le programme
Code :
java -jar /opt/pms-linux/*/pms.jar
Si je le démarre manuellement en console, le programme voit bien qu'il y'a un PID existant
Code :
1
2
3
paissad@paissad-server:/etc/init.d$ sudo ./pms-linux-server start
pid -> 5877
pms-linux-server is already running !
mais s'il n'y avait pas de PID existant et que je fait
Code :
1
2
3
4
5
6
paissad@paissad-server:/etc/init.d$ sudo ./pms-linux-server start
pid -> 0
Starting Playstation 3 Media Server : pms-linux:
start-stop-daemon: invalid option -- j
Try `start-stop-daemon --help' for more information.
paissad@paissad-server:/etc/init.d$
est ce que quelqu'un peut m'aider, j'ai bien lu le manuel de start-stop-daemon, mais bon .. et j'ai aussi regardé des examples sur le repertoire /etc/init.d mais je ne trouve pas la solution
et pourtant en console, ceci marche
Code :
exec java -jar /opt/pms-linux/*/pms.jar
Merci d'avance pour votre aide
__________________
Nous n'héritons pas de la terre de nos parents, nous l'empruntons à nos enfants.
Slackware for the Subgenius !
http://blog.paissad.net
paissad est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2009, 15h27   #2
Expert Confirmé
 
Avatar de N_BaH
 
Inscription : février 2008
Messages : 1 896
Détails du profil
Informations forums :
Inscription : février 2008
Messages : 1 896
Points : 3 676
Points : 3 676
Il faut deux tirets entre --exec $DAEMON et $OPTIONS :
Code :
start-stop-daemon --start --quiet --background --user "$USERID:$USERID" --chdir "$CONFIG_DIR" --exec $DAEMON -- $OPTIONS
Le $PIDFILE peut être créer par start-stop-daemon, la fonction status n'a plus qu'à vérifier l'existence de ce fichier...

Je te conseille de lire encore les autres scripts présents dans /etc/init.d/; ceux que j'ai lu n'utilisent pas kill -9 (qui est radical) pour tuer le processus lancé.
N_BaH est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2009, 15h30   #3
Membre éprouvé
 
Avatar de paissad
 
Homme
Étudiant
Inscription : avril 2006
Messages : 316
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2006
Messages : 316
Points : 444
Points : 444
Envoyer un message via Skype™ à paissad
Merci pour ta réponse,
comme j'avais dit le script n'est pas encore fini, et je débute sous bash,
j'avais entre temps vu qu'il fallait ajouter les "--" avant $OPTIONS merci beaucoup
et pour l'arret du programme sans utiliser kill -9, c'est ce que je suis entrain de regarder aussi, merci pour la suggestion
Tout marche maintenant, mais j'affine le script
je posterai la version finale par la suite
Cordialement,
__________________
Nous n'héritons pas de la terre de nos parents, nous l'empruntons à nos enfants.
Slackware for the Subgenius !
http://blog.paissad.net
paissad est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2009, 16h13   #4
Membre éprouvé
 
Avatar de paissad
 
Homme
Étudiant
Inscription : avril 2006
Messages : 316
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2006
Messages : 316
Points : 444
Points : 444
Envoyer un message via Skype™ à paissad
j'ai preque fini le script, y'a q'une ligne qui marche pas encore
Voici le script
http://pastebin.com/f381d35c2
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/sh
#
# init script for the ps3 media server for linux : pms-server
 
# Author: paissad
 
### BEGIN INIT INFO
# Provides:          pms-linux
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Media server for the playstation 3 
### END INIT INFO
 
# Author: Torsten Landschoff <torsten@debian.org>
 
NAME="pms-linux"
version="1.10.5"  # Version du logiciel 
DAEMON="/usr/bin/java"
OPTIONS="-jar /opt/$NAME/$NAME-$version/pms.jar"
DESC="Playstation 3 Media Server"
CONFIG_FILE="/etc/PMS.conf" # fichier de conf par défaut
CONFIG_DIR="`dirname "$CONFIG_FILE"`"
USERID=paissad
PIDFILE="/var/run/$NAME.pid"
 
. /lib/lsb/init-functions
 
# On vérifie que le fichier de conf PMS.conf est bien dans le repertoire /etc
if [ ! -e "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration /etc/PMS.conf est inexistant !" 
	exit 1
fi
 
if [ ! -r "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration PMS.conf n'est pas disponible en lecture !"
	exit 1
fi
 
#--------------------------------------------------------------------------
 
is_running(){
	pid=`pgrep -f '^[^ ]*java .*-jar.*pms.jar'`
	if [ -n "$pid" ]; then
		return 1 # pms.jar tourne
	fi
	pid=0
	return 0 # pms.jar qui est le serveur n'est pas lancé, ni manuellment ni par le init.d
}
is_running
 
#--------------------------------------------------------------------------
 
# Cette fonction permet de vérifier si le programme a été lancé via init.d ou manuellement
# S'il existe un fichier .pid dans /var/run alors c'est init.d, sinon .... manuellement.
type_of_start(){
	if [ ! -e $PIDFILE ]; then
		manual="yes"
		echo "WARNING: the server has been started manually"
	fi
}
 
#--------------------------------------------------------------------------
 
d_start(){
	if [ ! $pid -eq 0 ]; then
		echo "pms-linux-server is already running !"
		type_of_start
		exit 0
	fi
	log_daemon_msg "Starting $DESC : $NAME"
	echo
	#start-stop-daemon --start --quiet --background --chdir "$CONFIG_DIR" --exec $DAEMON -- $OPTIONS 
	start-stop-daemon --start --quiet --background --user $USERID --chdir "$CONFIG_DIR" --exec $DAEMON -- $OPTIONS 
	echo "$pid" > $PIDFILE
	log_end_msg $?
 
}
 
#--------------------------------------------------------------------------
 
d_stop(){
	if [ $pid -eq 0 ]; then
		echo "pms-linux-server is NOT running !"
		exit 0
	fi
	type_of_start
	log_daemon_msg "Stopping $DESC : $NAME"
	echo
	start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --user $USERID --exec $DAEMON 
	#kill -9 $pid
	#`rm -f "$PIDFILE"`
	log_end_msg $?
 
}
 
#--------------------------------------------------------------------------
 
d_status(){
	echo -n "STATUS: pms-linux-server is "
	if [ $pid -eq 0 ]; then
		echo "NOT running "
	else
		echo "running (PID -> $pid)"
		type_of_start
	fi
}
#--------------------------------------------------------------------------
 
case "$1" in 
 
	start|stop)
	d_${1}
	;;
 
	restart|reload|force-reload)
	d_stop
	sleep 5
	d_start
	;;
 
	status)
	d_status
	;;
 
	*)
	echo "Usage: /etc/init.d/$NAME-server {start|stop|restart|reload|force-reload|status}"
	exit 1
esac
 
exit 0
Alors, dans la fonction d_stop(), si je choisi la méthode kill -9 ... on peut dire que le script marche, mais c'est radical comme méthode
alors que si je choisis la méthode
Code :
	start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --user $USERID --exec $DAEMON
ça échoue .... il n'arrete rien du tout
Voici les sorties
Code :
1
2
3
4
5
6
7
8
paissad@paissad-server:/etc/init.d$ sudo ./pms-linux-server status
STATUS: pms-linux-server is running (PID -> 7488)
paissad@paissad-server:/etc/init.d$ sudo ./pms-linux-server start
pms-linux-server is already running !
paissad@paissad-server:/etc/init.d$ sudo ./pms-linux-server stop
Stopping Playstation 3 Media Server : pms-linux:
 failed!
paissad@paissad-server:/etc/init.d$
__________________
Nous n'héritons pas de la terre de nos parents, nous l'empruntons à nos enfants.
Slackware for the Subgenius !
http://blog.paissad.net
paissad est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2009, 17h42   #5
Membre éprouvé
 
Avatar de paissad
 
Homme
Étudiant
Inscription : avril 2006
Messages : 316
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2006
Messages : 316
Points : 444
Points : 444
Envoyer un message via Skype™ à paissad
Bon finalement, j'ai capitulé, y'a tout qui marche, sauf que j'utilise malheureusement la commande kill -9 pour stopper le programme
si vous testez le programme ou que vous avez des suggestions, je suis à l'écoute
voici le script sur pastebin http://pastebin.com/f1527f3b4
et ici
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /bin/sh
#
# init script for the ps3 media server for linux : pms-server
 
# Author: paissad
 
### BEGIN INIT INFO
# Provides:          pms-linux
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Media server for the playstation 3 
### END INIT INFO
 
# Author: Torsten Landschoff <torsten@debian.org>
 
NAME="pms-linux"
version="1.10.5"  # Version du logiciel 
DAEMON="/usr/bin/java"
OPTIONS="-jar /opt/$NAME/$NAME-$version/pms.jar"
DESC="Playstation 3 Media Server"
CONFIG_FILE="/etc/PMS.conf" # fichier de conf par défaut
CONFIG_DIR="`dirname "$CONFIG_FILE"`"
USERID=paissad
PIDFILE="/var/run/$NAME.pid"
 
. /lib/lsb/init-functions
 
# On vérifie que le fichier de conf PMS.conf est bien dans le repertoire /etc
if [ ! -e "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration /etc/PMS.conf est inexistant !" 
	exit 1
fi
 
if [ ! -r "$CONFIG_FILE" ]; then
	echo "Le fichier de configuration PMS.conf n\"est pas disponible en lecture !"
	exit 1
fi
 
#--------------------------------------------------------------------------
 
is_running(){
	pid=`pgrep -f '^[^ ]*java .*-jar.*pms.jar'`
	if [ -n "$pid" ]; then
		return 1 # pms.jar tourne
	else
		pid="0" # pms.jar qui est le serveur n est pas lancé, ni manuellment ni par le init.d
		return 0
	fi
}
is_running
 
#--------------------------------------------------------------------------
 
# Cette fonction permet de vérifier si le programme a été lancé via init.d ou manuellement
# S'il existe un fichier .pid dans /var/run alors c'est init.d, sinon .... manuellement.
type_of_start(){
	if [ ! -e $PIDFILE ]; then
		manual="yes"
		echo "WARNING: the server has been started manually"
	fi
}
 
#--------------------------------------------------------------------------
 
d_start(){
	if [ ! $pid -eq 0 ]; then
		echo "pms-linux-server is already running !"
		type_of_start
		exit 0
	fi
	log_daemon_msg "Starting $DESC : $NAME"
	echo
	start-stop-daemon --start --quiet --background --user $USERID --chdir "$CONFIG_DIR" \
	--pidfile "$PIDFILE" --make-pidfile --exec $DAEMON -- $OPTIONS 
	log_end_msg $?
 
}
 
#--------------------------------------------------------------------------
 
d_stop(){
	if [ $pid -eq 0 ]; then
		echo "pms-linux-server is NOT running !"
		exit 0
	fi
	type_of_start
	log_daemon_msg "Stopping $DESC : $NAME"
	echo
	#start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --user $USERID --exec $DAEMON 
	kill -9 $pid 
	`rm -f "$PIDFILE"`
	pid=0
	#log_end_msg $?
 
}
 
#--------------------------------------------------------------------------
 
d_status(){
	echo -n "STATUS: pms-linux-server is "
	if [ $pid -eq 0 ]; then
		echo "NOT running "
	else
		echo "running (PID -> $pid)"
		type_of_start
	fi
}
#--------------------------------------------------------------------------
 
case "$1" in 
 
	start|stop)
	d_${1}
	;;
 
	restart|reload|force-reload)
	d_stop
	sleep 3 
	d_start
	;;
 
	status)
	d_status
	;;
 
	*)
	echo "Usage: /etc/init.d/$NAME-server {start|stop|restart|reload|force-reload|status}"
	exit 1
esac
 
exit 0
__________________
Nous n'héritons pas de la terre de nos parents, nous l'empruntons à nos enfants.
Slackware for the Subgenius !
http://blog.paissad.net
paissad est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2009, 18h02   #6
Expert Confirmé
 
Avatar de N_BaH
 
Inscription : février 2008
Messages : 1 896
Détails du profil
Informations forums :
Inscription : février 2008
Messages : 1 896
Points : 3 676
Points : 3 676
Dans un init/script que j'utilise, j'ai ça :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
do_start()
{
        start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- \
                || return 2
}
 
do_stop()
{
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        rm -f $PIDFILE
        return "$RETVAL"
}
Je n'ai pas touché à la fonction do_stop, qui vient de /etc/init.d/skeleton, et à peine modifié do_start.
Je n'avais pas fait le lien entre KILL et sigterm 9 (dsl), mais de toute évidence, il est effectivement utilisé, en avant-dernier ressort.
N_BaH est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +1. Il est actuellement 21h11.


 
 
 
 
Partenaires

Hébergement Web