OpenRC/Prefix

From Gentoo Wiki
< OpenRC
Jump to: navigation, search

This work is a reponse to bug #196294.

The following guideline applies to a Gentoo Prefix on RHEL-5.6 amd64 and on Debian 6.0 amd64, for other setups it should be similar. Feel free to documents corner cases here.

Getting openrc on Prefix

root #emerge --ask sys-apps/openrc

Specify the system to be Prefix:

FILE EPREFIX/etc/rc.conf
rc_sys="prefix"

Tips

Start OpenRC Automatically

As a service manager, OpenRC is more useful to be started automatically.

/etc/rc.local

Many distributions provide /etc/rc.local as a site specific place start services.

If you have root access to the host, start OpenRC from /etc/rc.local:

FILE /etc/rc.local
EPREFIX/sbin/openrc # replace EPREFIX with yours

crontab

If your do not have root access to the host, but the host has cron, you can hook OpenRC into crontab on every reboot.

FILE crontab -e
@reboot EPREFIX/sbin/openrc # replace EPREFIX with yours

.profile

If the host does not even have cron, OpenRC can be started from login shell. Taking bash for example,

FILE ${HOME}/.profile
EPREFIX/sbin/openrc # replace EPREFIX with yours

OpenRC does nothing if a runlevel is entered again. Logging in (and entering default runlevel) many times does not have side-effects.

Trouble Shooting

XXX is already starting

user $rc-service ntpd start
 * WARNING: ntpd is already starting

OpenRC needs to enter some runlevel to initiate the runtime status directores in EPREFIX/var/run/openrc to really start anything.

user $openrc

Example: tinc

tinc is a decentralized VPN. A tinc started from Gentoo Prefix can serve as a relay node in the VPN, if tun/tap is not available for normal user.

emerge tinc, or re-emerge to get its {init,conf}.d files back with our new portage

root #emerge --ask tinc

prefixify init script

user $EPREFIX=$(portage envvar EPREFIX)
user $sed -i -r -e "s,(\W)/(etc|bin|sbin|usr|var),\1${EPREFIX}/\2,g" ${EPREFIX}/etc/init.d/tincd

fire up tincd from OpenRC

Make necessary changes in ${EPREFIX}/etc/conf.d/tinc.networks and ${EPREFIX}/etc/tinc according to your specific setup.

Add tincd into default runlevel

user $rc-update add tincd default

Finally we are done with

user $openrc
 * Starting tinc VPN networks ...
 * Starting tinc network manifold ... [ ok ]
 * Starting local                     [ ok ]

Example: nginx

nginx is a small, robust and high-performance web server.

Emerge nginx, or re-emerge to get its initd and confd files back with our new portage:

root #emerge --ask nginx

prefixify init script

user $EPREFIX=$(portageq envvar EPREFIX)
user $sed -i -r -e "s,(\W)/(etc|bin|sbin|usr|var),\1${EPREFIX}/\2,g" ${EPREFIX}/etc/init.d/nginx

prefixify nginx.conf

user $EPREFIX=$(portageq envvar EPREFIX)
user $sed -i -r -e "s,(\W)/(etc|bin|sbin|usr|var),\1${EPREFIX}/\2,g" ${EPREFIX}/etc/nginx/nginx.conf

normal privilege

  • remove "user nginx nginx;" from the first line of ${EPREFIX}/etc/nginx/nginx.conf
  • You cannot listen on port 80 without root privilege. Change it to 8008,
FILE ${EPREFIX}/etc/nginx/nginx.conflisten on 8008
...
http {
    ...
    server {
        ...
        listen [::]:8008;
        ...
    }
    ...
}

add nginx to default runlevel and fire up

user $rc-update add nginx default
user $openrc
 * Checking nginx' configuration ... [ ok ]
 * Starting nginx ...                [ ok ]
user $netstat -nlp | grep nginx
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::8008                 :::*                    LISTEN      570/nginx: master p

See also