Move init scripts and installation of them in tree

glean is not complete without the simple-init script and init scripts.
Move them here. Also, rename them to glean.

Change-Id: I2ed25ce434023bfc8b6a88a08c0c06c1cef63982
This commit is contained in:
Monty Taylor 2015-06-27 12:49:23 -04:00
parent ff66735e38
commit db1afd6420
8 changed files with 167 additions and 0 deletions

0
glean/init/__init__.py Normal file
View File

View File

@ -0,0 +1 @@
SUBSYSTEM=="net", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="glean@$name.service"

15
glean/init/glean.conf Normal file
View File

@ -0,0 +1,15 @@
# Call a script to generate a /etc/network/interfaces file to DHCP all available interfaces
# Then remove this config file so the script is never run again
description "Run glean to configure network interfaces"
# console output connects stdout/stderr to the console log. This is important
# for debuggability of cloud images that wind up not booting
console output
start on starting network-interface
instance $INTERFACE
task
exec /usr/local/bin/glean.sh $INTERFACE

31
glean/init/glean.init Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: glean
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop: 0 6
# X-Start-Before: networking
# Short-Description: Autodetect network interfaces
# Description: Autodetect network interfaces during boot and configure them for DHCP
### END INIT INFO
NAME=glean
INIT_NAME=/etc/init.d/${NAME}
SCRIPT_NAME=/usr/local/bin/${NAME}.sh
[ -x $SCRIPT_NAME ] || exit 0
case "$1" in
start)
$SCRIPT_NAME
;;
stop)
;;
*)
echo "Usage: $INIT_NAME {start|stop}"
exit 1
;;
esac
exit 0

53
glean/init/glean.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
# dib-lint: disable=dibdebugtrace
set -eu
set -o pipefail
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
INTERFACE=${1:-} #optional, if not specified configure all available interfaces
function config_exists() {
local interface=$1
if [ "$CONF_TYPE" == "netscripts" ]; then
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$interface" ]; then
return 0
fi
else
ifquery $interface >/dev/null 2>&1 && return 0 || return 1
fi
return 1
}
# Test to see if config-drive exists. If not, skip and assume DHCP networking
# will work becasue sanity
if blkid -t LABEL="config-2" ; then
# Mount config drive
mkdir -p /mnt/config
mount -o mode=0700 $(blkid -t LABEL="config-2" | cut -d ':' -f 1) /mnt/config || true
glean --ssh --skip-network --hostname
fi
if [ -f /usr/bin/dpkg ] ; then
test -f /etc/ssh/ssh_host_rsa_key || dpkg-reconfigure openssh-server
fi
if [ -n "$INTERFACE" ]; then
glean --interface $INTERFACE
else
glean
fi

15
glean/init/glean@.service Normal file
View File

@ -0,0 +1,15 @@
[Unit]
Description=DHCP interface %I
After=network.service network.target
ConditionPathExists=!/etc/sysconfig/network-scripts/ifcfg-%I
[Service]
Type=oneshot
User=root
ExecStartPre=/usr/local/bin/glean.sh %I
ExecStart=/sbin/ifup %I
RemainAfterExit=true
[Install]
WantedBy=multi-user.target

47
glean/install.py Executable file
View File

@ -0,0 +1,47 @@
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
def install(source_file, target_file, mode='0755'):
script_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'init')
os.system(
'install -D -g root -o root'
' -m {mode} {source_file} {target_file}'.format(
source_file=os.path.join(script_dir, source_file),
target_file=target_file,
mode=mode))
def main():
if os.path.exists('/etc/init'):
install('glean.conf', '/etc/init/glean.conf')
elif os.path.exists('/usr/lib/systemd'):
install(
'glean@.service',
'/usr/lib/systemd/system/glean@.service')
install(
'glean-udev.rules',
'/etc/udev/rules.d/99-glean.rules',
mode='0644')
else:
install('glean.init', '/etc/init.d/glean')
os.system('update-rc.d glean defaults')
if __name__ == '__main__':
main()

View File

@ -23,6 +23,11 @@ classifier =
[entry_points]
console_scripts =
glean = glean.cmd:main
glean-install = glean.install:main
[files]
scripts =
glean/init/glean.sh
[build_sphinx]
source-dir = doc/source