├── .github ├── dco.yml ├── pull_request_template.md └── workflows │ └── shellcheck.yml ├── .gitignore ├── LICENSE ├── README.md ├── generate-all.sh ├── generate.sh ├── pkg ├── postinstall ├── postuninstall ├── postupgrade └── preuninstall ├── src ├── etc │ ├── NetworkManager │ │ ├── conf.d │ │ │ ├── 10-globally-managed-devices.conf##linux.one │ │ │ └── one-context.conf##linux.one │ │ └── dispatcher.d │ │ │ └── pre-up.d │ │ │ └── netplan-ipv6-privacy-off##deb │ ├── cron.d │ │ └── one-context-reconfigure##crond │ ├── devd │ │ └── one-context.conf##bsd │ ├── init.d │ │ ├── one-context##apk.one │ │ ├── one-context##deb.sysv.one │ │ ├── one-context##rpm.sysv.one │ │ ├── one-context-force##apk.one │ │ ├── one-context-force##deb.sysv.one │ │ ├── one-context-force##rpm.sysv.one │ │ ├── one-context-local##apk.one │ │ ├── one-context-local##deb.sysv.one │ │ ├── one-context-local##rpm.sysv.one │ │ ├── one-context-reconfigure##apk.one │ │ ├── one-context-reconfigure##deb.sysv.one │ │ ├── one-context-reconfigure##rpm.sysv.one │ │ ├── one-context-reconfigure-delayed##apk.one │ │ ├── one-context-reconfigure-delayed##deb.sysv.one │ │ └── one-context-reconfigure-delayed##rpm.sysv.one │ ├── init │ │ ├── one-context-force.conf##deb.upstart.one │ │ ├── one-context-local.conf##deb.upstart.one │ │ ├── one-context-reconfigure-delayed.conf##deb.upstart.one │ │ ├── one-context-reconfigure.conf##deb.upstart.one │ │ └── one-context.conf##deb.upstart.one │ ├── modules-load.d │ │ └── one-context.conf##apk │ ├── one-context.d │ │ ├── loc-04-run-dir │ │ ├── loc-05-grow-rootfs │ │ ├── loc-09-timezone │ │ ├── loc-10-network │ │ ├── loc-10-network-pci##one │ │ ├── loc-10-network.d │ │ │ ├── functions │ │ │ ├── netcfg-bsd │ │ │ ├── netcfg-interfaces │ │ │ ├── netcfg-netplan │ │ │ ├── netcfg-networkd │ │ │ ├── netcfg-nm │ │ │ └── netcfg-scripts │ │ ├── loc-12-firewall##vr │ │ ├── loc-14-mount-swap##one │ │ ├── loc-15-ip_forward##vr │ │ ├── loc-15-keepalived##vr │ │ ├── loc-16-gen-env │ │ ├── loc-20-set-username-password │ │ ├── loc-22-ssh_public_key │ │ ├── loc-24-ssh_host_key##deb │ │ ├── loc-30-console##one │ │ ├── loc-35-securetty │ │ ├── net-11-fix-loopback##deb.one │ │ ├── net-15-hostname │ │ ├── net-97-start-script │ │ ├── net-98-execute-scripts │ │ └── net-99-report-ready │ ├── periodic │ │ └── 1min │ │ │ └── one-context-reconfigure##apk │ ├── rc.d │ │ ├── one-context##bsd_rc.one │ │ ├── one-context-force##bsd_rc.one │ │ ├── one-context-local##bsd_rc.one │ │ ├── one-context-reconfigure##bsd_rc.one │ │ └── one-context-reconfigure-delayed##bsd_rc.one │ ├── systemd │ │ └── system │ │ │ └── acpid.path.d │ │ │ └── one-context.conf##deb.systemd │ └── udev │ │ └── rules.d │ │ ├── 75-cd-aliases-generator.rules │ │ └── 75-persistent-net-generator.rules ├── lib │ └── udev │ │ └── rules.d │ │ ├── 65-context.rules##apk.one │ │ ├── 65-context.rules##deb.one │ │ ├── 65-context.rules##rpm.systemd.one │ │ └── 65-context.rules##rpm.sysv.one └── usr │ ├── bin │ ├── onegate │ └── onegate.rb │ ├── lib │ └── systemd │ │ └── system │ │ ├── one-context-force.service##systemd.one │ │ ├── one-context-local.service##deb.systemd.one │ │ ├── one-context-local.service##rpm.systemd.one │ │ ├── one-context-online.service##systemd.one │ │ ├── one-context-reconfigure-delayed.service##systemd.one │ │ ├── one-context-reconfigure.service##systemd.one │ │ ├── one-context-reconfigure.timer##systemd.one │ │ ├── one-context.service##arch.one │ │ ├── one-context.service##systemd.ec2 │ │ └── one-context.service##systemd.one │ ├── local │ └── etc │ │ └── rc.d │ │ ├── one-context-force.sh##pfsense_rc.one │ │ ├── one-context-local.sh##pfsense_rc.one │ │ ├── one-context-reconfigure-delayed.sh##pfsense_rc.one │ │ ├── one-context.sh##pfsense_rc.one │ │ └── one-contextre-configure.sh##pfsense_rc.one │ └── sbin │ ├── growpart##apk │ ├── one-context-run##one │ ├── one-contextd │ ├── one-dual-dhclient##bsd │ └── onesysprep └── targets.sh /.github/dco.yml: -------------------------------------------------------------------------------- 1 | require: 2 | members: false 3 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Changes proposed in this pull request: 8 | - briefly describe change here, 9 | - briefly describe change here, 10 | - briefly describe change here. 11 | -------------------------------------------------------------------------------- /.github/workflows/shellcheck.yml: -------------------------------------------------------------------------------- 1 | name: 'ShellCheck' 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | shellcheck: 7 | name: Shellcheck 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Run ShellCheck 12 | uses: ludeeus/action-shellcheck@master 13 | with: 14 | scandir: './src' 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | *.rpm 3 | *.deb 4 | .vagrant*/ 5 | *~bak 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | ⚠️⚠️⚠️⚠️⚠️⚠️⚠️ 3 | 4 | >[!IMPORTANT] 5 | >This repository is being moved to a new location https://github.com/OpenNebula/one-apps 6 | >During the transition the repository is in read-only mode 7 | 8 | ---- 9 | 10 | # OpenNebula Linux VM Contextualization 11 | 12 | ## Description 13 | 14 | This addon provides contextualization packages for the Linux (and, other 15 | Unix-like) guest virtual machines running in the OpenNebula cloud. Based 16 | on the provided contextualization parameters, the packages prepare the 17 | networking in the running guest virt. machine, configure SSH keys, set 18 | passwords, run custom start scripts, and many others. 19 | 20 | ## Download 21 | 22 | Latest versions can be downloaded from the 23 | [release page](https://github.com/OpenNebula/addon-context-linux/releases). 24 | Check the supported OpenNebula versions for each release. 25 | 26 | ## Install 27 | 28 | Documentation on packages installation and guest contextualization can 29 | be found in the latest stable 30 | [OpenNebula Operation Guide](http://docs.opennebula.org/stable/operation/vm_setup/context_overview.html). 31 | For beta releases, refer to the latest 32 | [development documentation](http://docs.opennebula.org/devel/operation/vm_setup/context_overview.html). 33 | 34 | ## Tested platforms 35 | 36 | List of tested platforms only: 37 | 38 | | Platform | Versions | 39 | |---------------------------------|------------------------------------------| 40 | | AlmaLinux | 8, 9 | 41 | | Alpine Linux | 3.15, 3.16, 3.17 | 42 | | ALT Linux | 9, 10 | 43 | | Amazon Linux | 2 | 44 | | CentOS | 7, 8 Stream | 45 | | Debian | 10, 11 | 46 | | Devuan | 3, 4 | 47 | | Fedora | 37 | 48 | | FreeBSD | 12, 13 | 49 | | openSUSE | 15 | 50 | | Oracle Linux | 7, 8, 9 | 51 | | Red Hat Enterprise Linux | 7, 8, 9 | 52 | | Rocky Linux | 8, 9 | 53 | | Ubuntu | 20.04, 22.04 | 54 | | Ubuntu Minimal | 20.04, 22.04 | 55 | 56 | (the packages might work on other versions or flavours, but those aren't tested) 57 | 58 | ### Guest Network Configuration 59 | 60 | > **NOTE: Available since context packages version 6.2.0.** 61 | 62 | The context scripts support selectable guest network management service (a component in guest OS responsible for assigning IP addresses, routes, and bringing interfaces up). Following network configuration types can be selected by setting the context variable `NETCFG_TYPE` (empty default fallbacks to autodetection of the most suitable one for a particular platform): 63 | 64 | - `bsd` for FreeBSD network configuration, 65 | - `interfaces` for Debian-style configuration in `/etc/network/interfaces`, 66 | - `netplan` for Netplan with following renders set in context variable `NETCFG_NETPLAN_RENDERER`: 67 | - empty or `networkd` for systemd-network (default), 68 | - `NetworkManager` for NetworkManager 69 | - `networkd` for systemd-networkd, 70 | - `nm` for NetworkManager, 71 | - `scripts` for legacy Red Hat-style configuration via `/etc/sysconfig/network-scripts/ifcfg-ethX` files. 72 | 73 | Interface IP address configuration method can be customized as well. Following IPv4 configuration methods are supported via NIC attribute `METHOD`: 74 | 75 | - empty or `static` for static address assignment based on context variables, 76 | - `dhcp` for DHCPv4, 77 | - `skip` to skip IPv4 configuration. 78 | 79 | Following IPv6 configuration methods are supported via NIC attribute `IP6_METHOD`: 80 | 81 | - empty or `static` for static address assignment based on context variables, 82 | - `auto` for SLAAC, 83 | - `dhcp` for SLAAC and DHCPv6, 84 | - `disable` to disable IPv6 in guest, 85 | - `skip` to skip IPv6 configuration. 86 | 87 | Selectable configuration types and IP configuration methods are **supported only on the following platforms**: 88 | 89 | | Platform | Network Type (`NETCFG_TYPE`) | 90 | |---------------------------------------------------------------|-------------------------------------------| 91 | | Alpine Linux 3.15+ | `interfaces` | 92 | | ALT Linux p10, Sisyphus | `networkd`, `nm` | 93 | | Amazon Linux 2 | `scripts` | 94 | | Debian 10+ | `interfaces`, `netplan`, `nm`, `networkd` | 95 | | Devuan 3 | `interfaces` | 96 | | Fedora 36+ | `scripts`, `nm`, `networkd` | 97 | | FreeBSD 12+ | `bsd` | 98 | | openSUSE 15 | `scripts` | 99 | | RHEL-like 7 (CentOS, Oracle Linux) | `scripts` | 100 | | RHEL-like 8 (CentOS, Oracle/Rocky/AlmaLinux) | `scripts`, `nm`, `networkd` | 101 | | RHEL-like 9 (CentOS Stream 9, Oracle/Rocky/AlmaLinux) | `nm`, `networkd` | 102 | | Ubuntu 18.04, 20.04, 22.04 | `interfaces`, `netplan`, `nm`, `networkd` | 103 | 104 | (other than listed platforms are not supported for using `NETCFG_TYPE` nor `METHOD`/`IP6_METHOD`!): 105 | 106 | Known Issues: 107 | 108 | - Alpine Linux: `IP6_METHOD=dhcp` runs DHCPv4 client instead of DHCPv6, 109 | - Debian 10: `NETCFG_TYPE=netplan` with **networkd** doesn't configure IPv6 (only) SLAAC (`IP6_METHOD=auto`) when no IPv4 is configured, 110 | - Debian/Ubuntu: `NETCFG_TYPE=netplan` with **NetworkManager** might not configure IPv6 SLAAC (`IP6_METHOD=auto`) for hot-plugged interfaces, 111 | - Debian 10 and Ubuntu 18.04, 20.04: might trigger DHCPv6 with `IP6_METHOD=auto` 112 | - on `NETCFG_TYPE=netplan` with **networkd**, 113 | - on `NETCFG_TYPE=networkd`. 114 | 115 | ## Build own package 116 | 117 | Packages for each release for supported guests are available in the 118 | [release page](https://github.com/OpenNebula/addon-context-linux/releases). 119 | Also, any version can be built by the scripts provided in this repository. 120 | 121 | ### Requirements 122 | 123 | * **Linux host** 124 | * **Ruby** >= 1.9 125 | * gem **fpm** >= 1.10.0 126 | * **dpkg utils** for deb package creation 127 | * **rpm utils** for rpm package creation 128 | 129 | ### Steps 130 | 131 | The script `generate.sh` is able to create all package types and can be 132 | configured to include more files in the package or change some of 133 | its parameters. Package type and content are configured by the env. variable 134 | `TARGET`, the corresponding target must be defined in `target.sh`. Target 135 | describes the package format, name, dependencies, and files. Files are 136 | selected by the tags. Set of required tags is defined for the target 137 | (in `targets.sh`), each file has a list of corresponding tags right in its 138 | filename (divided by the regular name by 2 hashes `##`, dot-separated). 139 | 140 | Package name or version can be overridden by env. variables `NAME` and `VERSION`. 141 | 142 | Examples: 143 | 144 | ``` 145 | $ TARGET=deb ./generate.sh 146 | $ TARGET=el7 NAME=my-one-context ./generate.sh 147 | $ TARGET=alpine ./generate.sh 148 | $ TARGET=freebsd VERSION=5.7.85 ./generate.sh 149 | ``` 150 | 151 | NOTE: The generator must be executed from the same directory it resides. 152 | 153 | Check `generate.sh` for general package metadata and `targets.sh` for the list 154 | of targets and their metadata. Most of the parameters can be overriden by 155 | the appropriate environment variable. 156 | 157 | ## Development 158 | 159 | To contribute bug patches or new features, you can use the github Pull Request 160 | model. It is assumed that code and documentation are contributed under 161 | the Apache License 2.0. 162 | 163 | More info: 164 | * [How to Contribute](http://opennebula.org/addons/contribute/) 165 | * Support: [OpenNebula user forum](https://forum.opennebula.org/c/support) 166 | * Development: [OpenNebula developers forum](https://forum.opennebula.org/c/development) 167 | * Issues Tracking: Github issues (https://github.com/OpenNebula/addon-context-linux/issues) 168 | 169 | ### Repository structure 170 | 171 | All code is located under `src/` and structure follows the installation 172 | directory structure. Files for different environments/targets are picked 173 | by the tag, tags are part of the filename separated from the installation 174 | name by 2 hashes (`##`). Tags are dot-separated. 175 | 176 | Examples: 177 | 178 | * `script` - non-tagged file for all targets 179 | * `script##systemd` - file tagged with **systemd** 180 | * `script##systemd.rpm` - file tagged with **systemd** and **rpm** 181 | 182 | ### Contextualization scripts 183 | 184 | Contextualization scripts, which are executed on every boot and during 185 | the reconfiguration, are located in `src/etc/one-context.d/`. Scripts are 186 | divided into following 2 parts: 187 | 188 | * local - pre-networking, prefixed with `loc-` 189 | * post-networking, prefixed with `net-` 190 | 191 | All other scripts, which are not prefixed with `loc-` or `net-`, are 192 | executed as a first during the post-networking contextualization stage. 193 | 194 | ## License 195 | 196 | Copyright 2002-2022, OpenNebula Project, OpenNebula Systems (formerly C12G Labs) 197 | 198 | Licensed under the Apache License, Version 2.0 (the "License"); you may 199 | not use this file except in compliance with the License. You may obtain 200 | a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 201 | 202 | Unless required by applicable law or agreed to in writing, software 203 | distributed under the License is distributed on an "AS IS" BASIS, 204 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 205 | See the License for the specific language governing permissions and 206 | limitations under the License. 207 | -------------------------------------------------------------------------------- /generate-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | export DATE=$(date +%Y%m%d) 6 | TARGETS='el6 el7 el8 el9 alt suse deb alpine freebsd iso' 7 | 8 | for TARGET in $TARGETS; do 9 | TARGET="${TARGET}" ./generate.sh 10 | done 11 | 12 | echo 13 | echo "The packages are here:" 14 | echo "--------------------------------------------------------------------------------" 15 | find out -type f 16 | -------------------------------------------------------------------------------- /generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2022, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # shellcheck disable=SC1091 20 | 21 | if [ -z "${TARGET}" ]; then 22 | echo 'Error: env. variable TARGET not set' >&2 23 | exit 1 24 | fi 25 | 26 | set -e 27 | source targets.sh 28 | set +e 29 | 30 | ### 31 | 32 | if [ -z "${RELEASE}" ]; then 33 | if git describe --contains "$(git rev-parse HEAD)" &>/dev/null; then 34 | RELEASE=1 35 | else 36 | DATE=${DATE:-$(date +%Y%m%d)} 37 | GIT=$(git rev-parse --short HEAD) 38 | RELEASE="0.${DATE}git${GIT}" 39 | fi 40 | fi 41 | 42 | ### 43 | 44 | VERSION=${VERSION:-6.6.1} 45 | RELEASE=${RELEASE:-1} 46 | MAINTAINER=${MAINTAINER:-OpenNebula Systems } 47 | LICENSE=${LICENSE:-Apache 2.0} 48 | VENDOR=${VENDOR:-OpenNebula Systems} 49 | SUMMARY="OpenNebula Contextualization Package" 50 | DESC=" 51 | Contextualization tools for the virtual machine running in the OpenNebula 52 | cloud. Based on parameters provided by the cloud controller configures the 53 | networking, initial user password, SSH keys, runs custom start scripts, 54 | resizes the root filesystem, and provides tools to communicate with 55 | OneGate service. 56 | 57 | Check the OpenNebula web page (http://opennebula.org) to get the support. 58 | " 59 | DESCRIPTION=${DESCRIPTION:-$DESC} 60 | URL=${URL:-http://opennebula.org} 61 | RELEASE_FULL="${RELEASE}${RELSUFFIX}" 62 | EXT="${EXT:-${TYPE}}" 63 | 64 | if [ "${TYPE}" = 'deb' ]; then 65 | FILENAME="${NAME}_${VERSION}-${RELEASE_FULL}.${EXT}" 66 | elif [ "${TYPE}" = 'apk' ]; then 67 | RELEASE_FULL="r${RELEASE_FULL}" 68 | FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${EXT}" 69 | elif [ "${TARGET}" = 'arch' ]; then 70 | FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}-any.${EXT}" 71 | elif [ "${TARGET}" = 'freebsd' ]; then 72 | FILENAME="${NAME}-${VERSION}_${RELEASE_FULL}.${EXT}" 73 | elif [ "${TARGET}" = 'alt' ]; then 74 | RELEASE_FULL="${RELSUFFIX}${RELEASE}" 75 | FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.noarch.${EXT}" 76 | elif [ "${TYPE}" = 'iso' ]; then 77 | LABEL="${NAME}-${VERSION}" 78 | FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.${EXT}" 79 | else 80 | FILENAME="${NAME}-${VERSION}-${RELEASE_FULL}.noarch.${EXT}" 81 | fi 82 | 83 | ### 84 | 85 | set -e 86 | 87 | UNAME_PATH=$(mktemp -d) 88 | BUILD_DIR=$(mktemp -d) 89 | 90 | _POSTIN=$(mktemp) 91 | _PREUN=$(mktemp) 92 | _POSTUN=$(mktemp) 93 | _POSTUP=$(mktemp) 94 | 95 | # shellcheck disable=SC2064 96 | trap "rm -rf ${UNAME_PATH} ${BUILD_DIR} ${_POSTIN} ${_PREUN} ${_POSTUN} ${_POSTUP}" EXIT 97 | 98 | while IFS= read -r -d $'\0' SRC; do 99 | F_TAGS=${SRC##*##} 100 | if [ "x${SRC}" != "x${F_TAGS}" ]; then 101 | # shellcheck disable=SC2001 102 | for F_TAG in $(echo "${F_TAGS}" | sed -e 's/\./ /g'); do 103 | for TAG in ${TAGS}; do 104 | if [ "${F_TAG}" = "${TAG}" ]; then 105 | continue 2 # tag matches, continue with next tag 106 | fi 107 | done 108 | continue 2 # tags not maching, skip this file 109 | done 110 | fi 111 | 112 | # file matches 113 | DST=${SRC%##*} #strip tags 114 | mkdir -p "${BUILD_DIR}/$(dirname "${DST}")" 115 | cp "src/${SRC}" "${BUILD_DIR}/${DST}" 116 | done < <(cd src/ && find . -type f -print0) 117 | 118 | for F in "$@"; do 119 | cp -r "$F" "${BUILD_DIR}/" 120 | done 121 | 122 | # fix permissions and set umask for fpm 123 | find "${BUILD_DIR}/" -perm -u+r -exec chmod go+r {} \; 124 | find "${BUILD_DIR}/" -perm -u+x -exec chmod go+x {} \; 125 | umask 0022 126 | 127 | # cleanup 128 | if [ -z "${OUT}" ]; then 129 | OUT="out/${FILENAME}" 130 | _out_dir=$(dirname "${OUT}") 131 | mkdir -p "${_out_dir}" 132 | rm -rf "${OUT}" 133 | fi 134 | 135 | # Mocked 'uname' to fake FreeBSD on Linux build systems. 136 | # Otherwise FPM places Linux identification into TXZ packages. 137 | if [ "${TYPE}" = 'freebsd' ] && [ ! -x /bin/freebsd-version ]; then 138 | cat - <"${UNAME_PATH}/uname" 139 | #!/bin/sh 140 | [ "\$1" = '-s' ] && echo 'FreeBSD' 141 | [ "\$1" = '-r' ] && echo '12.0-RELEASE' 142 | EOF 143 | 144 | chmod +x "${UNAME_PATH}/uname" 145 | export PATH="${UNAME_PATH}:${PATH}" 146 | fi 147 | 148 | if [ "${TYPE}" = 'dir' ]; then 149 | cp -rT "${BUILD_DIR}" "${OUT}" 150 | 151 | elif [ "${TYPE}" = 'iso' ]; then 152 | _out_dir=$(dirname "${OUT}") 153 | mkisofs -J -R -input-charset utf8 \ 154 | -m '*.iso' \ 155 | -V "${LABEL}" \ 156 | -o "${OUT}" \ 157 | "${_out_dir}" 158 | 159 | else 160 | CONFIG_FILES=$(cd "${BUILD_DIR}" && \ 161 | find etc/ \ 162 | ! -path 'etc/one-context.d/*' \ 163 | ! -path 'etc/init*' \ 164 | -type f -printf '--config-files %p ') 165 | 166 | # concatenate pre/postinstall scripts 167 | if [ -n "${POSTIN}" ]; then 168 | cat "${POSTIN}" >"${_POSTIN}" 169 | fi 170 | 171 | if [ -n "${PREUN}" ]; then 172 | cat "${PREUN}" >"${_PREUN}" 173 | fi 174 | 175 | if [ -n "${POSTUN}" ]; then 176 | cat "${POSTUN}" >"${_POSTUN}" 177 | fi 178 | 179 | if [ -n "${POSTUP}" ]; then 180 | cat "${POSTUP}" >"${_POSTUP}" 181 | fi 182 | 183 | # set the package version of onesysprep 184 | sed -i "s/\<_PACKAGE_VERSION_\>/${VERSION}/" \ 185 | "${BUILD_DIR}/usr/sbin/onesysprep" 186 | 187 | # shellcheck disable=SC2086 188 | fpm --name "${NAME}" --version "${VERSION}" --iteration "${RELEASE_FULL}" \ 189 | --architecture all --license "${LICENSE}" \ 190 | --vendor "${VENDOR}" --maintainer "${MAINTAINER}" \ 191 | --description "${DESCRIPTION}" --url "${URL}" \ 192 | --output-type "${TYPE}" --input-type dir --chdir "${BUILD_DIR}" \ 193 | --directories /etc/one-context.d \ 194 | ${POSTIN:+ --after-install ${_POSTIN}} \ 195 | ${POSTUP:+ --after-upgrade ${_POSTUP}} \ 196 | ${PREUN:+ --before-remove ${_PREUN}} \ 197 | ${POSTUN:+ --after-remove ${_POSTUN}} \ 198 | --rpm-os linux \ 199 | --rpm-summary "${SUMMARY}" \ 200 | ${DEPENDS:+ --depends ${DEPENDS// / --depends }} \ 201 | ${RECOMMENDS:+ --rpm-tag Recommends:${RECOMMENDS// / --rpm-tag Recommends:}} \ 202 | ${RECOMMENDS:+ --deb-recommends ${RECOMMENDS// / --deb-recommends }} \ 203 | ${REPLACES:+ --replaces ${REPLACES// / --replaces }} \ 204 | ${CONFLICTS:+ --conflicts ${CONFLICTS// / --conflicts }} \ 205 | ${PROVIDES:+ --provides ${PROVIDES// / --provides }} \ 206 | --deb-no-default-config-files \ 207 | --pacman-user 0 \ 208 | --pacman-group 0 \ 209 | ${CONFIG_FILES} \ 210 | --package "${OUT}" 211 | fi 212 | 213 | basename "${OUT}" 214 | -------------------------------------------------------------------------------- /pkg/postinstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SERVICES=${SERVICES:-one-context-local one-context-online one-context} 4 | TIMERS=${TIMERS:-one-context-reconfigure.timer} 5 | 6 | rm -f /etc/udev/rules.d/70-persistent-cd.rules 7 | rm -f /etc/udev/rules.d/70-persistent-net.rules 8 | 9 | # Reload udev rules 10 | udevadm control --reload >/dev/null 2>&1 || : 11 | 12 | 13 | ### Enable services ######################################## 14 | 15 | if which systemctl >/dev/null 2>&1 && \ 16 | [ -d /etc/systemd ] && \ 17 | [ -f /usr/lib/systemd/system/one-context.service ]; 18 | then 19 | systemctl daemon-reload >/dev/null 2>&1 || : 20 | 21 | for S in ${SERVICES} ${TIMERS}; do 22 | systemctl enable "${S}" >/dev/null 2>&1 23 | done 24 | fi 25 | 26 | if which chkconfig >/dev/null 2>&1; then 27 | for S in ${SERVICES}; do 28 | chkconfig --add "${S}" >/dev/null 2>&1 29 | done 30 | 31 | # EL6: refresh initramfs via dracut for growroot module 32 | if [ -f /usr/share/dracut/modules.d/50growroot/install ]; then 33 | for I in $(find /boot -name 'initramfs-*.img'); do 34 | KERNEL_VERS=$(echo "${I}" | sed -e 's/.*initramfs-\(.*\)\.img/\1/') 35 | dracut -f "${I}" "${KERNEL_VERS}" || : 36 | done 37 | fi 38 | 39 | elif which update-rc.d >/dev/null 2>&1; then 40 | for S in ${SERVICES}; do 41 | update-rc.d "${S}" enable >/dev/null 2>&1 42 | update-rc.d "${S}" defaults >/dev/null 2>&1 43 | done 44 | 45 | elif which rc-update >/dev/null 2>&1; then 46 | for S in ${SERVICES}; do 47 | rc-update add "${S}" boot >/dev/null 2>&1 48 | done 49 | 50 | # Add crontab action for 1min schedules 51 | if ! crontab -l -u root | grep -qF '/etc/periodic/1min'; then 52 | ( 53 | crontab -l -u root 54 | echo -e '\n# Added by one-context' 55 | echo -e '* * * * * run-parts /etc/periodic/1min' 56 | ) | crontab -u root - 57 | fi 58 | 59 | # When existing file is changed, the new one might be created with 60 | # .apk-new suffix. Such files need to be processed by update-conf. 61 | if update-conf -al 2>/dev/null | grep -q context; then 62 | echo 'WARNING: Run update-conf to process any updated one-context files in /etc!' >&2 63 | fi 64 | 65 | elif [ -x /bin/freebsd-version ]; then 66 | : 67 | 68 | else 69 | echo 'WARNING: Contextualization service not enabled automatically' >&2 70 | fi 71 | 72 | 73 | ### Cleanup network configuration ########################## 74 | 75 | if [ -f /etc/sysctl.d/50-one-context.conf ]; then 76 | rm -f /etc/sysctl.d/50-one-context.conf 77 | fi 78 | 79 | # Debian based distros 80 | if [ -d /etc/network ]; then 81 | # Prepare network files 82 | cp /etc/network/interfaces "/etc/network/interfaces.$(date '+%s')" 83 | rm -rf /etc/network/interfaces.d 84 | 85 | cat > /etc/network/interfaces <> /etc/default/networking 95 | # fi 96 | # fi 97 | fi 98 | 99 | # Red Hat based distros 100 | if [ -d /etc/sysconfig/network-scripts/ ]; then 101 | # Prepare network files 102 | find /etc/sysconfig/network-scripts -type f \ 103 | \( -name 'ifcfg-*' -o -name 'route-*' -o -name 'route6-*' \) \ 104 | ! -name 'ifcfg-lo' ! -name 'route-lo' ! -name 'route6-lo' \ 105 | -exec rm -f {} \; 106 | fi 107 | 108 | # openSUSE based distros 109 | if [ -d /etc/sysconfig/network/ ]; then 110 | # Prepare network files 111 | find /etc/sysconfig/network -type f \ 112 | \( -name 'ifcfg-*' -o -name 'ifroute-*' -o -name 'ifsysctl-*' \) \ 113 | ! -name 'ifcfg-lo' ! -name 'ifroute-lo' ! -name 'ifsysctl-lo' \ 114 | -exec rm -f {} \; 115 | 116 | rm -f /etc/sysconfig/network/routes /etc/sysconfig/network/ifsysctl 117 | 118 | sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=""/' /etc/sysconfig/network/config 119 | sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config 120 | fi 121 | 122 | # Netplan 123 | if [ -d /etc/netplan/ ]; then 124 | rm -f /etc/netplan/* 125 | fi 126 | 127 | # NetworkManager 128 | if [ -d /etc/NetworkManager/system-connections/ ]; then 129 | rm -f /etc/NetworkManager/system-connections/* 130 | fi 131 | 132 | # systemd-networkd 133 | if [ -d /etc/systemd/network/ ]; then 134 | rm -f \ 135 | /etc/systemd/networkd/*.network \ 136 | /etc/systemd/networkd/*.link 137 | fi 138 | 139 | # FreeBSD based distros 140 | #TODO: pfsense paths? 141 | if [ -x /bin/freebsd-version ]; then 142 | rm -f /etc/rc.conf.d/network /etc/rc.conf.d/routing 143 | 144 | if [ -f /etc/rc.conf ]; then 145 | sed -i '' \ 146 | -e '/^ifconfig_/d' \ 147 | -e '/^route_/d' \ 148 | -e '/^static_routes/d' \ 149 | -e '/^defaultrouter/d' \ 150 | /etc/rc.conf 151 | fi 152 | fi 153 | -------------------------------------------------------------------------------- /pkg/postuninstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | udevadm control --reload >/dev/null 2>&1 || : 4 | 5 | if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then 6 | systemctl daemon-reload >/dev/null 2>&1 || : 7 | fi 8 | -------------------------------------------------------------------------------- /pkg/postupgrade: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Reload udev rules 4 | udevadm control --reload >/dev/null 2>&1 || : 5 | 6 | ### Enable services ######################################## 7 | 8 | SERVICES=${SERVICES:-one-context-local one-context-online one-context} 9 | TIMERS=${TIMERS:-one-context-reconfigure.timer} 10 | 11 | if which systemctl >/dev/null 2>&1 && \ 12 | [ -d /etc/systemd ] && \ 13 | [ -f /usr/lib/systemd/system/one-context.service ]; 14 | then 15 | systemctl daemon-reload >/dev/null 2>&1 || : 16 | 17 | for S in ${SERVICES} ${TIMERS}; do 18 | systemctl enable "${S}" >/dev/null 2>&1 19 | done 20 | fi 21 | 22 | if which chkconfig >/dev/null 2>&1; then 23 | for S in ${SERVICES}; do 24 | chkconfig --add "${S}" >/dev/null 2>&1 25 | done 26 | 27 | # EL6: refresh initramfs via dracut for growroot module 28 | if [ -f /usr/share/dracut/modules.d/50growroot/install ]; then 29 | for I in $(find /boot -name 'initramfs-*.img'); do 30 | KERNEL_VERS=$(echo "${I}" | sed -e 's/.*initramfs-\(.*\)\.img/\1/') 31 | dracut -f "${I}" "${KERNEL_VERS}" || : 32 | done 33 | fi 34 | 35 | elif which update-rc.d >/dev/null 2>&1; then 36 | for S in ${SERVICES}; do 37 | update-rc.d "${S}" enable >/dev/null 2>&1 38 | update-rc.d "${S}" defaults >/dev/null 2>&1 39 | done 40 | 41 | elif which rc-update >/dev/null 2>&1; then 42 | for S in ${SERVICES}; do 43 | rc-update add "${S}" boot >/dev/null 2>&1 44 | done 45 | 46 | # Add crontab action for 1min schedules 47 | if ! crontab -l -u root | grep -qF '/etc/periodic/1min'; then 48 | ( 49 | crontab -l -u root 50 | echo -e '\n# Added by one-context' 51 | echo -e '* * * * * run-parts /etc/periodic/1min' 52 | ) | crontab -u root - 53 | fi 54 | 55 | # When existing file is changed, the new one might be created with 56 | # .apk-new suffix. Such files need to be processed by update-conf. 57 | if update-conf -al 2>/dev/null | grep -q context; then 58 | echo 'WARNING: Run update-conf to process any updated one-context files in /etc!' >&2 59 | fi 60 | 61 | elif [ -x /bin/freebsd-version ]; then 62 | : 63 | 64 | else 65 | echo 'WARNING: Contextualization service not enabled automatically' >&2 66 | fi 67 | -------------------------------------------------------------------------------- /pkg/preuninstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SERVICES=${SERVICES:-one-context one-context-online one-context-local one-context-reconfigure one-context-reconfigure-delayed} 4 | TIMERS=${TIMERS:-one-context-reconfigure.timer} 5 | 6 | # Disable services 7 | if which systemctl >/dev/null 2>&1 && [ -d /etc/systemd ]; then 8 | for S in ${TIMERS} ${SERVICES}; do 9 | systemctl --no-reload disable "${S}" >/dev/null 2>&1 || : 10 | systemctl stop "${S}" >/dev/null 2>&1 || : 11 | done 12 | fi 13 | 14 | if which chkconfig >/dev/null 2>&1; then 15 | for S in ${SERVICES}; do 16 | chkconfig --del "${S}" >/dev/null 2>&1 || : 17 | done 18 | 19 | elif which update-rc.d >/dev/null 2>&1; then 20 | for S in ${SERVICES}; do 21 | update-rc.d -f "${S}" remove >/dev/null 2>&1 || : 22 | done 23 | 24 | elif which rc-update >/dev/null 2>&1; then 25 | for S in ${SERVICES}; do 26 | rc-update del "${S}" boot >/dev/null 2>&1 || : 27 | done 28 | fi 29 | -------------------------------------------------------------------------------- /src/etc/NetworkManager/conf.d/10-globally-managed-devices.conf##linux.one: -------------------------------------------------------------------------------- 1 | # This enables sensible default for 'unmanaged-devices' on ubuntu: 2 | # https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842 3 | # https://askubuntu.com/questions/882806/ethernet-device-not-managed 4 | # 5 | # This file must exist prior start of NetworkManager to take an effect - 6 | # a simple reloading of the already running daemon will not work. 7 | 8 | -------------------------------------------------------------------------------- /src/etc/NetworkManager/conf.d/one-context.conf##linux.one: -------------------------------------------------------------------------------- 1 | [main] 2 | no-auto-default=* 3 | dns=none 4 | -------------------------------------------------------------------------------- /src/etc/NetworkManager/dispatcher.d/pre-up.d/netplan-ipv6-privacy-off##deb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # -------------------------------------------------------------------------- # 18 | 19 | # As of Netplan 0.102, the NetworkManager renderer can only enable 20 | # IPv6 privacy if ipv6-privacy == true, but doesn't disable it if false. 21 | # Instead of enforcing any global defaults, we set IPv6 privacy via sysctl 22 | # on Netplan described interfaces in case the current settings is -1 (unknown), 23 | # i.e. not explicitly configured. This is a forward compatible workaround, once 24 | # Netplan properly sets NM ipv6.ip6-privacy=0, this code won't be effective. 25 | 26 | case "${CONNECTION_ID}" in 27 | netplan-*) 28 | IP6_PRIVACY=$(nmcli -g ipv6.ip6-privacy con show "${CONNECTION_UUID}") 29 | 30 | # overwrite only unknown state 31 | if [ "${IP6_PRIVACY}" = '-1' ]; then 32 | sysctl -q -w "net.ipv6.conf.${DEVICE_IFACE}.use_tempaddr=0" 33 | 34 | # delete any existing temporary IPv6 addresses 35 | ip -6 address show dev "${DEVICE_IFACE}" | \ 36 | grep 'inet6.*temporary' | \ 37 | tr -s ' ' | \ 38 | cut -d' ' -f 3 | \ 39 | xargs -r -n1 ip -6 address del dev "${DEVICE_IFACE}" 40 | fi 41 | ;; 42 | esac 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /src/etc/cron.d/one-context-reconfigure##crond: -------------------------------------------------------------------------------- 1 | # Periodically run one-context-reconfigure on VMware 2 | SHELL=/bin/sh 3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin 4 | MAILTO='' 5 | 6 | * * * * * root if [ "$(virt-what 2>/dev/null)" = 'vmware' ]; then service one-context-reconfigure start >/dev/null 2>&1 || service one-context-reconfigure onestart >/dev/null 2>&1; fi 7 | -------------------------------------------------------------------------------- /src/etc/devd/one-context.conf##bsd: -------------------------------------------------------------------------------- 1 | # On NIC hotplug the delayed reconfiguration is triggered. 2 | 3 | # NOTE: With hot-attached emulated NICs (e1000, ...) the interface 4 | # and kernel event may appear later, even after CD-ROM is refreshed. 5 | # Such interface doesn't configure, since new change in context 6 | # script is not detected anymore. We hack the state files so that the 7 | # recontextualization is forced to run. 8 | notify 21 { 9 | match "system" "ETHERNET"; 10 | match "type" "IFATTACH"; 11 | match "subsystem" "!vtnet[0-9]+"; 12 | action "/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network; service one-context-reconfigure-delayed onestart'"; 13 | }; 14 | 15 | notify 20 { 16 | match "system" "ETHERNET"; 17 | match "type" "IFATTACH"; 18 | action "service one-context-reconfigure-delayed onestart"; 19 | }; 20 | 21 | notify 20 { 22 | match "system" "IFNET"; 23 | match "type" "DETACH"; 24 | action "service one-context-reconfigure-delayed onestart"; 25 | }; 26 | 27 | # On CONTEXT CD-ROM change the immediate reconfiguration is triggered. 28 | notify 20 { 29 | match "system" "DEVFS"; 30 | match "subsystem" "CDEV"; 31 | match "type" "CREATE"; 32 | match "cdev" "iso9660/CONTEXT"; 33 | action "service one-context-reconfigure onestart"; 34 | }; 35 | 36 | # Handle disk resize 37 | # NOTE: Event not generated on FreeBSD 12 and older 38 | notify 20 { 39 | match "system" "GEOM"; 40 | match "subsystem" "DEV"; 41 | match "type" "SIZECHANGE"; 42 | match "cdev" "!(cd[0-9]+|.*/.*|.*p[0-9]+)"; # skip CD-ROM/context, filesystems and partitions 43 | action "service one-context-force onestart"; 44 | }; 45 | 46 | # Handle swap hot-attach 47 | # NOTE: swap activation not supported on FreeBSD now 48 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context##apk.one: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | name="OpenNebula contextualization" 20 | 21 | depend() { 22 | use one-context-local net 23 | before sshd 24 | after logger 25 | keyword -stop -shutdown 26 | } 27 | 28 | start() { 29 | ebegin "Starting one-context" 30 | /usr/sbin/one-contextd network 31 | eend $? 32 | } 33 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context##deb.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # Provides: one-context 21 | # Required-Start: $local_fs $network $syslog one-context-local 22 | # Required-Stop: 23 | # Should-Start: $time 24 | # Should-Stop: 25 | # X-Start-Before: sshd 26 | # X-Stop-After: 27 | # Default-Start: 2 3 4 5 28 | # Default-Stop: 0 1 6 29 | # Short-Description: OpenNebula contextualization 30 | ### END INIT INFO 31 | 32 | . /lib/lsb/init-functions 33 | 34 | case "$1" in 35 | start) 36 | log_daemon_msg $"Starting OpenNebula contextualization" 37 | /usr/sbin/one-contextd network 38 | log_end_msg $? 39 | ;; 40 | *) 41 | log_action_msg $"Usage: $0 {start}" 42 | exit 2 43 | esac 44 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # chkconfig: 2345 11 99 20 | # description: OpenNebula contextualization 21 | 22 | ### BEGIN INIT INFO 23 | # Provides: one-context 24 | # Required-Start: $local_fs $network $syslog one-context-local 25 | # Required-Stop: 26 | # Should-Start: $time 27 | # Should-Stop: 28 | # X-Start-Before: sshd 29 | # X-Stop-After: 30 | # Default-Start: 2 3 4 5 31 | # Default-Stop: 0 1 6 32 | # Short-Description: OpenNebula contextualization 33 | ### END INIT INFO 34 | 35 | # Source function library. 36 | . /etc/rc.d/init.d/functions 37 | 38 | case "$1" in 39 | start) 40 | action $"Starting OpenNebula contextualization: " \ 41 | /usr/sbin/one-contextd network 42 | ;; 43 | *) 44 | echo $"Usage: $0 {start}" 45 | exit 2 46 | esac 47 | 48 | exit $? 49 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-force##apk.one: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | name="OpenNebula forced run" 20 | 21 | depend() { 22 | use one-context one-context-local 23 | keyword -stop -shutdown 24 | } 25 | 26 | start() { 27 | ebegin "Starting one-context-force" 28 | export TIMEOUT=0 29 | /usr/sbin/one-context-run force 30 | eend $? 31 | } 32 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-force##deb.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # Provides: one-context-force 21 | # Required-Start: one-context-local one-context 22 | # Required-Stop: 23 | # Should-Start: $time 24 | # Should-Stop: 25 | # Default-Start: 26 | # Default-Stop: 0 1 2 3 4 5 6 27 | # Short-Description: OpenNebula forced run 28 | ### END INIT INFO 29 | 30 | . /lib/lsb/init-functions 31 | 32 | case "$1" in 33 | start|restart) 34 | export TIMEOUT=0 35 | log_daemon_msg $"Starting OpenNebula forced reconfiguration" 36 | /usr/sbin/one-context-run force 37 | log_end_msg $? 38 | ;; 39 | *) 40 | log_action_msg $"Usage: $0 {start|restart}" 41 | exit 2 42 | esac 43 | 44 | exit $? 45 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-force##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # chkconfig: - 99 1 20 | # description: OpenNebula forced run 21 | 22 | ### BEGIN INIT INFO 23 | # Provides: one-context-force 24 | # Required-Start: one-context-local one-context 25 | # Required-Stop: 26 | # Should-Start: $time 27 | # Should-Stop: 28 | # Default-Start: 29 | # Default-Stop: 0 1 2 3 4 5 6 30 | # Short-Description: OpenNebula forced run 31 | ### END INIT INFO 32 | 33 | # Source function library. 34 | . /etc/rc.d/init.d/functions 35 | 36 | case "$1" in 37 | start|restart) 38 | export TIMEOUT=0 39 | action $"Starting OpenNebula forced reconfiguration: " \ 40 | /usr/sbin/one-context-run force 41 | ;; 42 | *) 43 | echo $"Usage: $0 {start|restart}" 44 | exit 2 45 | esac 46 | 47 | exit $? 48 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-local##apk.one: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | name="OpenNebula pre-networking contextualization" 20 | 21 | depend() { 22 | need localmount udev udev-trigger udev-settle 23 | before net 24 | after logger 25 | keyword -stop -shutdown 26 | } 27 | 28 | start() { 29 | ebegin "Starting one-context-local" 30 | /usr/sbin/one-contextd local 31 | eend $? 32 | } 33 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-local##deb.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # Provides: one-context-local 21 | # Required-Start: $local_fs 22 | # Required-Stop: 23 | # Should-Start: $time 24 | # Should-Stop: 25 | # X-Start-Before: $network 26 | # X-Stop-After: 27 | # Default-Start: S 28 | # Default-Stop: 0 1 6 29 | # Short-Description: OpenNebula pre-networking contextualization 30 | ### END INIT INFO 31 | 32 | . /lib/lsb/init-functions 33 | 34 | case "$1" in 35 | start) 36 | log_daemon_msg $"Starting OpenNebula pre-networking contextualization" 37 | /usr/sbin/one-contextd local 38 | log_end_msg $? 39 | ;; 40 | *) 41 | log_action_msg $"Usage: $0 {start}" 42 | exit 2 43 | esac 44 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-local##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # chkconfig: 2345 9 99 20 | # description: OpenNebula pre-networking contextualization 21 | 22 | ### BEGIN INIT INFO 23 | # Provides: one-context-local 24 | # Required-Start: $local_fs 25 | # Required-Stop: 26 | # Should-Start: $time 27 | # Should-Stop: 28 | # X-Start-Before: $network 29 | # X-Stop-After: 30 | # Default-Start: 2 3 4 5 31 | # Default-Stop: 0 1 6 32 | # Short-Description: OpenNebula pre-networking contextualization 33 | ### END INIT INFO 34 | 35 | # Source function library. 36 | . /etc/rc.d/init.d/functions 37 | 38 | case "$1" in 39 | start) 40 | action $"Starting OpenNebula pre-networking contextualization: " \ 41 | /usr/sbin/one-contextd local 42 | ;; 43 | *) 44 | echo $"Usage: $0 {start}" 45 | exit 2 46 | esac 47 | 48 | exit $? 49 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure##apk.one: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | name="OpenNebula reconfiguration" 20 | 21 | depend() { 22 | use one-context one-context-local 23 | keyword -stop -shutdown 24 | } 25 | 26 | start() { 27 | ebegin "Starting one-context-reconfigure" 28 | export TIMEOUT=0 29 | /usr/sbin/one-context-run 30 | eend $? 31 | } 32 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure##deb.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # Provides: one-context-reconfigure 21 | # Required-Start: one-context-local one-context 22 | # Required-Stop: 23 | # Should-Start: $time 24 | # Should-Stop: 25 | # Default-Start: 26 | # Default-Stop: 0 1 2 3 4 5 6 27 | # Short-Description: OpenNebula reconfiguration 28 | ### END INIT INFO 29 | 30 | . /lib/lsb/init-functions 31 | 32 | case "$1" in 33 | start|restart) 34 | export TIMEOUT=0 35 | log_daemon_msg $"Starting OpenNebula reconfiguration" 36 | /usr/sbin/one-context-run 37 | log_end_msg $? 38 | ;; 39 | *) 40 | log_action_msg $"Usage: $0 {start|restart}" 41 | exit 2 42 | esac 43 | 44 | exit $? 45 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # chkconfig: - 99 1 20 | # description: OpenNebula reconfiguration 21 | 22 | ### BEGIN INIT INFO 23 | # Provides: one-context-reconfigure 24 | # Required-Start: one-context-local one-context 25 | # Required-Stop: 26 | # Should-Start: $time 27 | # Should-Stop: 28 | # Default-Start: 29 | # Default-Stop: 0 1 2 3 4 5 6 30 | # Short-Description: OpenNebula reconfiguration 31 | ### END INIT INFO 32 | 33 | # Source function library. 34 | . /etc/rc.d/init.d/functions 35 | 36 | case "$1" in 37 | start|restart) 38 | export TIMEOUT=0 39 | action $"Starting OpenNebula reconfiguration: " \ 40 | /usr/sbin/one-context-run 41 | ;; 42 | *) 43 | echo $"Usage: $0 {start|restart}" 44 | exit 2 45 | esac 46 | 47 | exit $? 48 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure-delayed##apk.one: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | name="OpenNebula delayed reconfiguration" 20 | 21 | depend() { 22 | use one-context one-context-local 23 | keyword -stop -shutdown 24 | } 25 | 26 | start() { 27 | ebegin "Starting one-context-reconfigure-delayed" 28 | /usr/sbin/one-context-run 29 | eend $? 30 | } 31 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure-delayed##deb.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # Provides: one-context-reconfigure-delayed 21 | # Required-Start: one-context-local one-context 22 | # Required-Stop: 23 | # Should-Start: $time 24 | # Should-Stop: 25 | # Default-Start: 26 | # Default-Stop: 0 1 2 3 4 5 6 27 | # Short-Description: OpenNebula delayed reconfiguration 28 | ### END INIT INFO 29 | 30 | . /lib/lsb/init-functions 31 | 32 | case "$1" in 33 | start|restart) 34 | log_daemon_msg $"Starting OpenNebula delayed reconfiguration" 35 | /usr/sbin/one-context-run 36 | log_end_msg $? 37 | ;; 38 | *) 39 | log_action_msg $"Usage: $0 {start|restart}" 40 | exit 2 41 | esac 42 | -------------------------------------------------------------------------------- /src/etc/init.d/one-context-reconfigure-delayed##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # chkconfig: - 99 1 20 | # description: OpenNebula delayed reconfiguration 21 | 22 | ### BEGIN INIT INFO 23 | # Provides: one-context-reconfigure-delayed 24 | # Required-Start: one-context-local one-context 25 | # Required-Stop: 26 | # Should-Start: $time 27 | # Should-Stop: 28 | # Default-Start: 29 | # Default-Stop: 0 1 2 3 4 5 6 30 | # Short-Description: OpenNebula delayed reconfiguration 31 | ### END INIT INFO 32 | 33 | # Source function library. 34 | . /etc/rc.d/init.d/functions 35 | 36 | case "$1" in 37 | start|restart) 38 | action $"Starting OpenNebula delayed reconfiguration: " \ 39 | /usr/sbin/one-context-run 40 | ;; 41 | *) 42 | echo $"Usage: $0 {start|restart}" 43 | exit 2 44 | esac 45 | 46 | exit $? 47 | -------------------------------------------------------------------------------- /src/etc/init/one-context-force.conf##deb.upstart.one: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 5 | # not use this file except in compliance with the License. You may obtain # 6 | # a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | #--------------------------------------------------------------------------- # 16 | 17 | description "OpenNebula forced run" 18 | author "OpenNebula Systems " 19 | 20 | manual 21 | task 22 | 23 | env TIMEOUT=0 24 | 25 | exec /usr/sbin/one-context-run force 26 | -------------------------------------------------------------------------------- /src/etc/init/one-context-local.conf##deb.upstart.one: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 5 | # not use this file except in compliance with the License. You may obtain # 6 | # a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | #--------------------------------------------------------------------------- # 16 | 17 | description "OpenNebula pre-networking contextualization" 18 | author "OpenNebula Systems " 19 | 20 | start on mounted MOUNTPOINT=/ and mounted MOUNTPOINT=/run 21 | 22 | task 23 | 24 | exec /usr/sbin/one-contextd local 25 | -------------------------------------------------------------------------------- /src/etc/init/one-context-reconfigure-delayed.conf##deb.upstart.one: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 5 | # not use this file except in compliance with the License. You may obtain # 6 | # a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | #--------------------------------------------------------------------------- # 16 | 17 | description "OpenNebula delayed reconfiguration" 18 | author "OpenNebula Systems " 19 | 20 | manual 21 | task 22 | expect fork 23 | 24 | exec /usr/sbin/one-context-run 25 | -------------------------------------------------------------------------------- /src/etc/init/one-context-reconfigure.conf##deb.upstart.one: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 5 | # not use this file except in compliance with the License. You may obtain # 6 | # a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | #--------------------------------------------------------------------------- # 16 | 17 | description "OpenNebula reconfiguration" 18 | author "OpenNebula Systems " 19 | 20 | manual 21 | task 22 | 23 | env TIMEOUT=0 24 | 25 | exec /usr/sbin/one-context-run 26 | -------------------------------------------------------------------------------- /src/etc/init/one-context.conf##deb.upstart.one: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- # 2 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 5 | # not use this file except in compliance with the License. You may obtain # 6 | # a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | #--------------------------------------------------------------------------- # 16 | 17 | description "OpenNebula contextualization" 18 | author "OpenNebula Systems " 19 | 20 | start on (runlevel [2345] and stopped one-context-local) 21 | 22 | task 23 | 24 | exec /usr/sbin/one-contextd network 25 | -------------------------------------------------------------------------------- /src/etc/modules-load.d/one-context.conf##apk: -------------------------------------------------------------------------------- 1 | ipv6 2 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-04-run-dir: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | set -e 20 | 21 | # THIS IS A CONTEXTUALIZATION GUARD 22 | if [ "$1" != 'local' ] ; then 23 | exit 0 24 | fi 25 | 26 | # Umount the directory and remove it 27 | cleanup() 28 | { 29 | [ "$MOUNTED" = "yes" ] && umount -l "${ROOTFS_DIR}" 30 | rm -r "${TMP_DIR}" 31 | } 32 | 33 | if [ "${RECREATE_RUN^^}" = "YES" ] && [ "$(uname -s)" = 'Linux' ]; then 34 | # Detection of real run-time variable data directory in case there 35 | # would be images with (unusual) reverse symlink /run -> /var/run 36 | if [ -d /run ] && ! [ -L /run ]; then 37 | RUN_DIR=/run 38 | elif [ -d /var/run ] && ! [ -L /var/run ]; then 39 | RUN_DIR=/var/run 40 | else 41 | # this shouldn't happen 42 | echo 'ERROR: No suitable run-time data directory in image!' >&2 43 | exit 1 44 | fi 45 | 46 | ### 47 | 48 | TMP_DIR=$(mktemp -d "/tmp/one-context.XXXXXX") 49 | ROOTFS_DIR="${TMP_DIR}/rootfs" 50 | trap cleanup EXIT 51 | chmod 0700 "${TMP_DIR}" 52 | mkdir "${ROOTFS_DIR}" 53 | 54 | mount --bind -o ro,nodev,noexec,nosuid / "${ROOTFS_DIR}" 55 | MOUNTED=yes 56 | 57 | # copy, but don't overwrite 58 | # NOTE: using -i /dev/null &2 75 | return 1 76 | fi 77 | 78 | FSDEV=$(echo "$MOUNT_LINE" | cut -d' ' -f1) 79 | FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f2) 80 | 81 | case "$FSTYPE" in 82 | ufs) 83 | rootdev=${FSDEV#/dev/} 84 | ;; 85 | zfs) 86 | pool=${FSDEV%%/*} 87 | rootdev=$(zpool list -v "$pool" | awk 'END { print $1 }') 88 | ;; 89 | *) 90 | echo "GROWFS: Mount-point '${_FS}' of type '${FSTYPE}' is not supported!" >&2 91 | return 0 92 | esac 93 | 94 | if [ x"$rootdev" = x"${rootdev%/*}" ]; then 95 | # raw device 96 | rawdev="$rootdev" 97 | else 98 | rawdev=$(glabel status | awk '$1 == "'"$rootdev"'" { print $3 }') 99 | if [ x"$rawdev" = x"" ]; then 100 | echo "GROWFS: Unable to found a device for '${rootdev}'!" >&2 101 | return 1 102 | fi 103 | fi 104 | 105 | if [ -n "$DEBUG" ]; then 106 | echo "DEVICE: ${rootdev}" 107 | echo "RAW DEVICE: ${rawdev}" 108 | echo "FSTYPE: ${FSTYPE}" 109 | fi 110 | 111 | sysctl -b kern.geom.conftxt | awk ' 112 | { 113 | lvl=$1 114 | device[lvl] = $3 115 | type[lvl] = $2 116 | idx[lvl] = $7 117 | parttype[lvl] = $13 118 | if (dev == $3) { 119 | for (i = 1; i <= lvl; i++) { 120 | # resize 121 | if (type[i] == "PART") { 122 | pdev = device[i - 1] 123 | cmd[i] = "gpart resize -i " idx[i] " " pdev 124 | if (parttype[i] == "GPT") 125 | cmd[i] = "gpart recover " pdev " ; " cmd[i] 126 | } else if (type[i] == "LABEL") { 127 | continue 128 | } else { 129 | print "unhandled type: " type[i] 130 | exit 1 131 | } 132 | } 133 | for (i = 1; i <= lvl; i++) { 134 | if (cmd[i]) 135 | system(cmd[i]) 136 | } 137 | exit 0 138 | } 139 | }' dev="$rawdev" 140 | 141 | gpart commit "$rootdev" 142 | case "$FSTYPE" in 143 | ufs) 144 | growfs -y /dev/"$rootdev" 145 | ;; 146 | zfs) 147 | zpool online -e "$pool" "$rootdev" 148 | ;; 149 | esac 150 | ) 151 | 152 | # 153 | # main 154 | # 155 | 156 | if [ -z "${GROW_FS}" ] && [ "${GROW_ROOTFS}" != 'YES' ]; then 157 | echo 'GROWFS: Skipping filesystem resize' >&2 158 | exit 0 159 | fi 160 | 161 | # add rootfs ('/') to the GROW_FS if GROW_ROOTFS=YES 162 | if [ "${GROW_ROOTFS}" = 'YES' ] ; then 163 | # duplicates will be removed by the next command 164 | GROW_FS="/ ${GROW_FS}" 165 | fi 166 | 167 | # sanitize the GROW_FS 168 | GROW_FS=$(echo "${GROW_FS}" | sed 's/[[:space:]]\+/\n/g' | sed '/^$/d' | sort -u) 169 | 170 | OS=$(uname | tr '[:upper:]' '[:lower:]') 171 | case "$OS" in 172 | linux) 173 | GROWPART=$(command -v growpart || true) 174 | if [ -z "${GROWPART}" ]; then 175 | echo "GROWFS: growpart command is missing" >&2 176 | exit 1 177 | fi 178 | ;; 179 | freebsd) 180 | if ! [ -x /etc/rc.d/growfs ]; then 181 | echo "GROWFS: growfs command is missing" >&2 182 | exit 1 183 | fi 184 | ;; 185 | esac 186 | 187 | export DEBUG 188 | _exit_result=0 189 | 190 | # TODO: Check OS first, then iterate FS 191 | for _FS in ${GROW_FS} ; do 192 | 193 | # FreeBSD 194 | # only non rootfs resize is supported 195 | if [ "${OS}" = 'freebsd' ]; then 196 | case "$_FS" in 197 | /) 198 | # avoid resizing rootFS on FreeBSD 199 | # https://github.com/OpenNebula/addon-context-linux/issues/298 200 | continue 201 | 202 | # This breaks the image unless executed manually 203 | /etc/rc.d/growfs onestart || _exit_result=$? 204 | ;; 205 | *) 206 | freebsd_growfs "$_FS" || _exit_result=$? 207 | ;; 208 | esac 209 | continue 210 | fi 211 | 212 | # Linux 213 | # try /proc/mounts first otherwise fallback to /etc/mtab 214 | MOUNT_LINE=$(\ 215 | if [ -e /proc/mounts ] ; then \ 216 | cat /proc/mounts ; \ 217 | else \ 218 | cat /etc/mtab ; \ 219 | fi | awk -v grow_fs="${_FS}" ' 220 | {if (($0 !~ /rootfs/) && ($2 == grow_fs)) print $1, $3;} 221 | ') 222 | 223 | if [ -z "$MOUNT_LINE" ] ; then 224 | echo "GROWFS: No such mountpoint: ${_FS}" >&2 225 | _exit_result=1 226 | continue 227 | fi 228 | 229 | DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) 230 | FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f2) 231 | 232 | LVM=$(lvdisplay "${DEVICE}" 2>/dev/null | wc -l) 233 | if [ "$LVM" -eq 0 ]; then 234 | # findmnt supports --nofsroot since util-linux v2.19.1 but 235 | # unfortunately this is broken even in v2.20 (Ubuntu 14.04) 236 | # so trivial test follows which should filter out old and broken 237 | # versions... 238 | if findmnt -V >/dev/null 2>&1 ; then 239 | DEVICE=$(findmnt -ln -o SOURCE --nofsroot "$_FS") 240 | else 241 | # old broken util-linux does not have the -V option 242 | DEVICE=$(findmnt -ln -o SOURCE "$_FS") 243 | fi 244 | DISK=$(echo "$DEVICE" | sed 's/[0-9]*$//') 245 | PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||") 246 | LVM="no" 247 | fi 248 | 249 | if [ "${LVM}" != "no" ]; then 250 | # TODO: This should be rewritten to accomodate other PVs - this expects 251 | # that PV name ends with zero or exactly one numeric: /dev/sda1 252 | PVRESIZE=$(which pvresize) 253 | LVEXTEND=$(which lvextend) 254 | DISK=$(pvdisplay | awk '/PV Name/ {sub(/.$/, "", $3); print $3;}') 255 | PARTITION=$(pvdisplay | awk -v d="$DISK" '/PV Name/ {sub("^" d, "", $3); print $3;}') 256 | PV=$(pvdisplay | awk '/PV Name/ {print $3}') 257 | LV=$(lvdisplay "${DEVICE}" | awk '/LV Path/ {print $3}') 258 | 259 | # when PV is on MSDOS logical partition, detect the umbrella 260 | # extended partition and grow it first 261 | TABLE=$(parted -s "${DISK}" print 2>/dev/null | awk '/Partition Table:/ {print $3}') 262 | if [ "${TABLE}" = 'msdos' ] && [ "${PARTITION}" -gt 4 ]; then 263 | EXTENDED=$(parted -s "${DISK}" print | awk '/extended/ {print $1}') 264 | PARTITION="${EXTENDED} ${PARTITION}" 265 | fi 266 | fi 267 | 268 | if [ -n "$DEBUG" ]; then 269 | echo "DEVICE: ${DEVICE}" 270 | echo "FSTYPE: ${FSTYPE}" 271 | echo "DISK: ${DISK}" 272 | echo "PARTITION: ${PARTITION}" 273 | fi 274 | 275 | ( 276 | for PART in ${PARTITION}; do 277 | ${GROWPART} "${DISK}" "${PART}" 278 | done 279 | 280 | if [ "${LVM}" != "no" ]; then 281 | ${PVRESIZE} "${PV}" 282 | ${LVEXTEND} -l +100%FREE "${LV}" 283 | fi 284 | ) || : # don't fail, partition can be already extended by dracut 285 | 286 | case "${FSTYPE}" in 287 | ext2|ext3|ext4) 288 | resize2fs "${DEVICE}" 289 | ;; 290 | xfs) 291 | xfs_growfs "${_FS}" 292 | ;; 293 | btrfs) 294 | btrfs filesystem resize max "${_FS}" 295 | ;; 296 | esac 297 | 298 | done 299 | 300 | exit "$_exit_result" 301 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-09-timezone: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | if [ -z "${TIMEZONE}" ]; then 25 | exit 0 26 | fi 27 | 28 | if ! timedatectl set-timezone "${TIMEZONE}" 2>/dev/null; then 29 | _tz_base='/usr/share/zoneinfo/' 30 | _tz_dest=$(readlink -f "${_tz_base}${TIMEZONE}" 2>/dev/null) 31 | 32 | # if timezone file path is resolvable file and 33 | # real path is inside the timezone directory 34 | if [ -n "${_tz_dest}" ] && 35 | [ -f "${_tz_dest}" ] && 36 | [[ "${_tz_dest}" =~ ^${_tz_base} ]]; 37 | then 38 | ln -sf "${_tz_dest}" /etc/localtime 39 | else 40 | echo "ERROR: Invalid timezone '${TIMEZONE}'" >&2 41 | exit 1 42 | fi 43 | fi 44 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-10-network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # shellcheck disable=SC1091,SC1090 20 | 21 | . /etc/one-context.d/loc-10-network.d/functions 22 | 23 | context_type="$1" 24 | action="$2" 25 | os_id=$(detect_os) 26 | 27 | if [ -z "${action}" ] ; then 28 | action="configure" 29 | fi 30 | 31 | # update detect_os function if new distro is added 32 | if [ -z "${NETCFG_TYPE}" ] ; then 33 | case "${os_id}" in 34 | alpine) 35 | NETCFG_TYPE='interfaces' 36 | ;; 37 | altlinux) 38 | NETCFG_TYPE='networkd nm' 39 | ;; 40 | debian|devuan|ubuntu) 41 | NETCFG_TYPE='interfaces netplan nm networkd' 42 | ;; 43 | fedora|centos|rhel|almalinux|ol|rocky) 44 | NETCFG_TYPE='scripts nm networkd' 45 | ;; 46 | opensuse*|sles|sled) 47 | NETCFG_TYPE='scripts' 48 | ;; 49 | amzn) 50 | NETCFG_TYPE='scripts' 51 | ;; 52 | freebsd) 53 | NETCFG_TYPE='bsd' 54 | ;; 55 | *) 56 | NETCFG_TYPE='none' 57 | ;; 58 | esac 59 | else 60 | # trim and lowercase 61 | NETCFG_TYPE=$(echo "$NETCFG_TYPE" | \ 62 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \ 63 | tr '[:upper:]' '[:lower:]') 64 | 65 | # support alternative names for some configuration renderers 66 | case "${NETCFG_TYPE}" in 67 | networkmanager) 68 | NETCFG_TYPE='nm' 69 | ;; 70 | systemd-networkd|systemd-network|systemd) 71 | NETCFG_TYPE='networkd' 72 | ;; 73 | redhat) 74 | NETCFG_TYPE='scripts' 75 | ;; 76 | debian) 77 | NETCFG_TYPE='interfaces' 78 | ;; 79 | freebsd) 80 | NETCFG_TYPE='bsd' 81 | ;; 82 | esac 83 | fi 84 | 85 | if [ "${NETCFG_TYPE}" != 'none' ] ; then 86 | _found_valid_netcfg='no' 87 | 88 | # from a space separated list of $NETCFG_TYPE candidates check one 89 | # by one and select the first suitable one for current environment 90 | for _cfgtype in ${NETCFG_TYPE} ; do 91 | _cfgtype_file="/etc/one-context.d/loc-10-network.d/netcfg-$(basename "${_cfgtype}")" 92 | 93 | if [ -e "${_cfgtype_file}" ] ; then 94 | # reload functions to reset back any overrides from prev. netcfg-X 95 | . /etc/one-context.d/loc-10-network.d/functions 96 | . "${_cfgtype_file}" 97 | else 98 | echo "ERROR [!]: Requested network type is not implemented: ${_cfgtype}" >&2 99 | exit 1 100 | fi 101 | 102 | if is_network_supported ; then 103 | _found_valid_netcfg='yes' 104 | break 105 | fi 106 | done 107 | 108 | if [ "${_found_valid_netcfg}" = 'no' ] ; then 109 | echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2 110 | exit 1 111 | fi 112 | else 113 | # any action is meaningless without functioning network type 114 | action='none' 115 | fi 116 | 117 | # regardless of the required_context_type we need cleanup in the 'local' stage 118 | # 119 | # TODO: currently we must skip cleanup during reconfigure action (check-out the 120 | # initialize_network function) otherwise we would wiped-out running config and 121 | # broke the system 122 | if [ "${context_type}" = 'local' ] ; then 123 | case "$action" in 124 | configure|reconfigure) 125 | initialize_network 126 | ;; 127 | *) 128 | echo "ERROR [!]: Unknown ACTION: ${action}" >&2 129 | exit 1 130 | ;; 131 | esac 132 | fi 133 | 134 | # this is a contextualization guard 135 | # shellcheck disable=SC2154 136 | case "${required_context_type}" in 137 | ''|local|online) 138 | if [ "${required_context_type:-local}" != "${context_type}" ] ; then 139 | # skip this netcfg at this stage 140 | exit 0 141 | fi 142 | ;; 143 | *) 144 | echo "ERROR [!]: Unknown required context type: ${required_context_type}" >&2 145 | exit 1 146 | ;; 147 | esac 148 | 149 | case "$action" in 150 | none) 151 | echo "INFO: Network will not be configured" >&2 152 | ;; 153 | configure) 154 | configure_network 155 | ;; 156 | reconfigure) 157 | configure_network 158 | reload_network 159 | ;; 160 | *) 161 | echo "ERROR [!]: Unknown ACTION: ${action}" >&2 162 | exit 1 163 | ;; 164 | esac 165 | 166 | exit 0 167 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-10-network-pci##one: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | get_iface_var() 25 | { 26 | var_name="${UPCASE_DEV}_$1" 27 | var=$(eval "echo \"\${$var_name}\"") 28 | 29 | echo $var 30 | } 31 | 32 | get_pci_interfaces() 33 | { 34 | env | grep -E "^PCI[0-9]+_MAC=" | sed 's/_.*$//' | sort 35 | } 36 | 37 | get_dev_from_pci() 38 | { 39 | DEV=$(find /sys/class/net/*/device -lname "*$1" 2>/dev/null | awk -F '/' '{print $5}') 40 | 41 | if [ -z "$DEV" ]; then 42 | echo "PCI Device $1 not found" >&2 43 | return 44 | fi 45 | 46 | if [ `echo "$DEV" | wc -l` -gt 1 ]; then 47 | echo "More than one PCI Device $1 found" >&2 48 | return 49 | fi 50 | 51 | echo "$DEV" 52 | } 53 | 54 | PCI_INTERFACES=$(get_pci_interfaces) 55 | 56 | for pci in $PCI_INTERFACES; do 57 | UPCASE_DEV=$pci 58 | 59 | IP=$(get_iface_var "IP") 60 | MAC=$(get_iface_var "MAC") 61 | MASK=$(get_iface_var "MASK") 62 | MASK=${MASK:-255.255.255.0} 63 | GATEWAY=$(get_iface_var "GATEWAY") 64 | METRIC=$(get_iface_var "METRIC") 65 | MTU=$(get_iface_var "MTU") 66 | VLAN_ID=$(get_iface_var "VLAN_ID") 67 | 68 | IP6=$(get_iface_var "IP6") 69 | IP6_PREFIX_LENGTH=$(get_iface_var "IP6_PREFIX_LENGTH") 70 | IP6_PREFIX_LENGTH=${IP6_PREFIX_LENGTH:-64} 71 | IP6_ULA=$(get_iface_var "IP6_ULA") 72 | GATEWAY6=$(get_iface_var "GATEWAY6") 73 | 74 | ADDRESS=$(get_iface_var "ADDRESS") 75 | [ -z "$ADDRESS" ] && continue 76 | 77 | DEV=$(get_dev_from_pci "$ADDRESS") 78 | [ -z "$DEV" ] && continue 79 | 80 | # MAC 81 | ip link set dev $DEV address $MAC 82 | ip link set dev $DEV up 83 | 84 | # MTU 85 | if [ -n "$MTU" ]; then 86 | ip link set dev $DEV mtu $MTU 87 | fi 88 | 89 | # VLAN (802.1Q) 90 | if [ -n "$VLAN_ID" ]; then 91 | ip link add link $DEV name $DEV.$VLAN_ID type vlan id $VLAN_ID 92 | ip link set dev $DEV.$VLAN_ID up 93 | DEV=$DEV.$VLAN_ID 94 | fi 95 | 96 | # IPv4 97 | if [ -n "$IP" ]; then 98 | ip address add $IP/$MASK dev $DEV 99 | 100 | if [ -n "$GATEWAY" ]; then 101 | ip route add default via $GATEWAY dev $DEV ${METRIC:+metric ${METRIC}} 102 | fi 103 | fi 104 | 105 | # IPv6 106 | if [ -n "$IP6" ]; then 107 | ip -6 address add $IP6/$IP6_PREFIX_LENGTH dev $DEV 108 | 109 | if [ -n "$IP6_ULA" ]; then 110 | ip -6 address add $IP6_ULA/64 dev $DEV 111 | fi 112 | 113 | if [ -n "$GATEWAY6" ]; then 114 | ip -6 route add default via $GATEWAY6 dev $DEV 115 | fi 116 | fi 117 | done 118 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-10-network.d/netcfg-bsd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # 20 | # network module implementation 21 | # 22 | 23 | is_network_supported() 24 | { 25 | case "${os_id}" in 26 | freebsd) 27 | return 0 28 | ;; 29 | esac 30 | 31 | return 1 32 | } 33 | 34 | configure_network() 35 | { 36 | gen_resolvconf 37 | gen_network_configuration > /etc/rc.conf.d/network 38 | } 39 | 40 | stop_network() 41 | { 42 | service netif stop >/dev/null 43 | service routing stop >/dev/null 44 | service rtsold stop >/dev/null 45 | } 46 | 47 | start_network() 48 | { 49 | service netif start >/dev/null 50 | service routing start >/dev/null 51 | service rtsold start >/dev/null 52 | } 53 | 54 | reload_network() 55 | { 56 | service netif restart >/dev/null 57 | service routing restart >/dev/null 58 | service rtsold restart >/dev/null 59 | } 60 | 61 | # 62 | # helper functions 63 | # 64 | 65 | # TODO: remove global variables and get rid off exports 66 | # 67 | # to satisfy shellcheck SC2154: 68 | export os_id 69 | export ip 70 | export network 71 | export mask 72 | export cidr 73 | export ip6 74 | export ip6_prefix_length 75 | export ip6_ula 76 | export mac 77 | export dev 78 | export mtu 79 | export gateway 80 | export ip6_gateway 81 | export method 82 | export ip6_method 83 | export metric 84 | export ip6_metric 85 | export dns 86 | export search_domains 87 | export external 88 | export detach 89 | export all_nameservers 90 | export all_search_domains 91 | 92 | get_interface_mac() 93 | ( 94 | _macs=$(ifconfig | grep ether | awk '{print $2}') 95 | 96 | for _mac in ${_macs} ; do 97 | _iface=$(ifconfig | grep -B 2 "$_mac" | head -n 1 | awk '{print $1}' | cut -d ':' -f 1) 98 | echo "${_iface} ${_mac}" 99 | done 100 | ) 101 | 102 | gen_iface_conf() 103 | { 104 | echo -n "ifconfig_${dev}=\"inet ${ip} netmask ${mask}" 105 | 106 | if [ -n "${mtu}" ]; then 107 | echo -n " mtu ${mtu}" 108 | fi 109 | 110 | # WARNING: On FreeBSD the interface metrics are used only 111 | # by routing daemons (see man 8 ifconfig) 112 | if [ -n "${metric}" ]; then 113 | echo -n " metric ${metric}" 114 | fi 115 | 116 | echo "\"" 117 | 118 | ### 119 | 120 | routes_conf_path="/etc/rc.conf.d/routing" 121 | 122 | if [ -n "${gateway}" ]; then 123 | echo "defaultrouter=\"${gateway}\"" >> $routes_conf_path 124 | fi 125 | 126 | # Add static routes 127 | # static_routes="lan mumoffice foo" 128 | # route_lan="-net 192.168.1.0/24 192.168.1.254" 129 | # route_mumoffice="-net 10.0.0.0/8 10.30.110.5" 130 | # route_foo="-host 169.254.1.1 -iface lo0" 131 | route_names="" 132 | 133 | static_routes=$(get_iface_var "$dev" "ROUTES") 134 | 135 | if [ -n "${static_routes}" ]; then 136 | IFS=',' read -r -a routes <<< "$static_routes" 137 | 138 | routes_conf=() 139 | 140 | declare -i index=0 141 | 142 | for route in "${routes[@]}"; do 143 | rsplit=(${route}) 144 | dst="${rsplit[0]}" 145 | gw="${rsplit[2]}" 146 | 147 | route_name="r_${index}" 148 | route_names="${route_names}${route_name} " 149 | 150 | route_conf="route_${route_name}=\"-net ${dst} ${gw}\"" 151 | routes_conf+=("$route_conf") 152 | 153 | index+=1 154 | done 155 | 156 | # remove last whitespace 157 | echo -e "static_routes=\"$(echo "$route_names" | xargs)\"" >>$routes_conf_path 158 | 159 | for route_conf in "${routes_conf[@]}"; do 160 | echo -e "${route_conf}" >>$routes_conf_path 161 | done 162 | 163 | fi 164 | 165 | # Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0 166 | if missing_onegate_proxy_route; then 167 | route_name="r_onegateproxy" 168 | 169 | sed -i "s/${route_names}/${route_names} ${route_name}/g" "$routes_conf_path" 170 | route_conf="route_${route_name}=\"-host ${onegate_host} -iface ${dev}\"" 171 | 172 | echo -e "$route_conf\n" >> $routes_conf_path 173 | 174 | unset onegate_proxy_route_missing 175 | fi 176 | } 177 | 178 | gen_dhcp_conf() 179 | { 180 | echo -n "ifconfig_${dev}=\"DHCP" 181 | 182 | if [ -n "${mtu}" ]; then 183 | echo -n " inet mtu ${mtu}" 184 | fi 185 | 186 | echo "\"" 187 | } 188 | 189 | gen_alias_conf() 190 | { 191 | echo "ifconfig_${dev}_alias${alias_num}=\"inet ${ip} netmask ${mask}\"" 192 | alias_num=$((alias_num + 1)) 193 | } 194 | 195 | gen_iface6_conf() 196 | { 197 | echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}" 198 | 199 | if [ -n "${mtu}" ]; then 200 | echo -n " mtu ${mtu}" 201 | fi 202 | 203 | # WARNING: On FreeBSD the interface metrics are used only 204 | # by routing daemons (see man 8 ifconfig) 205 | if [ -n "${ip6_metric}" ]; then 206 | echo -n " metric ${ip6_metric}" 207 | fi 208 | 209 | echo " -accept_rtadv\"" 210 | 211 | if [ -n "${ip6_ula}" ]; then 212 | echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\"" 213 | alias_num=$((alias_num + 1)) 214 | fi 215 | 216 | ### 217 | 218 | if [ -n "${ip6_gateway}" ]; then 219 | echo "ipv6_defaultrouter=\"${ip6_gateway}\"" >> /etc/rc.conf.d/routing 220 | fi 221 | } 222 | 223 | gen_dhcp6_conf() 224 | { 225 | echo -n "ifconfig_${dev}_ipv6=\"" 226 | 227 | if [ "${ip6_method}" = "dhcp" ] ; then 228 | echo -n "DHCP " 229 | 230 | # FreeBSD support for DHCP6 does not seem to be great: 231 | # https://forums.freebsd.org/threads/ipv6-dhcpv6-client-and-accept_rtadv-vs-rtsold.77421/ 232 | # https://forums.freebsd.org/threads/is-there-a-working-dhcpv6-client-for-freebsd.60168/ 233 | # https://subatomicsolutions.org/8-freebsd/13-ipv4-ipv6-client-addresses-via-dhcp 234 | _dhclient_program=$(sysrc -n dhclient_program 2>/dev/null) 235 | if [ -z "${_dhclient_program}" ] || [ "${_dhclient_program}" = '/sbin/dhclient' ]; then 236 | echo "WARNING [!]: DHCPv6 on '${os_id}' is poorly supported, you need a different DHCP client! You can install net/isc-dhcp44-client and put into /etc/rc.conf: dhclient_program=\"/usr/sbin/one-dual-dhclient\"" >&2 237 | fi 238 | fi 239 | 240 | echo -n "inet6 accept_rtadv" 241 | 242 | if [ -n "${mtu}" ]; then 243 | echo -n " mtu ${mtu}" 244 | fi 245 | 246 | echo "\"" 247 | 248 | # Enable Router Solicitation Deaemon 249 | # NOTE: It's not enough to just enable the daemon during the current 250 | # boot process, since the services to run are already evaluated. We also 251 | # explicitly start the service on our own (but doesn't have to be correct!) 252 | sysrc rtsold_enable="YES" >/dev/null 253 | service rtsold start >/dev/null 254 | } 255 | 256 | gen_alias6_conf() 257 | { 258 | # very first IPv6 can't be alias 259 | if [ -n "${has_ip6}" ]; then 260 | echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}\"" 261 | alias_num=$((alias_num + 1)) 262 | else 263 | echo -n "ifconfig_${dev}_ipv6=\"inet6 ${ip6} prefixlen ${ip6_prefix_length:-64}" 264 | 265 | if [ -n "${mtu}" ]; then 266 | echo -n " mtu ${mtu}" 267 | fi 268 | 269 | # WARNING: On FreeBSD the interface metrics are used only 270 | # by routing daemons (see man 8 ifconfig) 271 | if [ -n "${ip6_metric}" ]; then 272 | echo -n " metric ${ip6_metric}" 273 | fi 274 | 275 | echo " -accept_rtadv\"" 276 | fi 277 | 278 | if [ -n "${ip6_ula}" ]; then 279 | echo "ifconfig_${dev}_alias${alias_num}=\"inet6 ${ip6_ula} prefixlen 64\"" 280 | alias_num=$((alias_num + 1)) 281 | fi 282 | } 283 | 284 | gen_network_configuration() 285 | { 286 | # clean routing information 287 | echo '# Generated by one-context' | tee /etc/rc.conf.d/routing 288 | 289 | _context_interfaces=$(get_context_interfaces) 290 | 291 | for _iface in $_context_interfaces; do 292 | setup_iface_vars "$_iface" 293 | 294 | skip_interface && continue 295 | 296 | case "${method}" in 297 | ''|static) 298 | [ -n "${ip}" ] && gen_iface_conf 299 | ;; 300 | dhcp) 301 | gen_dhcp_conf 302 | ;; 303 | esac 304 | 305 | case "${ip6_method}" in 306 | ''|static) 307 | [ -n "${ip6}" ] && gen_iface6_conf 308 | ;; 309 | auto|dhcp) 310 | gen_dhcp6_conf 311 | ;; 312 | disable) 313 | : 314 | ;; 315 | esac 316 | 317 | has_ip6="${ip6}" 318 | _aliases=$(get_interface_alias "$_iface") 319 | alias_num=0 320 | 321 | for _nic_alias in $_aliases; do 322 | setup_ipadr_vars "$_nic_alias" 323 | setup_ip6adr_vars "$_nic_alias" 324 | setup_alias_vars "$_nic_alias" 325 | 326 | if [ -z "${detach}" ]; then 327 | if ! is_true "${external}" ; then 328 | [ -n "${ip}" ] && gen_alias_conf 329 | 330 | if [ -n "${ip6}" ]; then 331 | gen_alias6_conf 332 | has_ip6="${ip6}" 333 | fi 334 | fi 335 | fi 336 | done 337 | done 338 | } 339 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-10-network.d/netcfg-netplan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # 20 | # network module implementation 21 | # 22 | 23 | is_network_supported() 24 | { 25 | command -v netplan >/dev/null 26 | 27 | return $? 28 | } 29 | 30 | configure_network() 31 | { 32 | init_netplan_renderer 33 | 34 | gen_resolvconf 35 | gen_network_configuration > /etc/netplan/50-one-context.yaml 36 | netplan generate 37 | nm_symlink_run_connections 38 | 39 | # On Debian 10 and Ubuntu 18.04 the initial netplan apply is needed to 40 | # set some interface parameters (e.g., MTU). Unfortunately, this deadlocks 41 | # booting of current systems, so we execute netplan apply on the background 42 | case "${NETCFG_NETPLAN_RENDERER}" in 43 | ''|networkd) 44 | flock /var/run/one-context/netplan.lock nohup netplan apply &>/dev/null & 45 | ;; 46 | esac 47 | } 48 | 49 | stop_network() 50 | { 51 | service networking stop 52 | } 53 | 54 | start_network() 55 | { 56 | netplan generate 57 | nm_symlink_run_connections 58 | service networking start 59 | flock /var/run/one-context/netplan.lock netplan apply 60 | } 61 | 62 | reload_network() 63 | { 64 | netplan generate 65 | nm_symlink_run_connections 66 | flock /var/run/one-context/netplan.lock netplan apply 67 | } 68 | 69 | # 70 | # helper functions 71 | # 72 | 73 | # TODO: remove global variables and get rid off exports 74 | # 75 | # to satisfy shellcheck SC2154: 76 | export os_id 77 | export ip 78 | export network 79 | export mask 80 | export cidr 81 | export ip6 82 | export ip6_prefix_length 83 | export ip6_ula 84 | export mac 85 | export dev 86 | export mtu 87 | export gateway 88 | export ip6_gateway 89 | export method 90 | export ip6_method 91 | export metric 92 | export ip6_metric 93 | export dns 94 | export search_domains 95 | export external 96 | export detach 97 | export all_nameservers 98 | export all_search_domains 99 | 100 | gen_addresses() 101 | { 102 | case "${method}" in 103 | ''|static) 104 | [ -n "${ip}" ] && gen_addr_conf 105 | ;; 106 | esac 107 | 108 | case "${ip6_method}" in 109 | ''|static) 110 | [ -n "${ip6}" ] && gen_addr6_conf 111 | ;; 112 | esac 113 | 114 | _aliases=$(get_interface_alias "$_iface") 115 | 116 | for _nic_alias in $_aliases; do 117 | setup_ipadr_vars "$_nic_alias" 118 | setup_ip6adr_vars "$_nic_alias" 119 | setup_alias_vars "$_nic_alias" 120 | 121 | if [ -z "${detach}" ]; then 122 | if ! is_true "${external}" ; then 123 | [ -n "${ip}" ] && gen_addr_conf 124 | [ -n "${ip6}" ] && gen_addr6_conf 125 | fi 126 | fi 127 | done 128 | } 129 | 130 | gen_routes() 131 | { 132 | if [ -n "${gateway}" ] && { [ -z "${method}" ] || [ "${method}" = 'static' ]; }; then 133 | cat </dev/null)" in 259 | 1.14.*) # Debian 10 260 | echo "WARNING: Symlinking NM's ephemeral connections into /etc" >&2 261 | ;; 262 | *) 263 | return 264 | ;; 265 | esac 266 | 267 | # symlink Netplan connection files 268 | for _src in /run/NetworkManager/system-connections/netplan-*; do 269 | if [ -f "${_src}" ]; then 270 | _dst="/etc/NetworkManager/system-connections/$(basename "${_src}")" 271 | ln -s "${_src}" "${_dst}" 272 | fi 273 | done 274 | } 275 | 276 | init_netplan_renderer() 277 | { 278 | if [ -z "${NETCFG_NETPLAN_RENDERER}" ] ; then 279 | if command -v networkctl >/dev/null ; then 280 | NETCFG_NETPLAN_RENDERER='networkd' 281 | elif command -v nmcli >/dev/null ; then 282 | NETCFG_NETPLAN_RENDERER='NetworkManager' 283 | else 284 | # fallback to networkd only not to leave the variable 285 | # uninitialized, deployment most likely won't work! 286 | NETCFG_NETPLAN_RENDERER='networkd' 287 | fi 288 | else 289 | # support alternative names for some configuration renderers 290 | _netcfg_netplan_renderer=$(echo "$NETCFG_NETPLAN_RENDERER" | \ 291 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \ 292 | tr '[:upper:]' '[:lower:]') 293 | 294 | # normalize renderer names and support alternatives 295 | case "${_netcfg_netplan_renderer}" in 296 | systemd-networkd|systemd-network|systemd|networkd) 297 | NETCFG_NETPLAN_RENDERER='networkd' 298 | ;; 299 | networkmanager|nm) 300 | NETCFG_NETPLAN_RENDERER='NetworkManager' 301 | ;; 302 | esac 303 | fi 304 | } 305 | 306 | gen_network_configuration() 307 | { 308 | if [ "${NETCFG_NETPLAN_RENDERER}" = 'NetworkManager' ]; then 309 | nm_enable 310 | fi 311 | 312 | cat </dev/null 26 | 27 | return $? 28 | } 29 | 30 | configure_network() 31 | { 32 | gen_resolvconf 33 | gen_network_configuration 34 | } 35 | 36 | stop_network() 37 | { 38 | systemctl stop systemd-networkd.service 39 | } 40 | 41 | start_network() 42 | { 43 | systemctl start systemd-networkd.service 44 | 45 | # Dummy query waits until networkd is running 46 | networkctl list &>/dev/null || : 47 | } 48 | 49 | reload_network() 50 | { 51 | # TODO: for newer systemd-networkd use 52 | # networkctl reload && networkctl reconfigure ethX 53 | # and fallback to service restart only if needed 54 | systemctl restart systemd-networkd.service 55 | 56 | # Dummy query waits until networkd is running 57 | networkctl list &>/dev/null || : 58 | } 59 | 60 | # 61 | # helper functions 62 | # 63 | 64 | # TODO: remove global variables and get rid off exports 65 | # 66 | # to satisfy shellcheck SC2154: 67 | export os_id 68 | export ip 69 | export network 70 | export mask 71 | export cidr 72 | export ip6 73 | export ip6_prefix_length 74 | export ip6_ula 75 | export mac 76 | export dev 77 | export mtu 78 | export gateway 79 | export ip6_gateway 80 | export method 81 | export ip6_method 82 | export metric 83 | export ip6_metric 84 | export dns 85 | export search_domains 86 | export external 87 | export detach 88 | export all_nameservers 89 | export all_search_domains 90 | 91 | gen_iface_conf() 92 | { 93 | cat < 279 | is_networkd_iface_managed() 280 | ( 281 | _managed=$(LANG=C networkctl list -al --no-pager --no-legend | \ 282 | awk -v dev="$1" '{if ($2 == dev) print $NF;}' | \ 283 | tr '[:upper:]' '[:lower:]') 284 | 285 | case "${_managed}" in 286 | ''|unmanaged) 287 | return 1 288 | ;; 289 | esac 290 | 291 | return 0 292 | ) 293 | 294 | gen_network_configuration() 295 | { 296 | _context_interfaces=$(get_context_interfaces) 297 | 298 | _networkd_version=$(networkctl --version | head -1 | awk '{print $2}') 299 | 300 | if [ -n "$_networkd_version" ]; then 301 | # put some dummy low version if not detected 302 | _networkd_version="100" 303 | fi 304 | 305 | for _iface in $_context_interfaces; do 306 | setup_iface_vars "$_iface" 307 | 308 | skip_interface && continue 309 | 310 | # NOTE: This is needed to workaround issue with the networkd metrics. 311 | # 312 | # When attaching new NIC from the same vnet on a running system then 313 | # the networkd will assign some metric to the prefix route of the first 314 | # NIC but leave out metric for the same prefix route of the new NIC. 315 | # 316 | # What happens is that outgoing packets on this subnet will now always 317 | # use the second NIC even while the incoming packets were targeted for 318 | # the IP on the first NIC - the result is a broken connection. 319 | # 320 | # This occurs at least with systemd/networkd version 248, which is on 321 | # Cent OS 8 for example. 322 | 323 | 324 | if [ $_networkd_version -le 250 ]; then 325 | if is_networkd_iface_managed "${dev}" ; then 326 | # networkctl up/down is not on ubuntu <21.04 327 | networkctl down "$dev" 2>/dev/null || true 328 | 329 | # this is still necessary to really unconfigure the interface 330 | ip addr flush "$dev" 331 | fi 332 | fi 333 | 334 | { 335 | cat < "/etc/systemd/network/${dev}.network" 404 | 405 | done 406 | } 407 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-12-firewall##vr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | get_management_interfaces() { 25 | env | grep -E "^ETH[0-9]+_VROUTER_MANAGEMENT=YES" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort 26 | } 27 | 28 | get_context_interfaces() { 29 | interfaces="$(env | grep -E "^ETH[0-9]+_MAC=" | sed 's/_.*$//' | tr 'ETH' 'eth' | sort)" 30 | management="$(get_management_interfaces)" 31 | if [ -n "$management" ]; then 32 | interfaces="$(echo "$interfaces" | grep -v "$management")" 33 | fi 34 | echo "$interfaces" 35 | } 36 | 37 | gen_header() { 38 | cat < /etc/iptables/rules-save 88 | 89 | if [ "$2" == "reconfigure" ]; then 90 | reload_service 91 | else 92 | rc-update add iptables boot 93 | fi 94 | 95 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-14-mount-swap##one: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | # arg: 25 | is_true() 26 | ( 27 | _value=$(echo "$1" | \ 28 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \ 29 | tr '[:upper:]' '[:lower:]') 30 | case "$_value" in 31 | 1|true|yes|y) 32 | return 0 33 | ;; 34 | esac 35 | 36 | return 1 37 | ) 38 | 39 | activate_swaps_linux() { 40 | SWAP_DRIVES=$(blkid -t TYPE="swap" -o device) 41 | for SWAP in $SWAP_DRIVES ; do 42 | if [ -z "$(swapon -s | grep $SWAP)" ]; then 43 | swapon "$SWAP" 44 | fi 45 | done 46 | } 47 | 48 | if is_true "${IGNORE_SWAP}" ; then 49 | exit 0 50 | fi 51 | 52 | if [ "$(uname -s)" = 'Linux' ]; then 53 | activate_swaps_linux 54 | fi 55 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-15-ip_forward##vr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | if [ -z "${VROUTER_ID}${VROUTER_KEEPALIVED_ID}" ]; then 25 | if [ -f /etc/sysctl.d/01-one.conf ]; then 26 | unlink /etc/sysctl.d/01-one.conf 27 | sysctl -w net.ipv4.ip_forward=0 28 | fi 29 | else 30 | echo 'net.ipv4.ip_forward = 1' >/etc/sysctl.d/01-one.conf 31 | sysctl -w net.ipv4.ip_forward=1 32 | fi 33 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-15-keepalived##vr: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | get_context_interfaces() { 25 | env | grep -E "^ETH[0-9]+_VROUTER_IP=" | sed 's/_.*$//' | sort 26 | } 27 | 28 | downcase() { 29 | tr 'ETH' 'eth' 30 | } 31 | 32 | get_ip() { 33 | ip=$(get_iface_var "$1" "IP") 34 | 35 | echo $ip 36 | } 37 | 38 | get_vrouter_id() { 39 | vrouter_id="$VROUTER_KEEPALIVED_ID" 40 | 41 | if [ -z "$vrouter_id" ]; then 42 | vrouter_id="0" 43 | fi 44 | 45 | # vrouter_id is a byte 46 | vrouter_id=$(( $vrouter_id & 255 )) 47 | 48 | if [ $? != 0 ]; then 49 | vrouter_id="0" 50 | fi 51 | 52 | echo $vrouter_id 53 | } 54 | 55 | get_vrouter_password() { 56 | password="$VROUTER_KEEPALIVED_PASSWORD" 57 | 58 | echo $password 59 | } 60 | 61 | get_check_script() { 62 | script="$VROUTER_KEEPALIVED_CHECK_SCRIPT" 63 | 64 | echo $script 65 | } 66 | 67 | get_iface_var() { 68 | var_name="$1_$2" 69 | var=$(eval "echo \"\${$var_name}\"") 70 | 71 | echo $var 72 | } 73 | 74 | gen_group() { 75 | cat < /etc/keepalived/keepalived.conf 197 | 198 | if [ "$2" == "reconfigure" ]; then 199 | reload_service 200 | else 201 | rc-update add keepalived boot 202 | fi 203 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-16-gen-env: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | ENV_FILE=/var/run/one-context/one_env 25 | MOUNT_DIR="${MOUNT_DIR:-/mnt}" 26 | TOKEN_FILE="${MOUNT_DIR}/token.txt" 27 | 28 | if [ -n "$ONEGATE_TOKEN" ]; then 29 | TOKENTXT="$ONEGATE_TOKEN" 30 | elif [ -f "$TOKEN_FILE" ]; then 31 | TOKENTXT=$(cat "$TOKEN_FILE") 32 | fi 33 | 34 | umask 0377 35 | echo "export TOKENTXT=\"$TOKENTXT\"" > "$ENV_FILE" 36 | echo "export VMID=\"$VMID\"" >> "$ENV_FILE" 37 | echo "export ONEGATE_ENDPOINT=\"$ONEGATE_ENDPOINT\"" >> "$ENV_FILE" 38 | 39 | function export_rc_vars 40 | { 41 | if [ -n "$1" ] && [ -f "$1" ] ; then 42 | ONE_VARS=$(grep -E -e '^[a-zA-Z\-\_0-9]*=' "$1" | sed 's/=.*$//') 43 | 44 | # shellcheck disable=SC1090 45 | . "$1" 46 | 47 | for v in $ONE_VARS; do 48 | echo "export $v=\"${!v}\"" >> "$ENV_FILE" 49 | done 50 | fi 51 | } 52 | 53 | export_rc_vars "${CONTEXT_FILE}" 54 | 55 | chown "root:$(id -gn root)" "$ENV_FILE" 56 | chmod 0400 "$ENV_FILE" 57 | 58 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-20-set-username-password: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | # defaults 25 | USERNAME=${USERNAME:-root} 26 | USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}} 27 | USERNAME_SUDO=$(echo "${USERNAME_SUDO}" | tr '[:lower:]' '[:upper:]') 28 | USERNAME_PASSWORD_RESET=${USERNAME_PASSWORD_RESET:-NO} 29 | USERNAME_PASSWORD_RESET=$(echo "${USERNAME_PASSWORD_RESET}" | tr '[:lower:]' '[:upper:]') 30 | 31 | _kernel="$(uname -s)" 32 | case "${_kernel}" in 33 | 'FreeBSD') 34 | USERNAME_SHELL=${USERNAME_SHELL:-/usr/local/bin/bash} 35 | _sudoers_file='/usr/local/etc/sudoers.d/one-context' 36 | ;; 37 | *) 38 | USERNAME_SHELL=${USERNAME_SHELL:-/bin/bash} 39 | _sudoers_file='/etc/sudoers.d/one-context' 40 | ;; 41 | esac 42 | 43 | # create user if missing 44 | if ! getent passwd "${USERNAME}" > /dev/null 2>&1; then 45 | if [ "${_kernel}" = 'FreeBSD' ]; then 46 | pw user add "${USERNAME}" -m -s "${USERNAME_SHELL}" -w no 47 | else 48 | useradd -m "${USERNAME}" -p '*' -s "${USERNAME_SHELL}" 49 | fi 50 | fi 51 | 52 | # enable sudo 53 | if [ "${USERNAME_SUDO}" == "YES" ] && [ "${USERNAME}" != "root" ]; then 54 | echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >"${_sudoers_file}" 55 | chmod 0440 "${_sudoers_file}" 56 | elif [ -f "${_sudoers_file}" ]; then 57 | unlink "${_sudoers_file}" 58 | fi 59 | 60 | # set password 61 | if [ -n "${CRYPTED_PASSWORD_BASE64}" ]; then 62 | CRYPTED_PASSWORD=$(echo $CRYPTED_PASSWORD_BASE64 | base64 -d) 63 | if [ "${_kernel}" = 'FreeBSD' ]; then 64 | echo "${CRYPTED_PASSWORD}" | pw user mod "${USERNAME}" -H 0 65 | else 66 | usermod -p "${CRYPTED_PASSWORD}" "${USERNAME}" 67 | fi 68 | elif [ -n "${PASSWORD_BASE64}" ]; then 69 | PASSWORD=$(echo $PASSWORD_BASE64 | base64 -d) 70 | if [ "${_kernel}" = 'FreeBSD' ]; then 71 | echo $PASSWORD | pw user mod "${USERNAME}" -h 0 72 | else 73 | chpasswd <<< "${USERNAME}:${PASSWORD}" 74 | fi 75 | 76 | if [ $? -ne 0 ]; then 77 | passwd "${USERNAME}" <> $AUTH_FILE 48 | fi 49 | done 50 | } 51 | 52 | [ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0 53 | 54 | mkdir -m0700 -p $AUTH_DIR 55 | 56 | [ ! -f $AUTH_FILE ] && touch $AUTH_FILE 57 | 58 | if [ -n "$SSH_PUBLIC_KEY" ]; then 59 | echo "$SSH_PUBLIC_KEY" | add_keys 60 | fi 61 | 62 | if [ -n "$EC2_PUBLIC_KEY" ]; then 63 | echo "$EC2_PUBLIC_KEY" | add_keys 64 | fi 65 | 66 | chown "${USERNAME}": ${AUTH_DIR} ${AUTH_FILE} 67 | chmod 600 $AUTH_FILE 68 | 69 | # restore SELinux contexts 70 | if which restorecon &>/dev/null; then 71 | restorecon -R -v "${AUTH_DIR}" 72 | fi 73 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-24-ssh_host_key##deb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then 25 | if ssh-keygen -A; then 26 | if type restorecon >/dev/null 2>&1; then 27 | restorecon -R -v /etc/ssh/ 28 | fi 29 | else 30 | DEBIAN_FRONTEND=noninteractive dpkg-reconfigure openssh-server 31 | fi 32 | fi 33 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-30-console##one: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | # Linux 25 | for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do 26 | TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}" 27 | done 28 | -------------------------------------------------------------------------------- /src/etc/one-context.d/loc-35-securetty: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # THIS IS A CONTEXTUALIZATION GUARD 20 | if [ "$1" != 'local' ] ; then 21 | exit 0 22 | fi 23 | 24 | _pam_file="/etc/pam.d/login" 25 | if [ ! -f "${_pam_file}" ]; then 26 | exit 0 27 | fi 28 | 29 | _kernel="$(uname -s)" 30 | if [ "${_kernel}" = 'FreeBSD' ]; then 31 | SED_I="sed -i ''" 32 | else 33 | SED_I="sed -i''" 34 | fi 35 | 36 | ### Defaults 37 | 38 | # By default, disable pam_securetty in the containers. 39 | # For virtualized machines, have the securetty enabled. 40 | if grep -qia 'container=' /proc/1/environ 2>/dev/null; then 41 | SECURETTY=${SECURETTY:-NO} 42 | fi 43 | 44 | SECURETTY=${SECURETTY:-YES} 45 | SECURETTY=${SECURETTY^^} 46 | 47 | ### 48 | 49 | _note='# one-contextd' 50 | 51 | if [ "${SECURETTY}" = 'YES' ]; then 52 | if grep -qE "^#.*pam_securetty.*${_note}" "${_pam_file}"; then 53 | eval "${SED_I} -e 's/^#\([^#]*\)${_note}.*$/\1/' -e 's/[[:space:]]*$//' \"${_pam_file}\"" 54 | fi 55 | 56 | elif [ "${SECURETTY}" = 'NO' ]; then 57 | if grep -qE '^[^#]*pam_securetty' "${_pam_file}"; then 58 | eval "${SED_I} -e 's/^\([^#]*pam_securetty.*\)$/#\1 ${_note}/' \"${_pam_file}\"" 59 | fi 60 | fi 61 | -------------------------------------------------------------------------------- /src/etc/one-context.d/net-11-fix-loopback##deb.one: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # Checks if the loopback interface is not configured and adds 127.0.0.1. 20 | # This fixes a problem with old Ubuntu 14.04 distros that leave loopback 21 | # IP unconfigured when restarting network. This does not happen with 22 | # Ubuntu 14.04.4 23 | 24 | ip_info="$(ip -o -4 address show lo)" 25 | 26 | if [ -z "$ip_info" ]; then 27 | ip addr add 127.0.0.1/8 dev lo 28 | ip link set lo up 29 | fi 30 | -------------------------------------------------------------------------------- /src/etc/one-context.d/net-15-hostname: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | _kernel="$(uname -s)" 20 | if [ "${_kernel}" = 'FreeBSD' ]; then 21 | SED_I="sed -i ''" 22 | else 23 | SED_I="sed -i''" 24 | fi 25 | 26 | # Detects suitable running syslog service and restarts it 27 | # to propagate the changed hostname into the logs 28 | # (otherwise old or default value remains until reboot) 29 | function restart_syslog() { 30 | for _name in syslog syslogd rsyslog; do 31 | if LANG=C systemctl is-active "${_name}" >/dev/null 2>&1; then 32 | systemctl restart "${_name}" && return 33 | elif service "${_name}" status >/dev/null 2>&1; then 34 | service "${_name}" restart && return 35 | fi 36 | done 37 | } 38 | 39 | function set_hostname() { 40 | local _hostname=$1 41 | 42 | # remember currently set hostname to detect a change 43 | local _old_hostname 44 | _old_hostname=$(hostname) 45 | 46 | if [ -d /run/systemd/system/ ] && hostnamectl status >/dev/null 2>/dev/null; then 47 | hostnamectl set-hostname --static "${_hostname}" 48 | else 49 | if [ -f /etc/sysconfig/network ]; then 50 | eval "${SED_I} '/^HOSTNAME=.*$/d' /etc/sysconfig/network" 51 | echo "HOSTNAME=${_hostname}" >>/etc/sysconfig/network 52 | elif [ "${_kernel}" = 'FreeBSD' ]; then 53 | sysrc hostname="${_hostname}" 54 | else 55 | echo "${_hostname}" >/etc/hostname 56 | fi 57 | 58 | hostname "${_hostname}" 59 | fi 60 | 61 | # restart syslog if actual hostname changed 62 | if [ "${_old_hostname}" != "$(hostname)" ]; then 63 | restart_syslog 64 | fi 65 | } 66 | 67 | function set_domainname() { 68 | local _domain=$1 69 | 70 | touch /etc/resolv.conf 71 | eval "${SED_I} -e '/^domain .*/d' /etc/resolv.conf" 72 | echo "domain ${_domain}" >>/etc/resolv.conf 73 | } 74 | 75 | function get_first_ip() { 76 | local ip 77 | 78 | ip=${ip:-$(ip route get 1 2>/dev/null | grep 'src [0-9\.]\+' | head -1 | sed -e 's/^.*src \([0-9\.]*\).*$/\1/')} 79 | ip=${ip:-$(ip -4 address show scope global up 2>/dev/null | awk '/inet / { gsub(/\/[^\/]+$/, "", $2); print $2; exit}')} 80 | ip=${ip:-$(ifconfig 2>/dev/null | awk '/inet / { gsub(/\/[^\/]+$/, "", $2); print $2; exit}')} 81 | ip=${ip:-$(hostname -I 2>/dev/null | cut -d' ' -f1)} 82 | ip=${ip:-$(hostname -i 2>/dev/null)} 83 | 84 | echo "${ip}" 85 | } 86 | 87 | function get_dns_name() { 88 | text=$(LC_ALL=C host "$1" 2>/dev/null) 89 | [ $? = 0 ] || exit 0 90 | [[ $text == *"has no PTR record" ]] && exit 0 91 | name=$(echo "$text" | awk '/(has address|name pointer)/ {print $(NF)}' | sed 's/\.$//') 92 | echo $name 93 | } 94 | 95 | function update_hosts() { 96 | ip=$1 97 | name=$2 98 | hostname=$3 99 | 100 | if [ "x${hostname}" = "x${name}" ]; then 101 | hosts="${name}" 102 | else 103 | hosts="${name} ${hostname}" 104 | fi 105 | 106 | note='# one-contextd' 107 | entry="${ip} ${hosts} ${note}" 108 | 109 | # update our old entry 110 | if grep -qi "${note}" /etc/hosts; then 111 | eval "${SED_I} -e \"s/^.*${note}\$/${entry}/\" /etc/hosts" 112 | # update entry with same IP (but not localhost) 113 | elif grep -E "^${ip}[[:space:]]" /etc/hosts | grep -qv localhost; then 114 | eval "${SED_I} -e \"/localhost/! s/^${ip}[[:space:]].*\$/${entry}/\" /etc/hosts" 115 | # update entry with same name 116 | elif grep -qE "[[:space:]]${name}([[:space:]]|#|\$)" /etc/hosts; then 117 | eval "${SED_I} -re \"s/^.*[[:space:]]${name}([[:space:]#].*|$)/${entry}/\" /etc/hosts" 118 | # create new entry 119 | elif [ -s /etc/hosts ]; then 120 | # In FreeBSD, sed doesn't interpret \n. We put a real newline. 121 | eval "${SED_I} -e \"1s/^/${entry}\"$'\\\\\n/' /etc/hosts" 122 | else 123 | echo "${entry}" >>/etc/hosts 124 | fi 125 | } 126 | 127 | ##### 128 | 129 | first_ip=$(get_first_ip) 130 | 131 | if [ -n "$SET_HOSTNAME" ]; then 132 | name=$(echo "$SET_HOSTNAME" | \ 133 | sed -e 's/[^-a-zA-Z0-9\.]/-/g' -e 's/^-*//g' -e 's/-*$//g') 134 | 135 | elif [ -n "$DNS_HOSTNAME" ]; then 136 | name=$(get_dns_name "${first_ip}") 137 | 138 | elif [ "${EC2_HOSTNAME}" = 'YES' ]; then 139 | # try to quickly get hostname from the EC2 metadata server or 140 | # create hostname based on the first IPv4 (format: "ip-1-2-3-4") 141 | name=$(curl -sf -m 5 'http://169.254.169.254/latest/meta-data/local-hostname' 2>/dev/null) 142 | if [ -z "${name}" ]; then 143 | name="$(echo "${first_ip}" | grep -x '[0-9\.]\+' | tr . -)" 144 | if [ -n "${name}" ]; then 145 | name="ip-${name}" 146 | fi 147 | fi 148 | fi 149 | 150 | if [ -n "${name}" ]; then 151 | # split host and domain names 152 | hostname=${name%%.*} 153 | domain=${name#*.} 154 | 155 | [ "$domain" = "$hostname" ] && domain='' 156 | [ -n "${domain}" ] && set_domainname "${domain}" 157 | 158 | if [ "${_kernel}" = 'FreeBSD' ]; then 159 | set_hostname "${name}" 160 | else 161 | set_hostname "${hostname}" 162 | fi 163 | 164 | if [ -n "${DNS_HOSTNAME}" ]; then 165 | host_ip=$first_ip 166 | else 167 | name_ip=$(get_dns_name "${name}") 168 | 169 | # If selected hostname resolves on first IP, 170 | # use first IP for local hostname in /etc/hosts. 171 | # Otherwise use loopback IP. 172 | if [ "$first_ip" = "$name_ip" ]; then 173 | host_ip=$first_ip 174 | else 175 | host_ip='127.0.0.1' 176 | fi 177 | fi 178 | 179 | [ -n "${host_ip}" ] && update_hosts "${host_ip}" "${name}" "${hostname}" 180 | fi 181 | -------------------------------------------------------------------------------- /src/etc/one-context.d/net-97-start-script: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | set -e 20 | 21 | MOUNT_DIR=${MOUNT_DIR:-/mnt} 22 | TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX") 23 | START_SCRIPT_AVAILABLE=no 24 | 25 | TMP_FILE="${TMP_DIR}/one-start-script" 26 | 27 | cleanup() 28 | { 29 | rm -rf "${TMP_DIR}" 30 | } 31 | 32 | trap cleanup EXIT 33 | 34 | chmod 0700 "${TMP_DIR}" 35 | 36 | if [ -n "${START_SCRIPT_BASE64}" ]; then 37 | echo "${START_SCRIPT_BASE64}" | base64 -d > "${TMP_FILE}" 38 | START_SCRIPT_AVAILABLE=yes 39 | elif [ -n "${START_SCRIPT}" ]; then 40 | echo "${START_SCRIPT}" > "${TMP_FILE}" 41 | START_SCRIPT_AVAILABLE=yes 42 | fi 43 | 44 | if [ "${START_SCRIPT_AVAILABLE}" = "yes" ]; then 45 | cd "${MOUNT_DIR}" 46 | chmod +x "${TMP_FILE}" 47 | "${TMP_FILE}" 48 | fi 49 | -------------------------------------------------------------------------------- /src/etc/one-context.d/net-98-execute-scripts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | set -e 20 | 21 | MOUNT_DIR="${MOUNT_DIR:-/mnt}" 22 | TMP_DIR=$(mktemp -d "${TMP_DIR:-/var/lib/one-context/tmp}/one-context.XXXXXX") 23 | 24 | cleanup() 25 | { 26 | rm -rf "${TMP_DIR}" 27 | } 28 | 29 | trap cleanup EXIT 30 | 31 | chmod 0700 "${TMP_DIR}" 32 | 33 | if [ -z "${INIT_SCRIPTS}" ]; then 34 | if [ -f "${MOUNT_DIR}/init.sh" ]; then 35 | INIT_SCRIPTS=init.sh 36 | fi 37 | fi 38 | 39 | cd "${MOUNT_DIR}" 40 | 41 | _result=0 42 | for f in $INIT_SCRIPTS; do 43 | f=$(basename "$f") 44 | 45 | if [ -f "$f" ] ; then 46 | cp "${f}" "${TMP_DIR}/" 47 | chmod +x "${TMP_DIR}/${f}" 48 | "${TMP_DIR}/${f}" || _result=$? 49 | else 50 | echo "ERROR: Init script does not exist: ${f}" >&2 51 | _result=1 52 | fi 53 | done 54 | 55 | exit $_result 56 | -------------------------------------------------------------------------------- /src/etc/one-context.d/net-99-report-ready: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ENV_FILE=${ENV_FILE:-/var/run/one-context/one_env} 20 | RETRY_COUNT="${RETRY_COUNT:-3}" 21 | RETRY_WAIT_PERIOD="${RETRY_WAIT_PERIOD:-10}" 22 | 23 | if [ "$REPORT_READY" != "YES" ]; then 24 | exit 0 25 | fi 26 | 27 | # $TOKENTXT is available only through the env. file 28 | if [ -f "${ENV_FILE}" ]; then 29 | # shellcheck disable=SC1090 30 | . "${ENV_FILE}" 31 | fi 32 | 33 | ### 34 | 35 | if command -v curl ; then 36 | _command=curl 37 | elif command -v wget && ! wget --help 2>&1 | grep -q BusyBox; then 38 | _command=wget 39 | elif command -v onegate ; then 40 | _command=onegate 41 | else 42 | echo "ERROR: No way to signal READY=YES (no usable binary)" >&2 43 | exit 1 44 | fi > /dev/null # this will not drop the error message which goes to stderr 45 | 46 | while [ "$RETRY_COUNT" -gt 0 ] ; do 47 | case "$_command" in 48 | curl) 49 | curl -X "PUT" "${ONEGATE_ENDPOINT}/vm" \ 50 | --header "X-ONEGATE-TOKEN: $TOKENTXT" \ 51 | --header "X-ONEGATE-VMID: $VMID" \ 52 | --max-time 10 \ 53 | --insecure \ 54 | -d "READY=YES" 55 | ;; 56 | wget) 57 | wget --method=PUT "${ONEGATE_ENDPOINT}/vm" \ 58 | --body-data="READY=YES" \ 59 | --header "X-ONEGATE-TOKEN: $TOKENTXT" \ 60 | --header "X-ONEGATE-VMID: $VMID" \ 61 | --timeout=10 \ 62 | --no-check-certificate 63 | ;; 64 | onegate) 65 | if command -v timeout >/dev/null; then 66 | timeout 10 onegate vm update --data "READY=YES" 67 | else 68 | onegate vm update --data "READY=YES" 69 | fi 70 | ;; 71 | esac 72 | 73 | # shellcheck disable=SC2181 74 | if [ "$?" = "0" ]; then 75 | exit 0 76 | fi 77 | 78 | RETRY_COUNT=$(( RETRY_COUNT - 1 )) 79 | sleep "${RETRY_WAIT_PERIOD}" 80 | done 81 | 82 | exit 1 83 | -------------------------------------------------------------------------------- /src/etc/periodic/1min/one-context-reconfigure##apk: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Periodically run one-context-reconfigure on VMware 3 | if [ "$(virt-what 2>/dev/null)" = 'vmware' ]; then 4 | service one-context-reconfigure restart >/dev/null 2>&1 5 | fi 6 | -------------------------------------------------------------------------------- /src/etc/rc.d/one-context##bsd_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # PROVIDE: one-context 21 | # REQUIRE: LOGIN NETWORKING one-context-local 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | 26 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 27 | 28 | name="one_context" 29 | desc="OpenNebula contextualization" 30 | rcvar="${name}_enable" 31 | start_precmd="${name}_prestart" 32 | stop_cmd="${name}_stop" 33 | command="/usr/sbin/one-contextd" 34 | command_args="network" 35 | 36 | one_context_get_pids() 37 | { 38 | # get main process PID and direct children processes 39 | for _pid in $(pgrep -f "${command} ${command_args}$"); do 40 | echo "${_pid}" 41 | pgrep -P "${_pid}" 42 | done 43 | } 44 | 45 | one_context_prestart() 46 | { 47 | if [ -f /var/run/one-context/context.sh.network ]; then 48 | warn "Service started once already." 49 | return 1 50 | fi 51 | } 52 | 53 | one_context_stop() 54 | { 55 | echo -n "Stopping ${name}" 56 | 57 | _pids=$(one_context_get_pids) 58 | for _pid in $_pids; do 59 | kill -- "${_pid}" >/dev/null 2>&1 60 | done 61 | 62 | echo '.' 63 | } 64 | 65 | load_rc_config $name 66 | : ${one_context_enable:="yes"} 67 | run_rc_command "$1" 68 | -------------------------------------------------------------------------------- /src/etc/rc.d/one-context-force##bsd_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # PROVIDE: one-context-force 21 | # REQUIRE: one-context-local one-context 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | 26 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 27 | 28 | name="one_context_force" 29 | desc="OpenNebula forced reconfiguration" 30 | rcvar="${name}_enable" 31 | start_precmd="${name}_prestart" 32 | stop_cmd="${name}_stop" 33 | status_cmd="${name}_status" 34 | command="/usr/sbin/one-context-run" 35 | command_args="force" 36 | 37 | one_context_get_pids() 38 | { 39 | # get main process PID and direct children processes 40 | for _pid in $(pgrep -f "${command} ${command_args}$"); do 41 | echo "${_pid}" 42 | pgrep -P "${_pid}" 43 | done 44 | } 45 | 46 | one_context_force_status() 47 | { 48 | _pids=$(one_context_get_pids) 49 | 50 | if [ -z "${_pids}" ]; then 51 | echo "${name} is not running." 52 | return 1 53 | else 54 | echo "${name} is running as pids ${_pids}." 55 | return 0 56 | fi 57 | } 58 | 59 | one_context_force_prestart() 60 | { 61 | if ! [ -f /var/run/one-context/context.sh.local ]; then 62 | warn "Service one-context-local must run first." 63 | return 1 64 | fi 65 | 66 | if ! [ -f /var/run/one-context/context.sh.network ]; then 67 | warn "Service one-context must run first." 68 | return 1 69 | fi 70 | 71 | _pids=$(one_context_get_pids) 72 | if [ -n "${_pids}" ]; then 73 | warn "${name} already running? (pids=${_pids})" 74 | return 1 75 | fi 76 | 77 | return 0 78 | } 79 | 80 | one_context_force_stop() 81 | { 82 | echo -n "Stopping ${name}" 83 | 84 | _pids=$(one_context_get_pids) 85 | for _pid in $_pids; do 86 | kill -- "${_pid}" >/dev/null 2>&1 87 | done 88 | 89 | echo '.' 90 | } 91 | 92 | # run without any delay 93 | export TIMEOUT=0 94 | 95 | load_rc_config $name 96 | : ${one_context_force_enable:="no"} 97 | run_rc_command "$1" 98 | -------------------------------------------------------------------------------- /src/etc/rc.d/one-context-local##bsd_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # PROVIDE: one-context-local 21 | # REQUIRE: FILESYSTEMS ldconfig 22 | # BEFORE: NETWORKING hostname 23 | ### END INIT INFO 24 | 25 | . /etc/rc.subr 26 | 27 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 28 | 29 | name="one_context_local" 30 | desc="OpenNebula pre-networking contextualization" 31 | rcvar="${name}_enable" 32 | start_precmd="${name}_prestart" 33 | stop_cmd="${name}_stop" 34 | command="/usr/sbin/one-contextd" 35 | command_args="local" 36 | 37 | one_context_get_pids() 38 | { 39 | # get main process PID and direct children processes 40 | for _pid in $(pgrep -f "${command} ${command_args}$"); do 41 | echo "${_pid}" 42 | pgrep -P "${_pid}" 43 | done 44 | } 45 | 46 | one_context_local_prestart() 47 | { 48 | if [ -f /var/run/one-context/context.sh.local ]; then 49 | warn "Service started once already." 50 | return 1 51 | fi 52 | } 53 | 54 | one_context_local_stop() 55 | { 56 | echo -n "Stopping ${name}" 57 | 58 | _pids=$(one_context_get_pids) 59 | for _pid in $_pids; do 60 | kill -- "${_pid}" >/dev/null 2>&1 61 | done 62 | 63 | echo '.' 64 | } 65 | 66 | load_rc_config $name 67 | : ${one_context_local_enable:="yes"} 68 | run_rc_command "$1" 69 | -------------------------------------------------------------------------------- /src/etc/rc.d/one-context-reconfigure##bsd_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # PROVIDE: one-context-reconfigure 21 | # REQUIRE: one-context-local one-context 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | 26 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 27 | 28 | name="one_context_reconfigure" 29 | desc="OpenNebula reconfiguration" 30 | rcvar="${name}_enable" 31 | start_precmd="${name}_prestart" 32 | stop_cmd="${name}_stop" 33 | status_cmd="${name}_status" 34 | command="/usr/sbin/one-context-run" 35 | 36 | one_context_get_pids() 37 | { 38 | # get main process PID and direct children processes 39 | for _pid in $(pgrep -f "${command}$"); do 40 | echo "${_pid}" 41 | pgrep -P "${_pid}" 42 | done 43 | } 44 | 45 | one_context_reconfigure_status() 46 | { 47 | _pids=$(one_context_get_pids) 48 | 49 | if [ -z "${_pids}" ]; then 50 | echo "${name} is not running." 51 | return 1 52 | else 53 | echo "${name} is running as pids ${_pids}." 54 | return 0 55 | fi 56 | } 57 | 58 | one_context_reconfigure_prestart() 59 | { 60 | if ! [ -f /var/run/one-context/context.sh.local ]; then 61 | warn "Service one-context-local must run first." 62 | return 1 63 | fi 64 | 65 | if ! [ -f /var/run/one-context/context.sh.network ]; then 66 | warn "Service one-context must run first." 67 | return 1 68 | fi 69 | 70 | # immediate reconfiguration terminates delayed reconfiguration 71 | service one-context-reconfigure-delayed onestop >/dev/null 2>&1 72 | 73 | _pids=$(one_context_get_pids) 74 | if [ -n "${_pids}" ]; then 75 | warn "${name} already running? (pids=${_pids})" 76 | return 1 77 | fi 78 | 79 | return 0 80 | } 81 | 82 | one_context_reconfigure_stop() 83 | { 84 | echo -n "Stopping ${name}" 85 | 86 | _pids=$(one_context_get_pids) 87 | for _pid in $_pids; do 88 | kill -- "${_pid}" >/dev/null 2>&1 89 | done 90 | 91 | echo '.' 92 | } 93 | 94 | # run without any delay 95 | export TIMEOUT=0 96 | 97 | load_rc_config $name 98 | : ${one_context_reconfigure_enable:="no"} 99 | run_rc_command "$1" 100 | -------------------------------------------------------------------------------- /src/etc/rc.d/one-context-reconfigure-delayed##bsd_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # PROVIDE: one-context-reconfigure-delayed 21 | # REQUIRE: one-context-local one-context 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | 26 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 27 | 28 | name="one_context_reconfigure_delayed" 29 | desc="OpenNebula delayed reconfiguration" 30 | rcvar="${name}_enable" 31 | start_precmd="${name}_prestart" 32 | stop_cmd="${name}_stop" 33 | status_cmd="${name}_status" 34 | command="/usr/sbin/one-context-run" 35 | 36 | one_context_get_pids() 37 | { 38 | # get main process PID and direct children processes 39 | for _pid in $(pgrep -f "${command}$"); do 40 | echo "${_pid}" 41 | pgrep -P "${_pid}" 42 | done 43 | } 44 | 45 | one_context_reconfigure_delayed_status() 46 | { 47 | _pids=$(one_context_get_pids) 48 | 49 | if [ -z "${_pids}" ]; then 50 | echo "${name} is not running." 51 | return 1 52 | else 53 | echo "${name} is running as pids ${_pids}." 54 | return 0 55 | fi 56 | } 57 | 58 | one_context_reconfigure_delayed_prestart() 59 | { 60 | if ! [ -f /var/run/one-context/context.sh.local ]; then 61 | warn "Service one-context-local must run first." 62 | return 1 63 | fi 64 | 65 | if ! [ -f /var/run/one-context/context.sh.network ]; then 66 | warn "Service one-context must run first." 67 | return 1 68 | fi 69 | 70 | _pids=$(one_context_get_pids) 71 | if [ -n "${_pids}" ]; then 72 | warn "${name} already running? (pids=${_pids})" 73 | return 1 74 | fi 75 | 76 | return 0 77 | } 78 | 79 | one_context_reconfigure_delayed_stop() 80 | { 81 | echo -n "Stopping ${name}" 82 | 83 | _pids=$(one_context_get_pids) 84 | for _pid in $_pids; do 85 | kill -- "${_pid}" >/dev/null 2>&1 86 | done 87 | 88 | echo '.' 89 | } 90 | 91 | load_rc_config $name 92 | : ${one_context_reconfigure_delayed_enable:="no"} 93 | run_rc_command "$1" 94 | -------------------------------------------------------------------------------- /src/etc/systemd/system/acpid.path.d/one-context.conf##deb.systemd: -------------------------------------------------------------------------------- 1 | [Unit] 2 | # https://github.com/OpenNebula/one/issues/5504 3 | ConditionVirtualization=!container 4 | -------------------------------------------------------------------------------- /src/etc/udev/rules.d/75-cd-aliases-generator.rules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNebula/addon-context-linux/ed607dc164da0981c31ce8855064a9198634558e/src/etc/udev/rules.d/75-cd-aliases-generator.rules -------------------------------------------------------------------------------- /src/etc/udev/rules.d/75-persistent-net-generator.rules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNebula/addon-context-linux/ed607dc164da0981c31ce8855064a9198634558e/src/etc/udev/rules.d/75-persistent-net-generator.rules -------------------------------------------------------------------------------- /src/lib/udev/rules.d/65-context.rules##apk.one: -------------------------------------------------------------------------------- 1 | # NIC detach workaround for recontextualization on OpenNebula < 5.10.3 2 | # https://github.com/OpenNebula/one/issues/4130 3 | # https://github.com/OpenNebula/one/issues/4194 4 | SUBSYSTEM=="net", ACTION=="remove", \ 5 | ENV{ID_BUS}=="?*", \ 6 | RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" 7 | 8 | # On NIC hotplug the delayed reconfiguration is triggered. 9 | SUBSYSTEM=="net", ACTION=="add", \ 10 | RUN+="/sbin/service one-context-reconfigure-delayed restart" 11 | 12 | SUBSYSTEM=="net", ACTION=="remove", \ 13 | RUN+="/sbin/service one-context-reconfigure-delayed restart" 14 | 15 | # Change of CONTEXT CD-ROM triggers immediate reconfiguration, 16 | # which stops any existing delayed reconfiguration. 17 | SUBSYSTEM=="block", ACTION=="change", \ 18 | ENV{ID_CDROM}=="1", \ 19 | ENV{ID_FS_TYPE}=="iso9660", \ 20 | ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ 21 | RUN+="/sbin/service one-context-reconfigure restart" 22 | 23 | # Handle disk resize 24 | SUBSYSTEM=="block", ACTION=="change", \ 25 | ENV{RESIZE}=="1", \ 26 | RUN+="/sbin/service one-context-force restart" 27 | 28 | SUBSYSTEM=="scsi", ACTION=="change", \ 29 | ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ 30 | RUN+="/sbin/service one-context-force restart" 31 | 32 | # Handle swap hot-attach 33 | SUBSYSTEM=="block", ACTION=="add", \ 34 | ENV{ID_FS_TYPE}=="swap", \ 35 | ENV{DM_ACTIVATION}!="1", \ 36 | RUN+="/sbin/service one-context-force restart" 37 | -------------------------------------------------------------------------------- /src/lib/udev/rules.d/65-context.rules##deb.one: -------------------------------------------------------------------------------- 1 | # NIC detach workaround for recontextualization on OpenNebula < 5.10.3 2 | # https://github.com/OpenNebula/one/issues/4130 3 | # https://github.com/OpenNebula/one/issues/4194 4 | SUBSYSTEM=="net", ACTION=="remove", \ 5 | ENV{ID_BUS}=="?*", \ 6 | RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" 7 | 8 | # On NIC hotplug the delayed reconfiguration is triggered. 9 | SUBSYSTEM=="net", ACTION=="add", \ 10 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'" 11 | 12 | SUBSYSTEM=="net", ACTION=="remove", \ 13 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'" 14 | 15 | # Change of CONTEXT CD-ROM triggers immediate reconfiguration, 16 | # which stops any existing delayed reconfiguration. 17 | SUBSYSTEM=="block", ACTION=="change", \ 18 | ENV{ID_CDROM}=="1", \ 19 | ENV{ID_FS_TYPE}=="iso9660", \ 20 | ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ 21 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure.service || /usr/sbin/service one-context-reconfigure start'" 22 | 23 | # Handle disk resize 24 | SUBSYSTEM=="block", ACTION=="change", \ 25 | ENV{RESIZE}=="1", \ 26 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'" 27 | 28 | SUBSYSTEM=="scsi", ACTION=="change", \ 29 | ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ 30 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'" 31 | 32 | # Handle swap hot-attach 33 | SUBSYSTEM=="block", ACTION=="add", \ 34 | ENV{ID_FS_TYPE}=="swap", \ 35 | ENV{DM_ACTIVATION}!="1", \ 36 | RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'" 37 | -------------------------------------------------------------------------------- /src/lib/udev/rules.d/65-context.rules##rpm.systemd.one: -------------------------------------------------------------------------------- 1 | # NIC detach workaround for recontextualization on OpenNebula < 5.10.3 2 | # https://github.com/OpenNebula/one/issues/4130 3 | # https://github.com/OpenNebula/one/issues/4194 4 | SUBSYSTEM=="net", ACTION=="remove", \ 5 | ENV{ID_BUS}=="?*", \ 6 | RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" 7 | 8 | # On NIC hotplug the delayed reconfiguration is triggered. 9 | SUBSYSTEM=="net", ACTION=="add", \ 10 | TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service" 11 | 12 | SUBSYSTEM=="net", ACTION=="remove", \ 13 | RUN+="/usr/bin/systemctl --no-block start one-context-reconfigure-delayed.service" 14 | 15 | # Change of CONTEXT CD-ROM triggers immediate reconfiguration, 16 | # which stops any existing delayed reconfiguration. 17 | SUBSYSTEM=="block", ACTION=="change", \ 18 | ENV{ID_CDROM}=="1", \ 19 | ENV{ID_FS_TYPE}=="iso9660", \ 20 | ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ 21 | RUN+="/usr/bin/systemctl --no-block start one-context-reconfigure.service" 22 | 23 | # Handle disk resize 24 | SUBSYSTEM=="block", ACTION=="change", \ 25 | ENV{RESIZE}=="1", \ 26 | RUN+="/usr/bin/systemctl --no-block start one-context-force.service" 27 | 28 | SUBSYSTEM=="scsi", ACTION=="change", \ 29 | ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ 30 | RUN+="/usr/bin/systemctl --no-block start one-context-force.service" 31 | 32 | # Handle swap hot-attach 33 | SUBSYSTEM=="block", ACTION=="add", \ 34 | ENV{ID_FS_TYPE}=="swap", \ 35 | ENV{DM_ACTIVATION}!="1", \ 36 | RUN+="/usr/bin/systemctl --no-block start one-context-force.service" 37 | -------------------------------------------------------------------------------- /src/lib/udev/rules.d/65-context.rules##rpm.sysv.one: -------------------------------------------------------------------------------- 1 | # NIC detach workaround for recontextualization on OpenNebula < 5.10.3 2 | # https://github.com/OpenNebula/one/issues/4130 3 | # https://github.com/OpenNebula/one/issues/4194 4 | SUBSYSTEM=="net", ACTION=="remove", \ 5 | ENV{INTERFACE}=="eth*", \ 6 | RUN+="/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network'" 7 | 8 | # On NIC hotplug the delayed reconfiguration is triggered. 9 | SUBSYSTEM=="net", ACTION=="add", \ 10 | RUN+="/sbin/service one-context-reconfigure-delayed start" 11 | 12 | SUBSYSTEM=="net", ACTION=="remove", \ 13 | RUN+="/sbin/service one-context-reconfigure-delayed start" 14 | 15 | # Handle disk resize 16 | SUBSYSTEM=="block", ACTION=="change", \ 17 | ENV{RESIZE}=="1", \ 18 | RUN+="/sbin/service one-context-force start" 19 | 20 | SUBSYSTEM=="scsi", ACTION=="change", \ 21 | ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ 22 | RUN+="/sbin/service one-context-force start" 23 | 24 | # Handle swap hot-attach 25 | SUBSYSTEM=="block", ACTION=="add", \ 26 | ENV{ID_FS_TYPE}=="swap", \ 27 | ENV{DM_ACTIVATION}!="1", \ 28 | RUN+="/sbin/service one-context-force start" 29 | -------------------------------------------------------------------------------- /src/usr/bin/onegate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ENV_FILE=/var/run/one-context/one_env 20 | 21 | if [ -f $ENV_FILE ]; then 22 | . $ENV_FILE 23 | fi 24 | 25 | export HOME=/root 26 | 27 | DIR=$(dirname $(readlink -f $0)) 28 | 29 | ruby $DIR/onegate.rb "$@" 30 | 31 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-force.service##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula forced reconfiguration 3 | After=one-context.service 4 | Requisite=one-context.service 5 | ConditionPathExists=/var/run/one-context/context.sh.local 6 | ConditionPathExists=/var/run/one-context/context.sh.network 7 | StartLimitInterval=0 8 | 9 | [Service] 10 | Type=oneshot 11 | Environment=TIMEOUT=0 12 | ExecStart=/usr/sbin/one-context-run force 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-local.service##deb.systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula pre-networking contextualization 3 | DefaultDependencies=no 4 | Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target 5 | Before=network-pre.target 6 | After=local-fs.target systemd-udev-settle.service syslog.target 7 | ConditionPathExists=!/var/run/one-context/context.sh.local 8 | 9 | [Service] 10 | Type=oneshot 11 | RemainAfterExit=yes 12 | ExecStart=/usr/sbin/one-contextd local 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-local.service##rpm.systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula pre-networking contextualization 3 | Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target 4 | Before=network-pre.target 5 | After=local-fs.target systemd-udev-settle.service syslog.target 6 | ConditionPathExists=!/var/run/one-context/context.sh.local 7 | 8 | [Service] 9 | Type=oneshot 10 | RemainAfterExit=yes 11 | ExecStart=/usr/sbin/one-contextd local 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-online.service##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula early-networking contextualization 3 | Requires=one-context-local.service 4 | After=one-context-local.service 5 | After=NetworkManager.service systemd-networkd.service 6 | Wants=network.target 7 | Before=network.target 8 | Before=NetworkManager-wait-online.service systemd-networkd-wait-online.service 9 | ConditionPathExists=!/var/run/one-context/context.sh.online 10 | 11 | [Service] 12 | Type=oneshot 13 | RemainAfterExit=yes 14 | ExecStart=/usr/sbin/one-contextd online 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-reconfigure-delayed.service##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula delayed reconfiguration 3 | After=one-context.service 4 | Requisite=one-context.service 5 | ConditionPathExists=/var/run/one-context/context.sh.network 6 | StartLimitInterval=0 7 | 8 | [Service] 9 | Type=forking 10 | ExecStart=/usr/sbin/one-context-run 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-reconfigure.service##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula reconfiguration 3 | After=one-context.service 4 | Requisite=one-context.service 5 | Conflicts=one-context-reconfigure-delayed.service 6 | ConditionPathExists=/var/run/one-context/context.sh.network 7 | StartLimitInterval=0 8 | 9 | [Service] 10 | Type=oneshot 11 | Environment=TIMEOUT=0 12 | ExecStart=/usr/sbin/one-context-run 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context-reconfigure.timer##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Periodic OpenNebula reconfiguration 3 | After=one-context.service 4 | ConditionVirtualization=vmware 5 | 6 | [Timer] 7 | OnCalendar=*-*-* *:*:0 8 | AccuracySec=1s 9 | 10 | [Install] 11 | WantedBy=timers.target 12 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context.service##arch.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Context script for open nebula 3 | # dbus.service can be dropped once on kdbus, and systemd-udevd.service can be 4 | # dropped once tuntap is moved to netlink 5 | After=systemd-udevd.service dbus.service network-pre.target systemd-sysusers.service systemd-sysctl.service 6 | Before=systemd-networkd.service 7 | Wants=network.target systemd-networkd.service 8 | 9 | # On kdbus systems we pull in the busname explicitly, because it 10 | # carries policy that allows the daemon to acquire its name. 11 | Wants=org.freedesktop.network1.busname systemd-networkd.service 12 | After=org.freedesktop.network1.busname 13 | 14 | [Service] 15 | Type=oneshot 16 | RemainAfterExit=yes 17 | ExecStart=/usr/sbin/one-contextd 18 | StandardOutput=syslog 19 | StandardError=syslog 20 | SyslogIdentifier=one-context 21 | RemainAfterExit=yes 22 | 23 | [Install] 24 | WantedBy=multi-user.target 25 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context.service##systemd.ec2: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula contextualization 3 | Requires=network.target 4 | After=multi-user.target 5 | ConditionPathExists=!/var/run/one-context/context.sh.local 6 | ConditionPathExists=!/var/run/one-context/context.sh.network 7 | 8 | [Service] 9 | Type=oneshot 10 | RemainAfterExit=yes 11 | ExecStart=/usr/sbin/one-contextd all 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /src/usr/lib/systemd/system/one-context.service##systemd.one: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OpenNebula contextualization 3 | Requires=one-context-local.service one-context-online.service 4 | After=multi-user.target one-context-local.service one-context-online.service 5 | Wants=network-online.target 6 | After=network-online.target 7 | ConditionPathExists=!/var/run/one-context/context.sh.network 8 | 9 | [Service] 10 | Type=oneshot 11 | RemainAfterExit=yes 12 | ExecStart=/usr/sbin/one-contextd network 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /src/usr/local/etc/rc.d/one-context-force.sh##pfsense_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # REQUIRE: one-context-local one-context 21 | # PROVIDE: one-context-force 22 | # Short-Description: OpenNebula forced reconfiguration 23 | ### END INIT INFO 24 | 25 | . /etc/rc.subr 26 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 27 | 28 | name="one_context_force" 29 | desc="OpenNebula forced reconfiguration" 30 | rcvar="${name}_enable" 31 | 32 | command="/usr/sbin/one-context-run" 33 | command_args="force" 34 | 35 | load_rc_config $name 36 | : ${one_context_force_enable:="yes"} 37 | run_rc_command "$1" 38 | 39 | -------------------------------------------------------------------------------- /src/usr/local/etc/rc.d/one-context-local.sh##pfsense_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # REQUIRE: FILESYSTEMS 21 | # PROVIDE: one-context-local 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 26 | 27 | name="one_context_local" 28 | desc="OpenNebula pre-networking contextualization" 29 | rcvar="${name}_enable" 30 | 31 | command="/usr/sbin/one-contextd" 32 | command_args="local" 33 | 34 | load_rc_config $name 35 | : ${one_context_local_enable:="yes"} 36 | run_rc_command "$1" 37 | 38 | -------------------------------------------------------------------------------- /src/usr/local/etc/rc.d/one-context-reconfigure-delayed.sh##pfsense_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # REQUIRE: one-context-local one-context 21 | # PROVIDE: one-context-reconfigure-delayed 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 26 | 27 | name="one_context_reconfigure_delayed" 28 | desc="OpenNebula delayed reconfiguration" 29 | rcvar="${name}_enable" 30 | 31 | command="/usr/sbin/one-context-run" 32 | 33 | load_rc_config $name 34 | : ${one_context_reconfigure_delayed_enable:="yes"} 35 | run_rc_command "$1" 36 | 37 | -------------------------------------------------------------------------------- /src/usr/local/etc/rc.d/one-context.sh##pfsense_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # REQUIRE: LOGIN netif 21 | # PROVIDE: one-context 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin 26 | 27 | name="one_context" 28 | desc="OpenNebula's context scripts" 29 | rcvar="${name}_enable" 30 | 31 | command="/usr/sbin/one-contextd" 32 | command_args="network" 33 | 34 | load_rc_config $name 35 | : ${one_context_enable:="yes"} 36 | run_rc_command "$1" 37 | -------------------------------------------------------------------------------- /src/usr/local/etc/rc.d/one-contextre-configure.sh##pfsense_rc.one: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | ### BEGIN INIT INFO 20 | # REQUIRE: one-context-local one-context 21 | # PROVIDE: one-context-reconfigure 22 | ### END INIT INFO 23 | 24 | . /etc/rc.subr 25 | 26 | name="one_context_reconfigure" 27 | desc="OpenNebula reconfiguration" 28 | rcvar="${name}_enable" 29 | 30 | command="/usr/sbin/one-context-run" 31 | 32 | load_rc_config $name 33 | : ${one_context_reconfigure_enable:="yes"} 34 | run_rc_command "$1" 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/usr/sbin/one-context-run##one: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # -------------------------------------------------------------------------- # 4 | # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may # 7 | # not use this file except in compliance with the License. You may obtain # 8 | # a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | #--------------------------------------------------------------------------- # 18 | 19 | # Set PATH 20 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin 21 | 22 | TIMEOUT=${TIMEOUT:-30} 23 | COMMAND=${1:-reconfigure} 24 | CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh} 25 | 26 | if [ -f ${CONTEXT_BASE}.local ] && [ -f ${CONTEXT_BASE}.network ]; then 27 | if [ ${TIMEOUT} -gt 0 ]; then 28 | ( 29 | set -e 30 | sleep "${TIMEOUT}" 31 | /usr/sbin/one-contextd all ${COMMAND} 32 | ) &>/dev/null & 33 | disown 34 | else 35 | /usr/sbin/one-contextd all ${COMMAND} 36 | fi 37 | else 38 | echo 'Contextualization must start first as a boot service' >&2 39 | exit 1 40 | fi 41 | -------------------------------------------------------------------------------- /src/usr/sbin/one-dual-dhclient##bsd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Public domain 4 | 5 | ### For FreeBSD only: 6 | # Modified dual-dhclient script from package net/dual-dhclient 7 | # which conditionally triggers only a specific DHCP client 8 | # if it's enabled in interface configuration. This script needs to 9 | # 1. have dhclient from package net/isc-dhcp44-client installed 10 | # 2. be explicitly configured in /etc/rc.conf via 11 | # dhclient_program="/usr/sbin/one-dual-dhclient" 12 | 13 | # trigger DHCPv4 client only if DHCP tag is in interface configuration 14 | if sysrc -f /etc/rc.conf.d/network -f /etc/rc.conf -n "ifconfig_$@" | grep -q -i DHCP; then 15 | /sbin/dhclient "$@" 16 | fi 17 | 18 | # trigger DHCPv6 client only if DHCP tag is in interface configuration 19 | if sysrc -f /etc/rc.conf.d/network -f /etc/rc.conf -n "ifconfig_$@_ipv6" | grep -q -i DHCP; then 20 | DHCLIENT6='/usr/local/sbin/dhclient' 21 | 22 | if ! [ -x "${DHCLIENT6}" ]; then 23 | echo "ERROR: Suitable DHCPv6 client ${DHCLIENT6} not found. Install net/isc-dhcp44-client!" >&2 24 | exit 1 25 | fi 26 | 27 | "${DHCLIENT6}" -6 -nw -cf /dev/null "$@" 28 | fi 29 | -------------------------------------------------------------------------------- /targets.sh: -------------------------------------------------------------------------------- 1 | case "${TARGET}" in 2 | 'pfsense') 3 | NAME=${NAME:-one-context} 4 | RELSUFFIX=${RELSUFFIX:-} 5 | TYPE=${TYPE:-freebsd} 6 | EXT=${EXT:-txz} 7 | TAGS=${TAGS:-bsd pfsense_rc one sysv} 8 | DEPENDS=${DEPENDS:-sudo bash curl base64} 9 | PROVIDES=${PROVIDES:-} 10 | REPLACES=${REPLACES:-addon-context} 11 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 12 | POSTIN=${POSTINST:-pkg/postinstall.freebsd} 13 | PREUN=${PREUN:-} 14 | POSTUN=${POSTUN:-} 15 | POSTUP=${POSTUP:-} 16 | ;; 17 | 18 | 19 | 'freebsd') 20 | NAME=${NAME:-one-context} 21 | RELSUFFIX=${RELSUFFIX:-} 22 | TYPE=${TYPE:-freebsd} 23 | EXT=${EXT:-txz} 24 | TAGS=${TAGS:-bsd bsd_rc one sysv crond} 25 | DEPENDS=${DEPENDS:-sudo bash curl base64 ruby open-vm-tools-nox11 gawk virt-what} 26 | PROVIDES=${PROVIDES:-} 27 | REPLACES=${REPLACES:-addon-context} 28 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 29 | POSTIN=${POSTINST:-pkg/postinstall} 30 | PREUN=${PREUN:-} 31 | POSTUN=${POSTUN:-} 32 | POSTUP=${POSTUP:-} 33 | ;; 34 | 35 | 36 | 'el6') 37 | NAME=${NAME:-one-context} 38 | RELSUFFIX=${RELSUFFIX:-.el6} 39 | TYPE=${TYPE:-rpm} 40 | TAGS=${TAGS:-linux rpm sysv one network-scripts crond} 41 | DEPENDS=${DEPENDS:-util-linux-ng bash curl bind-utils cloud-utils-growpart dracut-modules-growroot parted ruby rubygem-json sudo shadow-utils openssh-server open-vm-tools qemu-guest-agent gawk virt-what} 42 | PROVIDES=${PROVIDES:-} 43 | REPLACES=${REPLACES:-cloud-init} 44 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 45 | POSTIN=${POSTINST:-pkg/postinstall} 46 | PREUN=${PREUN:-pkg/preuninstall} 47 | POSTUN=${POSTUN:-pkg/postuninstall} 48 | POSTUP=${POSTUP:-pkg/postupgrade} 49 | ;; 50 | 51 | 'el7') 52 | NAME=${NAME:-one-context} 53 | RELSUFFIX=${RELSUFFIX:-.el7} 54 | TYPE=${TYPE:-rpm} 55 | TAGS=${TAGS:-linux rpm systemd one network-scripts} 56 | DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server qemu-guest-agent gawk virt-what} 57 | RECOMMENDS=${RECOMMENDS:-open-vm-tools} 58 | PROVIDES=${PROVIDES:-} 59 | REPLACES=${REPLACES:-cloud-init} 60 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 61 | POSTIN=${POSTINST:-pkg/postinstall} 62 | PREUN=${PREUN:-pkg/preuninstall} 63 | POSTUN=${POSTUN:-pkg/postuninstall} 64 | POSTUP=${POSTUP:-pkg/postupgrade} 65 | ;; 66 | 67 | 'el8') 68 | NAME=${NAME:-one-context} 69 | RELSUFFIX=${RELSUFFIX:-.el8} 70 | TYPE=${TYPE:-rpm} 71 | TAGS=${TAGS:-linux rpm systemd one network-scripts} 72 | DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server qemu-guest-agent network-scripts gawk virt-what} 73 | RECOMMENDS=${RECOMMENDS:-open-vm-tools} 74 | PROVIDES=${PROVIDES:-} 75 | REPLACES=${REPLACES:-cloud-init} 76 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 77 | POSTIN=${POSTINST:-pkg/postinstall} 78 | PREUN=${PREUN:-pkg/preuninstall} 79 | POSTUN=${POSTUN:-pkg/postuninstall} 80 | POSTUP=${POSTUP:-pkg/postupgrade} 81 | ;; 82 | 83 | 'el9') 84 | NAME=${NAME:-one-context} 85 | RELSUFFIX=${RELSUFFIX:-.el9} 86 | TYPE=${TYPE:-rpm} 87 | TAGS=${TAGS:-linux rpm systemd one} 88 | DEPENDS=${DEPENDS:-util-linux bash curl bind-utils cloud-utils-growpart parted ruby rubygem-json sudo shadow-utils openssh-server qemu-guest-agent gawk virt-what} 89 | RECOMMENDS=${RECOMMENDS:-open-vm-tools} 90 | PROVIDES=${PROVIDES:-} 91 | REPLACES=${REPLACES:-cloud-init} 92 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 93 | POSTIN=${POSTINST:-pkg/postinstall} 94 | PREUN=${PREUN:-pkg/preuninstall} 95 | POSTUN=${POSTUN:-pkg/postuninstall} 96 | POSTUP=${POSTUP:-pkg/postupgrade} 97 | ;; 98 | 99 | 'alt') 100 | NAME=${NAME:-one-context} 101 | RELSUFFIX=${RELSUFFIX:-alt} 102 | TYPE=${TYPE:-rpm} 103 | TAGS=${TAGS:-linux rpm systemd one networkd} 104 | DEPENDS=${DEPENDS:-bind-utils btrfs-progs cloud-utils-growpart curl e2fsprogs iproute2 openssl parted passwd qemu-guest-agent open-vm-tools ruby-json-pure sudo systemd-services wget which xfsprogs gawk virt-what} 105 | PROVIDES=${PROVIDES:-} 106 | REPLACES=${REPLACES:-cloud-init} 107 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 108 | POSTIN=${POSTINST:-pkg/postinstall} 109 | PREUN=${PREUN:-pkg/preuninstall} 110 | POSTUN=${POSTUN:-pkg/postuninstall} 111 | POSTUP=${POSTUP:-pkg/postupgrade} 112 | ;; 113 | 114 | 115 | 'suse') 116 | NAME=${NAME:-one-context} 117 | RELSUFFIX=${RELSUFFIX:-.suse} 118 | TYPE=${TYPE:-rpm} 119 | TAGS=${TAGS:-linux rpm systemd one network-scripts} 120 | DEPENDS=${DEPENDS:-util-linux bash curl bind-utils growpart parted parted ruby sudo shadow openssh open-vm-tools qemu-guest-agent gawk virt-what} # rubygem-json} 121 | PROVIDES=${PROVIDES:-} 122 | REPLACES=${REPLACES:-cloud-init cloud-init-config-suse} 123 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 124 | POSTIN=${POSTINST:-pkg/postinstall} 125 | PREUN=${PREUN:-pkg/preuninstall} 126 | POSTUN=${POSTUN:-pkg/postuninstall} 127 | POSTUP=${POSTUP:-pkg/postupgrade} 128 | ;; 129 | 130 | 'deb') 131 | NAME=${NAME:-one-context} 132 | RELSUFFIX=${RELSUFFIX:-} 133 | TYPE=${TYPE:-deb} 134 | TAGS=${TAGS:-linux deb sysv systemd upstart one} 135 | DEPENDS=${DEPENDS:-util-linux bash curl bind9-host cloud-utils parted ruby ifupdown|ifupdown2 acpid|systemd sudo passwd dbus openssh-server open-vm-tools qemu-guest-agent gawk virt-what} 136 | PROVIDES=${PROVIDES:-} 137 | REPLACES=${REPLACES:-cloud-init} 138 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 139 | POSTIN=${POSTINST:-pkg/postinstall} 140 | PREUN=${PREUN:-pkg/preuninstall} 141 | POSTUN=${POSTUN:-pkg/postuninstall} 142 | POSTUP=${POSTUP:-pkg/postupgrade} 143 | ;; 144 | 145 | 'alpine') 146 | NAME=${NAME:-one-context} 147 | RELSUFFIX=${RELSUFFIX:-} 148 | TYPE=${TYPE:-apk} 149 | TAGS=${TAGS:-linux apk one} 150 | DEPENDS=${DEPENDS:-util-linux bash curl udev sfdisk parted e2fsprogs-extra sudo shadow ruby ruby-json bind-tools openssh open-vm-tools qemu-guest-agent gawk virt-what} 151 | PROVIDES=${PROVIDES:-} 152 | REPLACES=${REPLACES:-} #not respected 153 | CONFLICTS=${CONFLICTS:-one-context-ec2} 154 | POSTIN=${POSTINST:-pkg/postinstall} 155 | PREUN=${PREUN:-pkg/preuninstall} 156 | POSTUN=${POSTUN:-pkg/postuninstall} 157 | POSTUP=${POSTUP:-pkg/postupgrade} 158 | ;; 159 | 160 | 'iso') 161 | NAME=${NAME:-one-context-linux} 162 | TYPE=${TYPE:-iso} 163 | ;; 164 | 165 | 'arch') 166 | NAME=${NAME:-one-context} 167 | RELSUFFIX=${RELSUFFIX:-} 168 | TYPE=${TYPE:-pacman} 169 | EXT=${EXT:-pkg.tar.xz} 170 | TAGS=${TAGS:-linux arch systemd one networkd} 171 | # mkinitcpio-growrootfs ruby-json 172 | DEPENDS=${DEPENDS:-filesystem util-linux bash curl bind-tools ruby sudo shadow open-vm-tools qemu-guest-agent gawk virt-what} 173 | PROVIDES=${PROVIDES:-} 174 | REPLACES=${REPLACES:-cloud-init} 175 | CONFLICTS=${CONFLICTS:-${REPLACES} one-context-ec2} 176 | POSTIN=${POSTINST:-pkg/postinstall} 177 | PREUN=${PREUN:-pkg/preuninstall} 178 | POSTUN=${POSTUN:-pkg/postuninstall} 179 | POSTUP=${POSTUP:-pkg/postupgrade} 180 | echo 'ArchLinux target is currently not maintained' 181 | exit 1 182 | ;; 183 | 184 | *) 185 | echo "Invalid target ${TARGET}" 186 | exit 1 187 | esac 188 | --------------------------------------------------------------------------------