[prev in list] [next in list] [prev in thread] [next in thread]
List: gentoo-dev
Subject: Re: [gentoo-dev] Providing a `service` scripts that speaks OpenRC and systemd
From: Tom H <tomh0665 () gmail ! com>
Date: 2017-09-30 22:55:59
Message-ID: CAOdo=SyatPx7m3egU_z1wXXyXs9HQFULJuh3usS3Ex=dxYLMdQ () mail ! gmail ! com
[Download RAW message or body]
On Sat, Sep 30, 2017 at 12:20 AM, Walter Dnes <waltdnes@waltdnes.org> wrote:
> On Thu, Sep 28, 2017 at 04:27:31PM -0500, Austin English wrote
>> While having the pleasure of working with some proprietary software
>> recently, I was asked to run `service foo restart`, and was surprised to
>> see:
>> foobar ~ # service foo restart
>> * service: service `foo' does not exist
>
> Ridiculous! We need to develop one universal standard that covers
> everyone's use cases. https://xkcd.com/927/
>
> But if you insist, why not just set up a short bash script called
> "service" rather than monkeying with every init system's internals?
>
> #!/bin/bash
> if [[ <condition_running_systemd> ]] ; then
> systemctl ${2} ${1}
> elif [[ <condition_running_initrc> ]] ; then
> /etc/init.d/${1} ${2}
> elif [[ <condition_running_some_other_init> ]] ; then
> <do whatever that init system requires>
> else
> echo "ERROR: Unsupported init system; 'service' call failed"
> fi
With a "[ $# -eq 2 ]" test and with "env -i set_some_envvars
/etc/init.d/${1} ${2}" (and use "rc-service ${1} ${2}" instead of
"/etc/init.d/${1} ${2}")
> This can handle a large number of different inits, with as many "elif"
> lines as you care to add. But, how do we reliably detect the currently
> running init system? Are there running processes, or entries in /sys/
> or /proc/ or /dev that are unique to to each init system?
It's not init that you want to check, it's rc.
For openrc, "[ -d /run/openrc ]" should do the trick.
For systemd, the canonical way is "[ -d /run/systemd/system ]".
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic