Merge pull request #108 from ifupdown-ng/feature/openrc-init-script
openrc init script
This commit is contained in:
commit
d76c2df460
4 changed files with 99 additions and 5 deletions
|
@ -158,6 +158,8 @@ list_interfaces(struct lif_dict *collection, struct match_options *opts)
|
|||
printf("}\n");
|
||||
}
|
||||
|
||||
static bool listing = false, listing_stat = false, listing_running = false;
|
||||
|
||||
void
|
||||
list_state(struct lif_dict *state, struct match_options *opts)
|
||||
{
|
||||
|
@ -176,12 +178,14 @@ list_state(struct lif_dict *state, struct match_options *opts)
|
|||
continue;
|
||||
|
||||
struct lif_state_record *rec = entry->data;
|
||||
|
||||
if (listing_running)
|
||||
printf("%s\n", entry->key);
|
||||
else
|
||||
printf("%s=%s %zu\n", entry->key, rec->mapped_if, rec->refcount);
|
||||
}
|
||||
}
|
||||
|
||||
static bool listing = false, listing_stat = false;
|
||||
|
||||
static void
|
||||
set_listing(const char *opt_arg)
|
||||
{
|
||||
|
@ -196,6 +200,13 @@ set_show_state(const char *opt_arg)
|
|||
listing_stat = true;
|
||||
}
|
||||
|
||||
static void
|
||||
set_show_running(const char *opt_arg)
|
||||
{
|
||||
(void) opt_arg;
|
||||
listing_running = true;
|
||||
}
|
||||
|
||||
static void
|
||||
set_pretty_print(const char *opt_arg)
|
||||
{
|
||||
|
@ -217,6 +228,7 @@ set_property(const char *opt_arg)
|
|||
}
|
||||
|
||||
static struct if_option local_options[] = {
|
||||
{'r', "running", NULL, "show configured (running) interfaces", false, set_show_running},
|
||||
{'s', "state", NULL, "show configured state", false, set_show_state},
|
||||
{'p', "property", "property PROPERTY", "print values of properties matching PROPERTY", true, set_property},
|
||||
{'D', "dot", NULL, "generate a dependency graph", false, set_output_dot},
|
||||
|
@ -257,7 +269,7 @@ ifquery_main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* --list --state is not allowed */
|
||||
if (listing && listing_stat)
|
||||
if (listing && (listing_stat || listing_running))
|
||||
generic_usage(self_applet, EXIT_FAILURE);
|
||||
|
||||
if (listing)
|
||||
|
@ -265,7 +277,7 @@ ifquery_main(int argc, char *argv[])
|
|||
list_interfaces(&collection, &match_opts);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (listing_stat)
|
||||
else if (listing_stat || listing_running)
|
||||
{
|
||||
list_state(&state, &match_opts);
|
||||
return EXIT_SUCCESS;
|
||||
|
|
8
dist/openrc/networking.confd
vendored
Normal file
8
dist/openrc/networking.confd
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Sets the path used for the interface definitions.
|
||||
#cfgfile="/etc/network/interfaces"
|
||||
|
||||
# Sets the path used for the state database.
|
||||
#ifstate="/run/ifstate"
|
||||
|
||||
# Skip taking down networking while shutting down.
|
||||
#keep_network="YES"
|
70
dist/openrc/networking.initd
vendored
Normal file
70
dist/openrc/networking.initd
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
#!/sbin/openrc-run
|
||||
|
||||
: ${cfgfile:="/etc/network/interfaces"}
|
||||
ifstate=/run/ifstate
|
||||
|
||||
single_iface="${RC_SVCNAME#*.}"
|
||||
if [ "$single_iface" = "$RC_SVCNAME" ]; then
|
||||
single_iface=
|
||||
fi
|
||||
|
||||
depend() {
|
||||
need localmount
|
||||
want dev-settle
|
||||
after bootmisc hwdrivers modules
|
||||
provide net
|
||||
keyword -jail -prefix -vserver -docker
|
||||
}
|
||||
|
||||
# find interfaces we want to start
|
||||
find_ifaces() {
|
||||
if [ -n "$single_iface" ]; then
|
||||
echo $single_iface
|
||||
else
|
||||
ifquery -L -i "$cfgfile"
|
||||
fi
|
||||
}
|
||||
|
||||
# return the list of interfaces we should try stop
|
||||
find_running_ifaces() {
|
||||
if [ -n "$single_iface" ]; then
|
||||
echo $single_iface
|
||||
else
|
||||
ifquery -r -i "$cfgfile" -S "$ifstate"
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
local iface= ret=1
|
||||
ebegin "Starting networking"
|
||||
eindent
|
||||
for iface in $(find_ifaces); do
|
||||
local r=0
|
||||
ebegin "$iface"
|
||||
if ! ifup -i "$cfgfile" -S "$ifstate" $iface >/dev/null; then
|
||||
ifdown -f -i "$cfgfile" -S "$ifstate" $iface >/dev/null 2>&1
|
||||
r=1
|
||||
fi
|
||||
# atleast one interface needs to be started for action
|
||||
# to be success
|
||||
eend $r && ret=0
|
||||
done
|
||||
eoutdent
|
||||
return $ret
|
||||
}
|
||||
|
||||
stop() {
|
||||
local iface=
|
||||
# Don't stop the network at shutdown.
|
||||
yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0
|
||||
|
||||
ebegin "Stopping networking"
|
||||
eindent
|
||||
for iface in $(find_running_ifaces); do
|
||||
ebegin "$iface"
|
||||
ifdown -i "$cfgfile" -S "$ifstate" -f $iface >/dev/null
|
||||
eend $?
|
||||
done
|
||||
eoutdent
|
||||
return 0
|
||||
}
|
|
@ -32,6 +32,10 @@ configuration file to the current format.
|
|||
*-p, --property* _PROPERTY_
|
||||
Print the values of matching properties for an interface.
|
||||
|
||||
*-r, --running*
|
||||
Print the interface names that are marked as running in
|
||||
the state database.
|
||||
|
||||
*-s, --state*
|
||||
Query the state database instead of the config database.
|
||||
|
||||
|
|
Loading…
Reference in a new issue