aptosid.com

Requests & Suggestions - dist-upgrade WARNING if you are not in init 3

oddball - 23.09.2010, 09:34
Post subject: dist-upgrade WARNING if you are not in init 3
Could be that I'm alone with this problem but I usually do apt-get dist-upgrade -d in x so I can use my box during downloading. Then I do Ctrl+Alt+F1 and start the real upgrade with apt-get dist-upgrade and just as I did here, I sometimes forget to do init 3.

So far I have been lucky and nothing have broke but it's a problem for me.

Would it be possible to have an aptosid version of apt-get dist-upgrade that checks if you are in init 3 and if not, give you a warning and ask if you want to go on or not?

As I have understood the d-u in init 3 is a special sid/aptosid thing and not necessary in stable Debian, and that this is very important for us using aptosid I think it would be right to have this feature if it's possible.
mylo - 23.09.2010, 09:44
Post subject: RE: dist-upgrade WARNING if you are not in init 3
I think it is always recommended to d-u in init 3, as you do not know, whether X-related packages are to be updated. And that might kill X.
So the easiest way is getting used to do all of this in init 3 and not while working/doing other things.
gerd - 23.09.2010, 10:11
Post subject: RE: dist-upgrade WARNING if you are not in init 3
Downloading is possible without any problems in X.
To change apt-get dist-upgrade to check if it is in init 3 is not possible, cos it is a aptosid specific "problem" and apt belongs to debian.
But if you forget to init 3 and X crashes it should be no problem (if you have nothing unsaved in the running session, such as open text editors). The main reason to do apt-get du in init 3 is that the console from where you are running the d-u do not belongs to x, so that if X crashes the update process don't crashes to.
muchan - 23.09.2010, 10:38
Post subject: RE: dist-upgrade WARNING if you are not in init 3
there is a command 'runlevel', which should show something like
      Code:

5 3

if you have just changed runlevel 5 to 3 by init 3 command.
If you forgot init 3, it would show
      Code:

N 5

the second number is your current runlevel.

