voxpupuli / puppet-nodejs

Puppet module to install nodejs and global npm packages
https://forge.puppet.com/puppet/nodejs
Apache License 2.0
113 stars 247 forks source link

Circular symlinks when legacy_debian_symlinks = true #335

Closed fnoop closed 6 years ago

fnoop commented 6 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

    class { 'nodejs':
        repo_url_suffix => '8.x',
        legacy_debian_symlinks => true,
        nodejs_package_ensure => latest,
    }

What are you seeing

Circular symlinks and nodejs not working:

ls -l /usr/bin/node
lrwxrwxrwx 1 root root 15 Nov 13 07:32 /usr/bin/node -> /usr/bin/nodejs
ls -l /usr/bin/nodejs
lrwxrwxrwx 1 root root 24 Nov 13 07:31 /usr/bin/nodejs -> /etc/alternatives/nodejs
ls -l /etc/alternatives/nodejs
lrwxrwxrwx 1 root root 13 Nov 13 07:31 /etc/alternatives/nodejs -> /usr/bin/node

What behaviour did you expect instead

Output log

Notice: /Stage[main]/Nodejs::Repo::Nodesource::Apt/Apt::Source[nodesource]/Apt::Key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]/Apt_key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]/ensure: created
Notice: /Stage[main]/Nodejs::Repo::Nodesource::Apt/Apt::Source[nodesource]/Apt::Setting[list-nodesource]/File[/etc/apt/sources.list.d/nodesource.list]/ensure: defined content as '{md5}358da832fb466325b172bc8ec5dc6cf0'
Notice: /Stage[main]/Apt::Update/Exec[apt_update]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Nodejs::Install/Package[nodejs]/ensure: ensure changed '4.8.2~dfsg-1' to '8.9.1-1nodesource1'
Notice: /Stage[main]/Nodejs::Install/Package[nodejs-dev]/ensure: removed
Notice: /Stage[main]/Nodejs::Install/File[/usr/bin/node]/ensure: ensure changed 'file' to 'link'
Notice: /Stage[main]/Nodejs::Install/File[/usr/share/man/man1/node.1.gz]/ensure: ensure changed 'file' to 'link'
Notice: /Stage[main]/Nodejs::Install/Package[npm]/ensure: removed
Notice: /Stage[main]/Nodejs::Install/File[root_npmrc]/ensure: defined content as '{md5}17626e1e7e2db5c71227460a36f6bbb8'

Any additional information you'd like to impart

The nodejs package installed from the repo that this module manages installs node as /usr/bin/node:

dpkg -L nodejs |grep 'usr/bin'
/usr/bin
/usr/bin/node
/usr/bin/npx
/usr/bin/npm

This module then overwrites this with a symlink. Nor is this behaviour idempotent - the first run it installs the link before the package so the package overwrites the link, then on subsequent run it overwrites the file with the link.

fnoop commented 6 years ago

legacy_debian_symlinks => false resolves the behaviour, this parameter should be aware of which versions/packages provide node or nodejs. Once the circular symlinks are in place the nodejs package cannot be removed (fails preremove checks).

juniorsysadmin commented 6 years ago

@fnoop Quality bug report. Can you confirm that you didn't have the nodejs-legacy package installed?

This module then overwrites this with a symlink.

Whoops.

Nor is this behaviour idempotent - the first run it installs the link before the package so the package overwrites the link, then on subsequent run it overwrites the file with the link.

Even better.

this parameter should be aware of which versions/packages provide node or nodejs

This could be a bit tricky. An easier solution might be to run a hackey exec to check the existence and type of file of /usr/bin/node and go from there.

Once the circular symlinks are in place the nodejs package cannot be removed (fails preremove checks).

Super.

juniorsysadmin commented 6 years ago

The best way to fix this is probably using puppet-alternatives.