1 |
On Sat, Sep 30, 2017 at 12:20 AM, Walter Dnes <waltdnes@××××××××.org> wrote: |
2 |
> On Thu, Sep 28, 2017 at 04:27:31PM -0500, Austin English wrote |
3 |
|
4 |
|
5 |
>> While having the pleasure of working with some proprietary software |
6 |
>> recently, I was asked to run `service foo restart`, and was surprised to |
7 |
>> see: |
8 |
>> foobar ~ # service foo restart |
9 |
>> * service: service `foo' does not exist |
10 |
> |
11 |
> Ridiculous! We need to develop one universal standard that covers |
12 |
> everyone's use cases. https://xkcd.com/927/ |
13 |
> |
14 |
> But if you insist, why not just set up a short bash script called |
15 |
> "service" rather than monkeying with every init system's internals? |
16 |
> |
17 |
> #!/bin/bash |
18 |
> if [[ <condition_running_systemd> ]] ; then |
19 |
> systemctl ${2} ${1} |
20 |
> elif [[ <condition_running_initrc> ]] ; then |
21 |
> /etc/init.d/${1} ${2} |
22 |
> elif [[ <condition_running_some_other_init> ]] ; then |
23 |
> <do whatever that init system requires> |
24 |
> else |
25 |
> echo "ERROR: Unsupported init system; 'service' call failed" |
26 |
> fi |
27 |
|
28 |
With a "[ $# -eq 2 ]" test and with "env -i set_some_envvars |
29 |
/etc/init.d/${1} ${2}" (and use "rc-service ${1} ${2}" instead of |
30 |
"/etc/init.d/${1} ${2}") |
31 |
|
32 |
|
33 |
> This can handle a large number of different inits, with as many "elif" |
34 |
> lines as you care to add. But, how do we reliably detect the currently |
35 |
> running init system? Are there running processes, or entries in /sys/ |
36 |
> or /proc/ or /dev that are unique to to each init system? |
37 |
|
38 |
It's not init that you want to check, it's rc. |
39 |
|
40 |
For openrc, "[ -d /run/openrc ]" should do the trick. |
41 |
|
42 |
For systemd, the canonical way is "[ -d /run/systemd/system ]". |