So,
(1) you get habit of calling it... (well, same as getting habit of calling 'init 3'

(2) make a small script to check the second number of output and warn you.
(can be also check if you're root, and if not call 'su')
if both ok, proceed...

(eidt: I'm not good at shell scripting... now after effort, I came to this
      Code:

if [ "$(runlevel | cut -c3)" -ne "3" ]; then
  echo baa;
fi


but what devil wrote below meanwhile is true... Smile

(further edit. was not 'R 5' but 'N 5')
devil - 23.09.2010, 10:46
Post subject: RE: dist-upgrade WARNING if you are not in init 3
you might as well change to TTY by the command 'init 3' in your shell. that prevents you forgetting to switch there and is faster anyways.

greetz
devil
gerd - 23.09.2010, 10:58
Post subject: RE: dist-upgrade WARNING if you are not in init 3
it would be also possible to make a script as alias for apt-get dist-upgrade.
scheme:
.bashrc (for root)
apt-get dist-upgrade -> script

script: init 3 ; /path_to_apt_get/apt-get dist-upgrade

no warranty, but this could work
muchan - 23.09.2010, 11:02
Post subject: RE: dist-upgrade WARNING if you are not in init 3
what is not good, at least for me, with this aproach of calling init 3 in script is,
if I call it in X termnal, all the application running in X is shutdown...

Sure, I should know it before calling the script, but then, (for me) it's more conscious
to call 'init 3' expricitely myself in the root terminal.
bluewater - 23.09.2010, 12:00
Post subject:
who -r

will give the current runlevel
gerd - 23.09.2010, 12:11
Post subject:
      bluewater wrote:
who -r

will give the current runlevel

I think it's time for a fresh install here. w, who (with and without -r) in a console gives a empty answer, conky says that 0 user are active... but it's also cool. I'm invisible Smile
bluewater - 23.09.2010, 12:43
Post subject:
gerd

uuuuuuuumm ,,, you run :
who -r
in a terminal, no idea what a system monitor has to do with running a command

eg

$ who -r
run-level 5 2010-09-23 16:36 last=S
gerd - 23.09.2010, 12:48
Post subject:
      bluewater wrote:
gerd

uuuuuuuumm ,,, you run :
who -r
in a terminal, no idea what a system monitor has to do with running a command

Even if i change with strg+alt+1 to TTY1 and log me in i get nothing if i type who or w. Same when i open a terminal-emulator in the running xfce-session.
(but it's no case for support or something. Probably i played a bit too much with the running processes)
bluewater - 23.09.2010, 12:51
Post subject:
hrhr
edhunter - 23.09.2010, 13:44
Post subject:
creating an alias to the apt-get dist-upgrade command would probably be the best way. create a script to check the run level and if the run level is correct do the upgrade otherwise inform the user

init 3 from with-in X means that you lose the current session and thats something i dont want

init 3 ; /path_to_apt_get/apt-get dist-upgrade is not really good as the dist-upgrade command will be executed independently of the exit code of the init 3 command so even if you fail to switch runlevels you will still do a dist-upgrade

init 3 && apt-get dist-upgrade is better as it will only execute a d-u if the runlevel switch is successful. (this will only work if you are already in a tty with alt+ctrl+F1 for example)
oddball - 23.09.2010, 16:14
Post subject: Re: RE: dist-upgrade WARNING if you are not in init 3
      devil wrote:
you might as well change to TTY by the command 'init 3' in your shell. that prevents you forgetting to switch there and is faster anyways.

greetz
devil
I don't agree that its faster because you have to be root twice, first su to do init 3 and then log in as root in tty,,,,,, ok if I do it with my method above with d-u -d in x then I'm already superuser and then it's faster, yes you are right as always devil Wink

A script will be some automation which put you a little out of controll. I would still like a little warning if I'm in the wrong runlevel, a warning can be followed or ignored and therefore you will still have full controll, but also a some security if you forget to do right.

edit:
      Quote:
creating an alias to the apt-get dist-upgrade command would probably be the best way. create a script to check the run level and if the run level is correct do the upgrade otherwise inform the user
thats a script that makes the warning, good, but couldn't it be inside a aptosid version of apt-get dist-upgrade?
edhunter - 23.09.2010, 16:21
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
@oddball: as you probably know we have no custom apt-get dist-upgrade version and I for one wouldn't want to force all our users to use this alias since most dont want/need it but I could help you with a script/alias if you want that
muchan - 23.09.2010, 16:32
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
One more idea, is check the runlevel, and if in 4 or 5, just add "-d" option on
apt-get update.
After the download is complete, apt-get, at the end, warns it's was just download. Smile
DonKult - 23.09.2010, 17:16
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Its little-known that APT can run commands after dpkg finished his job. Tools like etckeeper use it.
Its even more little-known that APT can run commands before calling dpkg - even if tools like apt-listchanges and alike use this hook.

This is an unsupported answer to this topic -- consider this post be part of the dragons forum. I will not helping anyone collection the pieces of their broken systems if something fails. -- Its untested, so it is likely to fail!

So, in theory you could do something like this
      Code:
#!/bin/sh
TEST="$(ps axww)";
if echo "$TEST" | grep 'apt-get dist-upgrade' > /dev/null; then
        if [ $(runlevel | cut -d' ' -f 2) > 3 ]; then
                echo "ERROR: aptosid strongly advices to do dist-upgrades only in runlevel 3,"
                echo "but you are still in runlevel $(runlevel | cut -d' ' -f 2)!"
                echo "See http://manual.aptosid.com/en/sys-admin-apt-en.htm#du-st"
                exit 3
        fi
fi

Save the code as /etc/apt/enforce-init3-for-du.sh
      Code:
chmod +x /etc/apt/enforce-init3-for-du.sh
echo 'DPkg::Pre-Invoke:: "/etc/apt/enforce-init3-for-du.sh"' > /etc/apt/apt.conf.d/00enforceinit3


And enjoy. In theory. The script above is not fullfeatured - heck it is not even tested - and very easy to trick out (intensional or not). And i am not even sure if it is a good idea to show this little trick in public… hence the warning above: Consider it repeated here at the end of the post Exclamation
muchan - 23.09.2010, 18:31
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
In this case, I would un-Dragon-ify the DonKult's script to simply

      Code:

#!/bin/sh
if [ $(runlevel | cut -d' ' -f 2) > 3 ]; then
        echo "ERROR: aptosid strongly advices to do dist-upgrades only in runlevel 3,"
        echo "but you are still in runlevel $(runlevel | cut -d' ' -f 2)!"
        echo "See http://manual.aptosid.com/en/sys-admin-apt-en.htm#du-st"
        exit 3
fi

apt-get update && apt-get dist-upgrade


(not tested)
devil - 23.09.2010, 18:42
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
      Quote:

don't agree that its faster because you have to be root twice, first su to do init 3 and then log in as root in tty,,,,,

ok, in my case, i have at least 1 root konsole open at all times...

greetz
devil
oddball - 23.09.2010, 21:54
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Thank you all for your suggestions, I think I will dare to try one of the last scripts when I have time.

Edit:
After reading the script suggestions above and with my very little knowledge of scripts I would like to ask:

Does DonKults script make the thing I asked for, it makes the command apt-get dist-upgrade check my runlevel and muchans script is one that I have to make a name for myself like "d-u" and then it would do the same but without "kidnapping" the command apt-get dist-upgrade?
Lat - 26.09.2010, 05:03
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Time to pull my scripts Razz

This is what I use to dist-upgrade, feel free to adapt it for your needs
      Code:
#!/bin/bash
# This program uses the command script to log all the messages displayed in a dist-upgrade process
# Also checks if X, kdm, gdm ares running and the runlevel isn't 5
ARL=$( echo $(/sbin/runlevel) | cut -d " " -f 2 )
askug="0"

if [[ $ARL == "5" ]] ; then
 echo " WARNING: You seem to be in level 5"
 askug="1"
fi

if [[ -n "$(ps aux|egrep -e kdm -e gdm | grep --invert-match grep)" ]] ; then
 echo " WARNING: KDM seems to be running"
 askug="1"
fi

if [[ -n "$(ps aux|grep /usr/bin/X| grep -v grep)" ]] ; then
 echo " WARNING: X seems to be running"
 askug="1"
fi

if [[ "${askug}" == "1" ]]; then
 echo "A dist-upgrade shouldn't be run"
 printf "Type \"yes\" to continue with the dist-ugprade or press ENTER to exit: "

 read x

 if [[ "$x" != "yes" ]] ; then
  echo " Exiting ..."
  exit
 fi
fi

echo " Dist-upgrading ..."

script -c "apt-get dist-upgrade" /root/du.txt

spacepenguin - 26.09.2010, 15:34
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Lat, I like your script. I was about to write one for myself but yours does exactly what I want, runlevel-check, kdm-check, x-check, warning but option to ignore it, logging - thanks for posting it. Smile

I just use the -a option for script to append the output and insert a date-divider. But I'd more like to append the date to filename (but don't know how) and collect several files.
Lat - 27.09.2010, 00:44
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Thank you spacepenguin

It can be done like you say. Something like
      Code:

script -c "apt-get dist-upgrade" newest-du.txt
date +%c >> du.txt
cat newest-du.txt >> du.txt

but I'd prefer having multiple log files, better than just one
How about:
      Code:
script -c "apt-get dist-upgrade" /var/log/dist-upgrade/du-$(date +%F--%X).txt


it will give you a log named: du-2010-09-26--08:35:28 PM.txt
/var/log/dist-upgrade directory should exist already (not in the mood to make a check and creation code for it)

do "man date" search for "FORMAT controls" for other sequences. There should be another better sequence to have it sorted

Then a rotatelogs rule could be created to compress old logs

Maybe you could check THAT old script to see how he logs the dist-upgrades
slh - 27.09.2010, 00:55
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
You know about /var/log/apt/history.log or /var/log/apt/term.log?
Lat - 27.09.2010, 01:02
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
haha, thank you slh. No I didn't know about them. I checked in /var/log and my eyes could only catch dpkg.log

Awesome, nice journal. It's like I could see my apt sins

Thank you for stopping me re-inventing the wheel
DeepDayze - 27.09.2010, 01:11
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Nice script Lat...I could look into using it too. Something like that can save our bacon Smile

And that last line in tiny font sure made me chuckle!
sx9 - 28.09.2010, 16:19
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
I've written a little script that switches to runlevel 3, when you've forgotten it and then does the d-u.
      Code:
 #!/bin/bash

opt="$( echo "$@" )"
case $opt in
    *--help*|*-h*)
        echo 'aptosid dist-upgrader'
        echo 'Performs a dist-upgrade how it is recommended by the aptosid-Team'
        echo 'Usage: dist-upgrade [options]'
        echo ''
        echo 'Options:'
        echo '-n, --noupdate    Dist-Upgrade without doing an apt-get update before'
        echo '-h, --help    Displays this message'
        dist-upgrade "$opt"
    ;;
    *--noupdate*|*-n*)
            echo 'Update skipped'
    ;;
esac
run="$( who -r | awk '{print $2}' )"
if [ ! "$run" == 3 ]
then
    echo 'You are not in runlevel 3!'
    echo 'It is not recommended to do a dist-upgrade during another runlevel than 3'
    echo 'Do you want to switch to runlevel 3 and perform a dist-upgrade? (Yes|No|Switch|Help)'
    case $1 in
        h|help|Help|H|HELP)
            echo 'yes        Switch to runlevel 3, perform an apt-get update and dist-upgrade'
            echo 'no        Exit aptosid dist-upgrader without doing anything'
            echo 'switch    Switch to runlevel '
        ;;
        y|Y|yes|Yes|YES)
            init 3
            apt-get update
            apt-get dist-upgrade
            exit 0
        ;;
        n|N|no|NO|No)
            exit 1
        ;;
        s|S|switch|Switch|SWITCH)
            init 3
            exit 0
        ;;
    esac
