Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
convert systemd service to openrc init.
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
hedmo
Veteran
Veteran


Joined: 29 Aug 2009
Posts: 1305
Location: sweden

PostPosted: Wed Aug 04, 2021 5:35 pm    Post subject: convert systemd service to openrc init. Reply with quote

hi all

i need help with converting this service :

Code:

[Unit]
Description=Broadcomm Bluetooth daemon
After=syslog.target

[Service]
Type=simple
ExecStartPre=/bin/bash -c 'grep -qm 1 brcmfmac /proc/modules'
ExecStart=/usr/bin/btattach --bredr /dev/ttyS1 -P bcm
ExecStop=/usr/bin/killall btattach

[Install]
WantedBy=multi-user.target


to openrc init script.

regards
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Wed Aug 04, 2021 6:10 pm    Post subject: Reply with quote

Something like
Code:
#!/sbin/openrc-run
# Copyright 1999-2021 Gentoo Foundation

depend() {
   after logger
}

start_pre() {
   grep -qm 1 brcmfmac /proc/modules
   return $?
}

start() {
   ebegin "Start Broadcomm Bluetooth daemon"
   /usr/bin/btattach --bredr /dev/ttyS1 -P bcm
   eend $?
}

stop() {
   ebegin "Stop Broadcomm Bluetooth daemon"
   /usr/bin/killall btattach
   eend $?
}

_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
hedmo
Veteran
Veteran


Joined: 29 Aug 2009
Posts: 1305
Location: sweden

PostPosted: Wed Aug 04, 2021 6:12 pm    Post subject: Reply with quote

fedeliallalinea wrote:
Something like
Code:
#!/sbin/openrc-run
# Copyright 1999-2021 Gentoo Foundation

depend() {
   after logger
}

start_pre() {
   grep -qm 1 brcmfmac /proc/modules
   return $?
}

start() {
   ebegin "Start Broadcomm Bluetooth daemon"
   /usr/bin/btattach --bredr /dev/ttyS1 -P bcm
   eend $?
}

stop() {
   ebegin "Stop Broadcomm Bluetooth daemon"
   /usr/bin/killall btattach
   eend $?
}


as always :) . thank you fedeliallalinea . will check it right away :wink:
Back to top
View user's profile Send private message
hedmo
Veteran
Veteran


Joined: 29 Aug 2009
Posts: 1305
Location: sweden

PostPosted: Wed Aug 04, 2021 6:55 pm    Post subject: Reply with quote

the init scrip worked but it only stays there and openrc wont move forward.....
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Wed Aug 04, 2021 7:18 pm    Post subject: Reply with quote

I don't know how btattach works, maybe you should add & to end of command for run it in background
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
hedmo
Veteran
Veteran


Joined: 29 Aug 2009
Posts: 1305
Location: sweden

PostPosted: Wed Aug 04, 2021 7:27 pm    Post subject: Reply with quote

fedeliallalinea wrote:
I don't know how btattach works, maybe you should add & to end of command for run it in background


Yes i did that and openrc continued . Will check a bit more about it.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3309
Location: Rasi, Finland

PostPosted: Wed Aug 04, 2021 8:39 pm    Post subject: Reply with quote

Wouldn't start-stop-daemon fit better here, rather than killing every process with such name?
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
hedmo
Veteran
Veteran


Joined: 29 Aug 2009
Posts: 1305
Location: sweden

PostPosted: Wed Aug 04, 2021 8:49 pm    Post subject: Reply with quote

Zucca wrote:
Wouldn't start-stop-daemon fit better here, rather than killing every process with such name?


I am just happy to get it to work but if you can help me with it i Will be glad
To test it out . Scripts and stuff like that is something i never got in to.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1490
Location: South America

PostPosted: Wed Aug 04, 2021 11:18 pm    Post subject: Reply with quote

Using killall is likely wrong, even in the unit file: the service unit is defined as type simple, so it means that program btattach is providing the service itself and would keep running until asked to stop (tipically by sending the SIGTERM signal), instead of spawning a child process to provide the actual service and exiting ("backgrounding"). Which is likely the reason why OpenRC does not move forward.

And also means that btattach would be running as a child process of systemd, so systemd would know its process ID and can kill it itself when the unit is stopped, so killall seems completely useless here.

Current OpenRC's equivalent (sort of) for handling such a service is supervise-daemon, so I'd try this service script:

/etc/init.d/btattach
Code:
#!/sbin/openrc-run
description="Broadcomm Bluetooth daemon"
supervisor=supervise-daemon
command=/usr/bin/btattach
command_args="--bredr /dev/ttyS1 -P bcm"

depend() {
   after logger
}

start_pre() {
   grep -qm 1 brcmfmac /proc/modules && return 0
   eend 1 "Kernel module brcmfmac not loaded"
}
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30822
Location: here

PostPosted: Thu Aug 05, 2021 4:38 am    Post subject: Reply with quote

Sorry hedmo, I didn't think about btattach was a program that listens and therefore could be started with start-stop-daemon (the kill command should have made me understand), so the GDH-gentoo solution is the only correct one.
_________________
Questions are guaranteed in life; Answers aren't.
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