Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] rc-update
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
leonixyz
Tux's lil' helper
Tux's lil' helper


Joined: 18 Sep 2012
Posts: 76
Location: Italy

PostPosted: Fri Oct 05, 2012 4:10 pm    Post subject: [SOLVED] rc-update Reply with quote

Hello,
I wrote the two following scripts in /etc/init.d/, made them executable (chmod +x filename), and added to rc-update as default services (rc-update add scriptname default).
When I start the system they doesn't start, but if i call manually "/etc/inid.d/scriptname start", the programs ar launched correctly.
I want to start them as default, where am i wrong?

Another question: when i start those services (manually like is described above), and want to stop one of them (/etc/init.d/scriptname stop), all two were killed because they have the same name in "ps". Is it possible to append a string to the process name? otherwise how can i stop only one of them?
Thanks

Code:
#!/bin/sh

case "$1" in

    start)
        python3 /sbin/xyzserver.py &
        echo "The xyzbrowser server has been started."
        ;;

    stop)
        killall python3
        echo "The xyzbrowser process has been killed."
        ;;

    restart)
        killall python3
        echo "The xyzbrowser process has been killed."
        python3 /sbin/xyzserver.py &
        echo "The xyzbrowser server has been started."
        ;;

    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac



Code:
#!/bin/sh

case "$1" in

    start)
        python3 /sbin/xyzpinger.py &
        echo "The xyzpinger has been started."
        ;;

    stop)
        killall python3
        echo "The xyzpinger process has been killed."
        ;;

    restart)
        killall python3
        echo "The xyzpinger process has been killed."
        python3 /sbin/xyzserver.py &
        echo "The xyzpinger has been started."
        ;;

    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac


Last edited by leonixyz on Sat Oct 06, 2012 2:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2441
Location: Silver City, NM

PostPosted: Fri Oct 05, 2012 5:26 pm    Post subject: Reply with quote

Take a look at the fine documentation on how to write init scripts for Gentoo. They need to start with:
Code:
#!/sbin/runscript
Back to top
View user's profile Send private message
leonixyz
Tux's lil' helper
Tux's lil' helper


Joined: 18 Sep 2012
Posts: 76
Location: Italy

PostPosted: Sat Oct 06, 2012 8:29 am    Post subject: Reply with quote

thank you very much, now the scripts are executed at startup...
here is the code of one of them:
Code:
#!/sbin/runscript

start(){
        python3 /sbin/xyzserver.py &
        echo "The xyzbrowser server has been started."
}

stop(){
        killall python3
        echo "The xyzbrowser process has been killed."
}

restart(){
        killall python3
        echo "The xyzbrowser process has been killed."
        python3 /sbin/xyzserver.py &
        echo "The xyzbrowser server has been started."
}


how could i kill only one of them two, if the processes names are equal? ("python3")

It's not possible to append a string to the process name? (like "python3/scriptname")

should i note somehow the process id and kill them by id? how could i do that?

thanks
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2441
Location: Silver City, NM

PostPosted: Sat Oct 06, 2012 8:51 am    Post subject: Reply with quote

Take another look at the fine documentation. The start-stop-daemon function is designed to handle this problem. It puts the process id of the started process in the pidfile on startup and then kills that process on shutdown.

You really either need to read the documentation or at the very least try to mimic the scripts that are already in /etc/init.d.
Back to top
View user's profile Send private message
leonixyz
Tux's lil' helper
Tux's lil' helper


Joined: 18 Sep 2012
Posts: 76
Location: Italy

PostPosted: Sat Oct 06, 2012 3:37 pm    Post subject: Reply with quote

thank you another time..
follows one of the working scripts

i got some problems, solved
1) by adding #!/usr/bin/python3.2 in the first line of those .py scripts
2) by converting one of them with dos2unix because i got this error
/usr/bin/python3.2^M: bad interpreter: No such file or directory


Code:

#!/sbin/runscript

start(){
    ebegin "Starting xyzbrowser server"
    start-stop-daemon --start --pidfile /var/run/xyzserver.pid --background --make-pidfile --exec /sbin/xyzserver.py
    eend $?
}

stop(){
    ebegin "Stopping xyzbrowser server"
    start-stop-daemon --stop --pidfile /var/run/xyzbrowser.pid --exec /sbin/xyzserver.py
    eend $?
}

restart(){
    stop
    start
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo 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