hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Jessie: How to display "My IP address is" at login prompt

Fri Oct 02, 2015 12:45 am

When Wheezy booted up to a CLI login prompt, a handy line which appeared just above the Raspian GNU/Linux banner and login prompt showed "My IP address is 192.168.1.22" or similar. It was quite handy to have as it gave a list of all IP addresses assigned, static and DHCP.

That doesn't appear with Jessie. Anyone know how to get it or where one would stick a 'print' or something to show the same ?

A random example from Google Images just to show what I am talking about below -

Image

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 1:13 am

That functionality came from a few lines in /etc/rc.local, so the easiest thing to do would be to get hold of the rc.local file from a old (Wheezy) system and bring it over to Jessie.

The lines are something like:

Code: Select all

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 1:27 am

Joe Schmoe wrote:That functionality came from a few lines in /etc/rc.local, so the easiest thing to do would be to get hold of the rc.local file from a old (Wheezy) system and bring it over to Jessie.
That sounded like a good idea, but /etc/rc.local is already there in Jessie and with the appropriate lines included.

I would guess that it's not being run by systemd or perhaps being run earlier and getting scrolled off the top of the screen.

Thanks for pointing out where it is and what the code would be. Worked as expected when I created a shell script.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 1:29 am

I would guess that it's not being run by systemd or perhaps being run earlier and getting scrolled off the top of the screen.
It should start working again once you uninstall (deactivate, and thus revert to old style init) systemd.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 1:38 am

I just did some testing, yes it is running and I think as you have guessed either it is being run earlier or the output is not being displayed on the screen. If you get this working you will see another issue, Raspbian Jessie is using IP6 as well as IP4. The output of hostname -I gives both the IP6 and IP4 addresses. The output of the rc.local printf only prints the IP6 address

Code: Select all

My IP address is 2002:...

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 2:05 am

The issue is that you don't have an IP lease at the time rc.local runs, so there's nothing to show.

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 2:32 am

ShiftPlusOne wrote:The issue is that you don't have an IP lease at the time rc.local runs, so there's nothing to show.
I see ... the IP6 address I was getting was just the Link address.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 7:04 am

Joe Schmoe wrote:It should start working again once you uninstall (deactivate, and thus revert to old style init) systemd.
I am starting to understand why some people aren't at all happy with systemd.

This appears to be stock Debian behaviour, is flawed behaviour, and simply doesn't work when using DHCP ...
ShiftPlusOne wrote:The issue is that you don't have an IP lease at the time rc.local runs, so there's nothing to show.
That does seem to be the case from my own additional testing. Forcing a "printf" in rc.local shows it is run before "Starting LSB: IPv4 client..." which is when it would get its IP address.

Setting aside the flawed behaviour of systemd running rc.local before having an IP address assigned, does anyone know where the IP address report could be put to have it run as late as possible in the systemd boot-up process or, ideally, just before the "Raspbian GNU/Linux" banner ?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 10:01 am

hippy wrote:This appears to be stock Debian behaviour, is flawed behaviour, and simply doesn't work when using DHCP ...
Are you sure? I assumed it was because we're using dhcpcd. Not sure what stock raspbian/debian does.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 4:59 pm

ShiftPlusOne wrote:
hippy wrote:This appears to be stock Debian behaviour, is flawed behaviour, and simply doesn't work when using DHCP ...
Are you sure? I assumed it was because we're using dhcpcd. Not sure what stock raspbian/debian does.
You could well be right, so humble apologies if I am casting aspersions in the wrong direction.

I edited /etc/network/interfaces for eth0 from manual to static and dhcp and rc.local does then pick up and show the IP address in both cases. It's only when manual it doesn't.

When set for static, the "My IP address is..." shows only the static address when rc.local is run, and both static and dhcp IP addresses assigned after login. So IP address assignment behaviour appears the same as for Wheezy.

So does that means it's not necessarily rc.local being run too soon but dhcpcd being run too late ?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie : How to display "My IP address is" at login prom

Fri Oct 02, 2015 5:18 pm

The way it's set up, dhcpcd doesn't let systemd know when it's 'done'. So even when it gets a lease, it's still just an active process running in the background. Simon (spl) found that if you create a systemd unit for it instead of backgrounding it, use '-t 0', it seems to work as intended. Just doing a bit of testing to make sure it does what we think it does before releasing it as a fix. It looks like it will also take care of the nfs mounts and various other network-related issues people have been having with the new network setup.

EDIT: viewtopic.php?f=28&t=122066#p823749

bsberry
Posts: 1
Joined: Tue Oct 13, 2015 8:53 pm

Re: Jessie: How to display "My IP address is" at login promp

Tue Oct 13, 2015 8:55 pm

Has a solution to this been found?

