Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to stop one initscript when starting another?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
drt
n00b
n00b


Joined: 29 Apr 2017
Posts: 10

PostPosted: Sun Sep 16, 2018 7:07 am    Post subject: How to stop one initscript when starting another? Reply with quote

Hi folks,

hopefully this is the correct subforum, I didn't know where to place my question in first place.

I have a gentoo-Box which is controlled by infrared remote with 2 buttons,
and I want the 2 buttons to alternate two initscripts.

At press of button 1, initscript number 1 should be started and initscript 2 should be stopped.
At press of button 2, initscript number 2 should be started and initscript 1 should be started.

Both initscripts use X and so they conflict with each other.
so what I am searching for is some kind of NOT-dependency, like "not need app2" in the depend section or something, but unfortunately I do not find any - which makes me believe I am barking up the wrong tree.

What I did so far, is to place the stop-command from one initscript into the start-section of the other script.
This works, but the first script gets to status "crashed" when closed by the other script - so I think this is not the right way to do.

I attach you the examples of the two script, I hope you can help me out.

script 1
Code:
#!/sbin/openrc-run

depend()
{
        need net
}

start() {
  ebegin "Stopping app2"
        start-stop-daemon --stop /etc/init.d/app2\
        --pidfile /var/run/app2.pid
  eend $? "Failed to stop app2 (maybe not running?)"

  ebegin "Starting app1"
        start-stop-daemon --start -u ${APP1_USER} --background --pidfile /var/run/app1.pid --make-pidfile --exec /usr/bin/xinit -- /usr/bin/app1-standalone ${APP1_OPTS} -- :0
  eend $?
}

stop() {
  ebegin "Stopping app1"
        start-stop-daemon --stop --pidfile /var/run/app1.pid
  eend $?
}


script 2
Code:
#!/sbin/openrc-run

start() {
  ebegin "Starting app2"
        start-stop-daemon --start \
        --user app1_USER\
        --background \
        --pidfile /var/run/app2.pid \
        --make-pidfile \
        --exec /usr/bin/xinit -- /usr/bin/app2-- :0
  eend $? "Failed to start app2"
}

stop() {
  ebegin "Stopping app2"
        start-stop-daemon --stop \
        --pidfile /var/run/app2.pid
  eend $? "Failed to stop app2"
}


thanks a lot in advance!

best regards

drt
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6216
Location: Room 101

PostPosted: Sun Sep 16, 2018 8:44 am    Post subject: Reply with quote

drt ...

you should not be starting/stopping initscripts from within initscripts, instead you should be using openrc features (ie, runlevels) to switch between one set of services and another:

Code:
# install -d /etc/runlevels/infrastart
# rc-update -s add default infrastart
# install -d /etc/runlevels/infrastop
# rc-update -s add default infrastop

You then add the service you want started to 'infrastart', and omit it from 'infrastop'.

Code:
# rc-update add myservice infrastart

By calling 'rc infrastart' or 'rc infrastop' you will start/stop the service.

HTH & best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming 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