Answering based on watching hundreds of hours of the sport.
A player's shift is however long they stayed on ice without any break of the game clock. That is if there is a stoppage like a penalty or TV timeout and the player was on ice before and after it, it's still the shift as the game clock didn't pass without the player off ice.
But if the game clock resets, like it does at the end of the periods, then that players shift also ends. Most skaters shifts are typically averaged from 45 seconds to a minutes, but that doesn't mean all shifts are in that range. You can see players on ice for 2+ minutes in case of a penalty kill, or end of game push to score/keep the other team from scoring.
Shifts are based on line changes, but not always when it comes to individual players.
Some coaches like to always have at least 1 center on ice as much as possible, so they instruct players so that the center on ice comes off only after the next shift's center has come on ice.
If the on ice center comes off and then the replacing center on, there is a short amount of time no center is on ice and a faceoff could be called, and you would end up with no center to take the faceoff (see why centers take faceoffs).
Or you could have a player who had some portion of their shift, then a penalty occurs, and so they remain on ice to penalty kill, even though the rest of their line got off ice. In this case the rest of the line completed a shift, but this player is still continuing theirs since they're part of the penalty kill unit. Similar situation can happen if a player is part of the power play unit.
So in cases 1 to 3, this is the same shift. By the way, as Parker mentioned, who stays on ice is the coaches decisions, not the players.
For case 4 I'm inclined to say it's a new shift, as the game clock has passed since the last time the player was on ice. After penalties you usually see the offender come back on ice and skate for a while, I believe this is a shift. But sometimes you see the offender sprint the length of ice so a more suitable player can get on ice instead of them. In this case, I'm not sure if that's a 1 or 2 second shift or not (maybe it's just ignored??).
In Case 5 if the player stays on ice, then it's a new shift. But in most cases the offender and most of the penalty kill unit go back on bench for a break.
Case 6 is a new shift as the period ended.
EDIT: Based on Joe's comment on this answer I'm adding the post.
As stated earlier, a shift is however long a player is on ice without game clock break.
A shift is so fundamental you're not gonna see a definition for it on nhl.com.
Hockeyviz, a website that puts visualized basic and advanced stats defines a shift as following:
A shift for a player is the total time from when they set skate on the
ice until they leave the ice; usually they will return to the bench
but sometimes they will go to the dressing room or to the penalty box.
So as stated above, my answer for all cases remains the same.
Alex Kovelav's 5 minute shift is a famous long shift. Within this shift, there is an icing and an offside which both stop the play. There are 3 power plays, 1 by his team, 2 by the opponent against Kovalev himself. Kovalev scores on one of the power plays too. The shift finally comes to an end as the period ends. Many stoppages, all same shift. And if you don't believe it's all the same shift, look at the linked video uploaded by the NHL itself calling it a 5 minute shift!