View previous topic :: View next topic |
Author |
Message |
hedmo Veteran
Joined: 29 Aug 2009 Posts: 1305 Location: sweden
|
Posted: Wed Aug 04, 2021 5:35 pm Post subject: convert systemd service to openrc init. |
|
|
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 |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 30822 Location: here
|
Posted: Wed Aug 04, 2021 6:10 pm Post subject: |
|
|
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 |
|
|
hedmo Veteran
Joined: 29 Aug 2009 Posts: 1305 Location: sweden
|
Posted: Wed Aug 04, 2021 6:12 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
hedmo Veteran
Joined: 29 Aug 2009 Posts: 1305 Location: sweden
|
Posted: Wed Aug 04, 2021 6:55 pm Post subject: |
|
|
the init scrip worked but it only stays there and openrc wont move forward..... |
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 30822 Location: here
|
Posted: Wed Aug 04, 2021 7:18 pm Post subject: |
|
|
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 |
|
|
hedmo Veteran
Joined: 29 Aug 2009 Posts: 1305 Location: sweden
|
Posted: Wed Aug 04, 2021 7:27 pm Post subject: |
|
|
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 |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3309 Location: Rasi, Finland
|
Posted: Wed Aug 04, 2021 8:39 pm Post subject: |
|
|
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 |
|
|
hedmo Veteran
Joined: 29 Aug 2009 Posts: 1305 Location: sweden
|
Posted: Wed Aug 04, 2021 8:49 pm Post subject: |
|
|
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 |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1490 Location: South America
|
Posted: Wed Aug 04, 2021 11:18 pm Post subject: |
|
|
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 |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 30822 Location: here
|
Posted: Thu Aug 05, 2021 4:38 am Post subject: |
|
|
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 |
|
|
|