tpylkko
Posts: 392
Joined: Tue Oct 14, 2014 5:21 pm

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 4:30 am

I haven't done this since I don't need it. However, the proper way to do it would be (I think) to use After in the .service file and set that to match with something that guarantees that the network is up. for example, when using network manager, dbus-org.freedesktop.NetworkManager.target. Or After=network.target, or network-online.target though this might then cause boot time to increase?
See:
http://www.freedesktop.org/wiki/Softwar ... orkTarget/

Another way that would work, but which is a bit ugly would be to write a bash script (launched in a .service using ExecStart=yourscrptname inside the .service) that loops ifconfig or other ip revealing command untill the condition is met that it produces an output line that has 192.168 in it (using grep, for example) (assuming that your ip is going to start with that) and prints and exits right after.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 9:00 am

There are a few problems here:
Nothing seems to depend on network-online.target, even when it should be. For example, the default rc.local compatibility service, nfs mounts and transmission-daemon don't.
ifplugd doesn't work particularly well. It runs ifup for the lo service then complains that the lock files don't exist. We have it installed on the full image even though dhcpcd provides all the functionality, so they may be interfering with each other too.
After removing ifplugd, installing dhcpcd, creating and enabling unit file for it and setting up the interfaces file accordingly we found that we have a pretty good and flexible network setup.

A question remains of whether it's best to hold up the boot process while an IP address is leased and add ~5 seconds to the boot time, or boot anyway and expect the services that want internet access will start after network-online.target. Then we need to also consider people who'll boot without an internet connection and see what a reasonable time out is. In any case, there will be a raspi-config option to change this behaviour, which will be nice.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 10:01 am

ShiftPlusOne wrote:A question remains of whether it's best to hold up the boot process while an IP address is leased and add ~5 seconds to the boot time, or boot anyway and expect the services that want internet access will start after network-online.target
Everything seems to work as expected when networking is configured using /etc/network/interfaces so it appears to be use of dhcpcd which creates the problem.

Any explicit or forced holding up of the boot process is anathema to systemd and seems to point to doing it the wrong way, though I appreciate having to find a solution is the issue.

I like the idea of systemd ( at least the way it schedules and orders the boot process ). It makes a lot of sense to me, but I can understand why some people feel that the way it is implemented or configured, the difficulty of making things work as particular use cases require, renders it unfit for purpose.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 10:21 am

hippy wrote:
ShiftPlusOne wrote:A question remains of whether it's best to hold up the boot process while an IP address is leased and add ~5 seconds to the boot time, or boot anyway and expect the services that want internet access will start after network-online.target
Everything seems to work as expected when networking is configured using /etc/network/interfaces so it appears to be use of dhcpcd which creates the problem.

Any explicit or forced holding up of the boot process is anathema to systemd and seems to point to doing it the wrong way, though I appreciate having to find a solution is the issue.

I like the idea of systemd ( at least the way it schedules and orders the boot process ). It makes a lot of sense to me, but I can understand why some people feel that the way it is implemented or configured, the difficulty of making things work as particular use cases require, renders it unfit for purpose.
Only unfit for some purposes and use cases.

As to the OP, how about putting the IP address in the prompt itself, http://superuser.com/questions/668174/h ... ash-prompt. Probably still suffers the same issue of DHCP being too slow to get set up though.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 10:53 am

hippy wrote:
ShiftPlusOne wrote:A question remains of whether it's best to hold up the boot process while an IP address is leased and add ~5 seconds to the boot time, or boot anyway and expect the services that want internet access will start after network-online.target
Everything seems to work as expected when networking is configured using /etc/network/interfaces so it appears to be use of dhcpcd which creates the problem.

Any explicit or forced holding up of the boot process is anathema to systemd and seems to point to doing it the wrong way, though I appreciate having to find a solution is the issue.

I like the idea of systemd ( at least the way it schedules and orders the boot process ). It makes a lot of sense to me, but I can understand why some people feel that the way it is implemented or configured, the difficulty of making things work as particular use cases require, renders it unfit for purpose.
If you don't use dhcpcd and use auto eth0 with 'dhcp' instead of 'manual' setup, it will hold the boot process up until it has an IP too. It seems like the default Debian behaviour is to wait for the dhcp client to do its thing before saying the network is up.

dhcpcd isn't causing the problem. At most, it's the improper configuration thereof. I think the choice depends on the user, so it should be configurable. I don't care if Poettering or other systemd devs think holding up the boot process to get an IP address is wrong, if it means that a large chunk of the users are finding that their setup doesn't work the way it should. Until network-online.target is actually used by software which should use it, we can't rely on it. We also can't provide our own patched systemd unit files for all the software which should use it but doesn't. So that only leaves giving people the option to decide what they actually want.

