Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] startup script und pid file
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
Obelix
Tux's lil' helper
Tux's lil' helper


Joined: 22 Aug 2011
Posts: 100

PostPosted: Thu Jun 21, 2012 3:57 pm    Post subject: [Solved] startup script und pid file Reply with quote

Hallo,

ich bräuchte bitte mal Unterstützung bei einem startup script.

Ich habe synergy laufen und möchte das gerne beim Systemstart mitstarten.
Dazu habe ich mir die Anleitung durchgelesen und das startup script erst mal so übernommen. Nach einer kleinen Änderung (wegen deprecated -c) schien erst mal alles zu laufen.

Allerdings kann ich per "/etc/init.d/synergy stop" das ganze nicht mehr anhalten, weil das pid file einen anderen Wert aufweist, als der Prozess eigentlich hat.

Jetzt habe ich schon verschiedenes getestet:
--make-pidfile mitgeben oder auch nicht mitgeben
--background mitgeben oder auch nicht
verschiedene Optionen aus dem Standard-Aufruf weglassen

hat alles nix gebracht. Entweder bekomme ich gar kein pid file mehr, oder der Inhalt ist eine andere ID als die des Prozesses.

Wie bekomme ich denn nun den richtigen Wert in das pid file, dass auch ein "stop" alles wieder korrekt aufräumt und status nicht sofort sagt "crashed"?



hier noch das Script als Ganzes:

Code:
#!/sbin/runscript
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {
    use xdm net
}

start() {
    ebegin "Starting synergys"
    # the following line might be necessary to allow the connection to the x-server
    export XAUTHORITY=/home/${SYNERGY_USER}/.Xauthority
    start-stop-daemon --start -b -v -p /var/run/synergys.pid -m -x ${SYNERGY_EXEC} -- ${SYNERGY_OPTS}
    #start-stop-daemon --start --make-pidfile --pidfile /var/run/synergys.pid --exec ${SYNERGY_EXEC} -- ${SYNERGY_OPTS}
    eend $? "Failed to start synergys"
}

stop() {
    ebegin "Stopping synergys"
    start-stop-daemon --stop -x ${SYNERGY_EXEC} --pidfile /var/run/synergys.pid -q
    eend $? "Failed to stop synergys"
}

_________________
read my lips: NO MORE BUGS!!


Last edited by Obelix on Mon Jul 02, 2012 3:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
Obelix
Tux's lil' helper
Tux's lil' helper


Joined: 22 Aug 2011
Posts: 100

PostPosted: Tue Jun 26, 2012 10:45 am    Post subject: Reply with quote

...ich weiß inzwischen ein wenig mehr:

synergys scheint nach dem Start einen fork() zu machen, was dazu führt, dass der Prozess, dessen ID der start-stop-daemon in das PID file einträgt, später nicht mehr da ist. Nur noch die ID eines child-Prozesses, der nach dem fork() noch läuft.

Was ich versucht habe, ist im Script nach dem start-stop-daemon noch einen Befehl abzusetzen, der dann mittels "pgrep synergys" die echte pid ausliest und in das pidfile schreibt. Allerdings kommt der Befehl zu schnell, also läuft noch der ursprüngliche Prozess (ich erwische ihn also noch vor dem fork()).
Außerdem führt der Befehl dazu, dass das Script mit einem Fehler abbricht.

Weiß wirklich niemand Rat?
_________________
read my lips: NO MORE BUGS!!
Back to top
View user's profile Send private message
tomhog
n00b
n00b


Joined: 12 Mar 2004
Posts: 51
Location: FReiburg/South Germany

PostPosted: Tue Jun 26, 2012 8:43 pm    Post subject: Reply with quote

schreib doch den stop-Teil so um, daß du die pgrep-PID nimmst und nicht die dort gespeicherte.
Back to top
View user's profile Send private message
Obelix
Tux's lil' helper
Tux's lil' helper


Joined: 22 Aug 2011
Posts: 100

PostPosted: Wed Jun 27, 2012 6:54 pm    Post subject: Reply with quote

:) sehr pragmatisch, aber effektiv.
Das stop() klappt schon mal ganz gut, leider sagt status() noch *crashed*

gelegentlich versuche ich mal den status()-Teil aus dem init script zu basteln und werde dann das Ergebnis hier posten
_________________
read my lips: NO MORE BUGS!!
Back to top
View user's profile Send private message
Obelix
Tux's lil' helper
Tux's lil' helper


Joined: 22 Aug 2011
Posts: 100

PostPosted: Wed Jun 27, 2012 10:17 pm    Post subject: Reply with quote

So. Fertig.

Hier also das komplette Script für den synergy Server. Leider sieht die status() Meldung etwas anders aus, als bei den anderen Scripten, weil bei den anderen Scripten die status() section nicht gefüllt ist. Aber der Zweck ist erfüllt.

Für Verbesserungsvorschläge bin ich immer offen ;)


Code:
#!/sbin/runscript
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {
    use xdm net
}

start() {
    ebegin "Starting synergys"
    # the following line might be necessary to allow the connection to the x-server
    export XAUTHORITY=/home/${SYNERGY_USER}/.Xauthority
    start-stop-daemon --start --make-pidfile --pidfile /var/run/synergys.pid --exec ${SYNERGY_EXEC} -- ${SYNERGY_OPTS}
    eend $? "Failed to start synergys"
}

status() {
    ebegin "Synergy Server Status"
    pgrep synergys > /var/run/synergys.pid
    read -r PID < "/var/run/synergys.pid"
    eend $? "not running"
}

stop() {
    ebegin "Stopping synergys"
    pgrep synergys > /var/run/synergys.pid
    start-stop-daemon --stop -x ${SYNERGY_EXEC} --pidfile /var/run/synergys.pid -q
    eend $? "Failed to stop synergys"
}

_________________
read my lips: NO MORE BUGS!!
Back to top
View user's profile Send private message
RAPHEAD
Tux's lil' helper
Tux's lil' helper


Joined: 20 Jun 2003
Posts: 134
Location: Germany

PostPosted: Sat Mar 16, 2013 11:12 am    Post subject: Reply with quote

Hatte ein ähnliches problem und mir hat dein Post geholfen.
Danke
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum