Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Help with making an init script!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
rabcor
Apprentice
Apprentice


Joined: 05 Apr 2012
Posts: 200

PostPosted: Sun Jun 01, 2014 11:33 am    Post subject: [Solved] Help with making an init script! Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


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

PostPosted: Sun Jun 01, 2014 2:04 pm    Post subject: Re: Help with making an init script! Reply with quote

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
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6281

PostPosted: Sun Jun 01, 2014 4:54 pm    Post subject: Reply with quote

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,
Code:
:
at the end of the start() function.
Back to top
View user's profile Send private message
rabcor
Apprentice
Apprentice


Joined: 05 Apr 2012
Posts: 200

PostPosted: Mon Jun 02, 2014 4:23 am    Post subject: Reply with quote

Thanks guys :)
_________________
This picture was my biggest reason for ever trying Gentoo <3
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6281

PostPosted: Mon Jun 02, 2014 6:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing 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