diff --git a/glean/init/glean-early.service b/glean/init/glean-early.service index 85dc29c..9ba0c15 100644 --- a/glean/init/glean-early.service +++ b/glean/init/glean-early.service @@ -7,7 +7,7 @@ After=local-fs.target [Service] Type=oneshot User=root -ExecStart=%%GLEANSH_PATH%%/glean-early.sh --debug +ExecStart=%%GLEAN_SCRIPTS_DIR%%/glean-early.sh --debug RemainAfterExit=true StandardOutput=journal+console diff --git a/glean/init/glean-networkd.service b/glean/init/glean-networkd.service index 28acd24..0c526d2 100644 --- a/glean/init/glean-networkd.service +++ b/glean/init/glean-networkd.service @@ -8,7 +8,7 @@ Wants=glean-early.service [Service] Type=oneshot User=root -ExecStart=%%GLEANSH_PATH%%/python-glean --distro networkd %%EXTRA_ARGS%% +ExecStart=%%GLEAN_SCRIPTS_DIR%%/python-glean --distro networkd %%EXTRA_ARGS%% RemainAfterExit=true [Install] diff --git a/glean/init/glean-nm@.service b/glean/init/glean-nm@.service index e902bbb..2062903 100644 --- a/glean/init/glean-nm@.service +++ b/glean/init/glean-nm@.service @@ -13,7 +13,7 @@ ConditionPathExists=!/etc/sysconfig/network/ifcfg-%I Type=oneshot User=root Environment="ARGS=--interface %I" -ExecStart=%%GLEANSH_PATH%%/python-glean --use-nm --debug %%EXTRA_ARGS%% $ARGS +ExecStart=%%GLEAN_SCRIPTS_DIR%%/python-glean --use-nm --debug %%EXTRA_ARGS%% $ARGS RemainAfterExit=true StandardOutput=journal+console diff --git a/glean/init/glean.conf b/glean/init/glean.conf index 5f816be..deeb2ea 100644 --- a/glean/init/glean.conf +++ b/glean/init/glean.conf @@ -11,4 +11,4 @@ start on starting networking task -exec %%GLEANSH_PATH%%/glean-legacy.sh %%EXTRA_ARGS%% +exec %%GLEAN_SCRIPTS_DIR%%/glean-legacy.sh %%EXTRA_ARGS%% diff --git a/glean/init/glean.init b/glean/init/glean.init index 8288e91..906f66a 100755 --- a/glean/init/glean.init +++ b/glean/init/glean.init @@ -12,7 +12,7 @@ NAME=glean INIT_NAME=/etc/init.d/${NAME} -SCRIPT_NAME=%%GLEANSH_PATH%%/glean-legacy.sh +SCRIPT_NAME=%%GLEAN_SCRIPTS_DIR%%/glean-legacy.sh [ -x $SCRIPT_NAME ] || exit 0 diff --git a/glean/init/glean.openrc b/glean/init/glean.openrc index ccbbfd8..f097f23 100644 --- a/glean/init/glean.openrc +++ b/glean/init/glean.openrc @@ -5,7 +5,7 @@ description="basic instance setup" start() { - %%GLEANSH_PATH%%/glean-legacy.sh + %%GLEAN_SCRIPTS_DIR%%/glean-legacy.sh eend 0 } diff --git a/glean/init/glean@.service b/glean/init/glean@.service index 21441c7..1800275 100644 --- a/glean/init/glean@.service +++ b/glean/init/glean@.service @@ -16,7 +16,7 @@ ConditionPathExists=!/etc/network/interfaces.d/%I.cfg Type=oneshot User=root Environment="ARGS=--interface %I" -ExecStartPre=%%GLEANSH_PATH%%/python-glean %%EXTRA_ARGS%% ${ARGS} +ExecStartPre=%%GLEAN_SCRIPTS_DIR%%/python-glean %%EXTRA_ARGS%% ${ARGS} ExecStart=/sbin/ifup %I RemainAfterExit=true diff --git a/glean/install.py b/glean/install.py index 94eecdb..ff9b61c 100755 --- a/glean/install.py +++ b/glean/install.py @@ -23,9 +23,7 @@ import sys log = logging.getLogger("glean-install") -def _find_gleansh_path(): - # glean.sh is a script installed by setup.cfg as a sibling to this - # script +def _find_scripts_dir(): p = pkg_resources.resource_filename(__name__, "init") return p @@ -45,8 +43,7 @@ def install(source_file, target_file, mode='0755', replacements=dict()): log.info("Installing %s -> %s" % (source_file, target_file)) - script_dir = os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'init') + script_dir = _find_scripts_dir() cmd = ('install -D -g root -o root' ' -m {mode} {source_file} {target_file}').format( @@ -94,7 +91,7 @@ def main(): "it will be left unconfigured.") args = parser.parse_args() - p = _find_gleansh_path() + p = _find_scripts_dir() extra_args = '--no-dhcp-fallback' if args.no_dhcp_fallback else '' if args.quiet: @@ -102,19 +99,23 @@ def main(): else: logging.basicConfig(level=logging.INFO) - # Write the path of the currently executing interpreter into a - # file alongside glean.sh. This means glean.sh can call the + replacements = { + 'INTERP': sys.executable, + 'GLEAN_SCRIPTS_DIR': p, + 'EXTRA_ARGS': extra_args, + } + + # Write the path of the currently executing interpreter into the + # scripts dir. This means glean shell scripts can call the # sibling python-glean and know that it's using the glean we # installed, even in a virtualenv etc. install('python-glean.template', os.path.join(p, 'python-glean'), - mode='0755', replacements={'INTERP': sys.executable}) + mode='0755', replacements=replacements) # needs to go first because gentoo can have systemd along side openrc if os.path.exists('/etc/gentoo-release'): log.info('installing openrc services') - install('glean.openrc', '/etc/init.d/glean', - replacements={'GLEANSH_PATH': p, - 'EXTRA_ARGS': extra_args}) + install('glean.openrc', '/etc/init.d/glean', replacements=replacements) # Needs to check for the presence of systemd and systemctl # as apparently some packages may stage systemd init files # when systemd is not present. @@ -127,22 +128,18 @@ def main(): or os.path.exists('/bin/systemctl'))): log.info("Installing systemd services") - log.info("glean.sh in %s" % p) log.info("Install early service") install( 'glean-early.service', '/usr/lib/systemd/system/glean-early.service', - mode='0644', - replacements={'GLEANSH_PATH': p}) + mode='0644', replacements=replacements) subprocess.call(['systemctl', 'enable', 'glean-early.service']) if os.path.exists('/etc/gentoo-release'): install( 'glean-networkd.service', '/lib/systemd/system/glean.service', - mode='0644', - replacements={'GLEANSH_PATH': p, - 'EXTRA_ARGS': extra_args}) + mode='0644', replacements=replacements) subprocess.call(['systemctl', 'enable', 'glean.service']) else: log.info("Installing %s NetworkManager support" % @@ -154,9 +151,7 @@ def main(): install( service_file, '/usr/lib/systemd/system/glean@.service', - mode='0644', - replacements={'GLEANSH_PATH': p, - 'EXTRA_ARGS': extra_args}) + mode='0644', replacements=replacements) install( 'glean-udev.rules', '/etc/udev/rules.d/99-glean.rules', @@ -181,19 +176,13 @@ def main(): elif os.path.exists('/etc/init'): log.info("Installing upstart services") install('glean.conf', '/etc/init/glean.conf', - replacements={ - 'GLEANSH_PATH': p, - 'EXTRA_ARGS': extra_args - }) + replacements=replacements) elif os.path.exists('/sbin/rc-update'): subprocess.call(['rc-update', 'add', 'glean', 'boot']) else: log.info("Installing sysv services") install('glean.init', '/etc/init.d/glean', - replacements={ - 'GLEANSH_PATH': p, - 'EXTRA_ARGS': extra_args - }) + replacements=replacements) os.system('update-rc.d glean defaults')