Regarding your last point, the actual solution is quite simple and involves a single parameter change when launching dhcpcd. I find that configuring systemd is actually very easy and it's much more flexible than sysvinit. Not only that, but the solutions are much more elegant than they are with sysvinit. It's just that they're not out there on the wikis, stackexchange and the documentation, so if you are not willing to read the manual, you're going to have a bad time. There's also a lot of "this used to work, now it doesn't, therefore it's broken" and "where's inittab" as a result. We just need to make sure we find and provide the answers and update the documentation accordingly.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 10:59 am

jamesh wrote:As to the OP, how about putting the IP address in the prompt itself, http://superuser.com/questions/668174/h ... ash-prompt. Probably still suffers the same issue of DHCP being too slow to get set up though.
I would guess it depends on where one would put the commands to set the prompt. If in rc.local that's too early and would suffer the same problem. I have multiple IP address assigned and that would make a quite cumbersome prompt so not a solution for me anyway. I also want the display before logging in.

I have considered writing /etc/issue or message of the day but that has the same problem; it doesn't yet have the IP address when you come to use it. Those will however be the only means I can see so far to get the IP printed out just before the console login prompt, as one has little control over where in the list of messages rc.local displays things. There doesn't seem to be an 'after everything is done but before the login prompt' state to target.

I am planning to write /etc/issue to get the display where I want and will likely use /etc/network/interfaces to configure the network until the dhcpcd issue is resolved. Just haven't had the time to try it yet.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 11:06 am

jamesh wrote:Only unfit for some purposes and use cases.
I wouldn't grant that as a problem inherent to systemd. If it was sysvinit without the decades worth of resources out there for it, there would me as much confusion, I think.

I'd only say that for now, unless you've read through the documentation, the 'systemd for administrators' series and have played around with a few systemd units, you're going to have a bad time doing something non-standard.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 12:24 pm

ShiftPlusOne wrote:Regarding your last point, the actual solution is quite simple and involves a single parameter change when launching dhcpcd.
Thanks; I had thought that was the case from other postings but was waiting for that to roll out through apt-get update/upgrade.

I think you are right that most of the problem is lack of familiarity with systemd. For people like myself who have self-taught themselves some degree of Linux but not a lot it is very unfamiliar, difficult to even find where things are which need tweaking, along with reading up on it and understanding how it works.

If you could detail what the exact change is and in which file it has to made that would be appreciated and I'm quite happy to test that out.

That will fix one problem ( having a DHCP IP address assigned by dhcpcd when rc.local runs ) and I can deal with getting that displayed where I want with that.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 2:44 pm

Editing /etc/rc.local to write /etc/issue shows the "My IP address..." message before the login prompt as it used to be with Wheezy -

Code: Select all

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  printf "My IP address is %s\n\nRaspbian GNU/Linux\n\n" "$_IP" > /etc/issue
else
  printf "Raspbian GNU/Linux\n\n" > /etc/issue
fi    
So all that's needed now is to ensure the Pi has its DHCP IP address allocated when rc.local runs.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 3:06 pm

Caveat: I haven't followed all the chatter in this thread that closely, but ...

If what the OP is really looking for is just exactly this - i.e., that there are no further expectations - then how about just putting code in .profile (or one of the .bash_* files - whichever suits your fancy) so that it gets displayed when the user logs in? This, combined with an auto-login setup (which seems to be there by default on /dev/tty1) and it would come up (i.e., be displayed) automatically like it used to.

This suggestion depends on two assumptions:
  1. That this really is the point - that OP just wants it to display the IP address like it used to. I.e., that this isn't a proxy for a general "How do I do stuff in the brave new world?" type question.
  2. That you can rely on the network (and all the other brave new world stuff) to have been completed before the login prompt(s) are issued.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 3:46 pm

I am the OP. What I wanted was the "My IP Address is..." message to come up on the TV screen, at the bottom before the login prompt, as it did with Wheezy, as I had found it a useful informational tool to have.

I generally run my Pi headless but when messing with network configurations, swapping access points, routers and hubs around, when things go wrong I can turn the TV on and see what it says.

There were two unexpected problems with the 'brave new world' of Jessie - (1) that rc.local no longer does its thing just before the login prompt so any message from it isn't where I'd like it to be, and (2) the Pi doesn't know what IP addresses it has when it comes to run rc.local when using dhcpcd to get a DHCP IP address.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 3:56 pm

I am the OP.
I get it. So, what do you think of the idea of including it in the .profile?

Remember, there is already auto-login on /dev/tty1, so it will "just work".
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to display "My IP address is" at login promp

Wed Oct 14, 2015 5:31 pm

Joe Schmoe wrote:So, what do you think of the idea of including it in the .profile?
That should work but as it is so close to being solved as how it was I will be happy with that.

Return to “Raspbian”