View previous topic :: View next topic |
Author |
Message |
rabcor Apprentice
Joined: 05 Apr 2012 Posts: 200
|
Posted: Sun Jun 01, 2014 11:33 am Post subject: [Solved] Help with making an init script! |
|
|
I need to make an init script for openrc that would look like this in systemd:
Code: | [Unit]
Description=Binds devices to vfio-pci
After=syslog.target
[Service]
EnvironmentFile=-/etc/vfio-pci.cfg
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/bin/vfio-bind $DEVICES
[Install]
WantedBy=multi-user.target |
I've got two files, vfio-bind which is being executed and /etc/vfio-pci.cfg which looks like this:
Code: | #cat /etc/vfio-pci.cfg
DEVICES="0000:02:00.0 0000:02:00.1" |
Alternatively, it would be sufficient if I can just write an initscript that executes this command (eliminating the need for vfio-pci.cfg, that part is not essential):
Code: | vfio-bind 0000:02:00.0 0000:02:00.1 |
I read this but it is insufficient information for me.
Would the below actually work?
Code: |
#!/sbin/runscript
start() { /bin/vfio-bind 0000:02:00.0 0000:02:00.1 }
|
Fixed a linking tag. -- desultory _________________ This picture was my biggest reason for ever trying Gentoo <3
Last edited by rabcor on Mon Jun 02, 2014 4:24 am; edited 1 time in total |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Sun Jun 01, 2014 2:04 pm Post subject: Re: Help with making an init script! |
|
|
rabcor ... dependent on when this needs to run it might be better to use /etc/local.d/ (and have 'local' in the default runlevel) eg:
/etc/local.d/vfio-bind.start
Code: | #!/bin/sh
. /etc/vfio-pci.cfg
/bin/vfio-bind $DEVICES |
It looks (from the above service file) there are no dependencies involved, so it should be fine to start in the default runlevel. If not, then the following is based on the above *.service ... not sure if you want a stop() as I'm not sure what vfio-bind does exactly.
Code: | #!/sbin/runscript
# you could use /etc/conf.d/vfio-bind ... which would then provide "$DEVICES".
DEVICES="0000:02:00.0 0000:02:00.1"
depend() {
after logger
}
start() {
ebegin "Starting vfio-bind"
/bin/vfio-bind "$DEVICES"
eend $?
} |
HTH & best ... khay |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Sun Jun 01, 2014 4:54 pm Post subject: |
|
|
In addition to khayyam's remarks:
I would not put DEVICE=... into /etc/init.d/vfio-bind itself but into /etc/conf.d/vfio-bind (as khayyam has already remarked).
Actually, you can make the latter a symlink to /etc/vfio-pci.cfg or let it contain the single line Code: | ! test -r /etc/vfio-pci.cfg || . /etc/vfio-pci.cfg | so that you can easily change configurations for systemd and openrc simultaneously by editing /etc/vfio-pci.cfg.
Yet another note: The "-" in the ExecStart means that the service should succeed even if the command fails. To "simulate" this in openrc you should add, for instance, at the end of the start() function. |
|
Back to top |
|
|
rabcor Apprentice
Joined: 05 Apr 2012 Posts: 200
|
Posted: Mon Jun 02, 2014 4:23 am Post subject: |
|
|
Thanks guys _________________ This picture was my biggest reason for ever trying Gentoo <3 |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Mon Jun 02, 2014 6:59 am Post subject: |
|
|
Yet another remark: If you follow the suggestion to put setting of DEVICES to another file, "$DEVICES" should better be ${DEVICES+"$DEVICES"} in kahyaam's code so that the parameter is only used if it was actually set in the /etc/conf.d/... file (I think that this is the analogue of what systemd does with $DEVICES, but I would have to read systemd documentation again to be sure). |
|
Back to top |
|
|
|