fi
apt-get update
apt-get dist-upgrade
exit 0

The next init-script can be useful for you, too: It does an apt-get update during the boot and downloads all upgradable packages during the shutdown progress.
Save it under /etc/init.d/apt-update-loader
      Code:
#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          apt-update-loader
# Required-Start:    $all
# Required-Stop:     
# Default-Start:     1 2 3 4 5
# Default-Stop:      0 6
# Short-Description: APT dist-upgrade downloader
# Description:       Downloads automatically the newest Package updates without installing them
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

case $@ in
   start)
      echo "Starting apt-update-loader"
      sudo apt-get update
      echo
      touch /var/lock/apt-update-loader
      killproc apt-get
   ;;
   stop)
      echo -n "Downloading packages for upgrade:"
      sudo apt-get dist-upgrade -d
      killproc apt-get
      rm -f /var/run/httpd.pid
      rm -f /var/lock/apt-update-loader
   ;;
   restart)
      $0 stop
      $0 start

   ;;
   status)
      status apt-get
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|reload|status}"
      exit 1
   ;;
esac

exit 0

sx9 - 28.09.2010, 16:21
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Oh, sorry Lat...
Havn't seen your post...
piper - 07.10.2010, 22:31
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
There is NO script (including smxi) that is faster and easier than
      Code:
init 3 && apt-get update && apt-get dist-upgrade


I just don't understand ...

nice script though Lat Wink
oddball - 08.10.2010, 14:30
Post subject: Re: RE: Re: RE: dist-upgrade WARNING if you are not in init
      piper wrote:
There is NO script (including smxi) that is faster and easier than
      Code:
init 3 && apt-get update && apt-get dist-upgrade


I just don't understand ...

nice script though Lat Wink
You are right piper but the original question was based on that I some times forget the init 3 part and without a warning you will not notice the mistake.
All times are GMT - 12 Hours
Powered by PNphpBB2 © 2003-2010 The Zafenio Group
Credits