Author |
Message |
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 23.09.2010, 16:32
|
|
Moderator

Joined: 2010-09-11
Posts: 469
|
|
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.  |
|
|
|
|
 |
DonKult
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 23.09.2010, 17:16
|
|
Team Member

Joined: 2010-09-02
Posts: 485
Status: Offline
|
|
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  |
_________________ MfG. DonKult
"I never make stupid mistakes. Only very, very clever ones." ~ The Doctor
|
|
|
|
 |
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 23.09.2010, 18:31
|
|
Moderator

Joined: 2010-09-11
Posts: 469
|
|
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) |
Last edited by muchan on 23.09.2010, 19:13; edited 1 time in total
|
|
|
|
 |
devil
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 23.09.2010, 18:42
|
|

Joined: 2010-08-26
Posts: 491
Location: Berlin
Status: Offline
|
|
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 |
Last edited by devil on 24.09.2010, 00:23; edited 2 times in total
|
|
|
|
 |
oddball
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 23.09.2010, 21:54
|
|

Joined: 2010-09-11
Posts: 109
Location: Skåne, Sweden
Status: Offline
|
|
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
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 26.09.2010, 05:03
|
|

Joined: 2010-09-19
Posts: 205
Status: Offline
|
|
Time to pull my scripts
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
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 26.09.2010, 15:34
|
|

Joined: 2010-09-11
Posts: 98
Location: Germany
Status: Offline
|
|
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.
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. |
_________________ Susan | Hardware: SysProfile | 32bit
|
|
|
|
 |
Lat
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 27.09.2010, 00:44
|
|

Joined: 2010-09-19
Posts: 205
Status: Offline
|
|
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
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 27.09.2010, 00:55
|
|

Joined: 2010-08-25
Posts: 954
Status: Offline
|
|
You know about /var/log/apt/history.log or /var/log/apt/term.log? |
|
|
|
|
 |
Lat
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 27.09.2010, 01:02
|
|

Joined: 2010-09-19
Posts: 205
Status: Offline
|
|
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
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 27.09.2010, 01:11
|
|

Joined: 2010-09-11
Posts: 616
Location: USA
Status: Offline
|
|
Nice script Lat...I could look into using it too. Something like that can save our bacon
And that last line in tiny font sure made me chuckle! |
|
|
|
|
 |
sx9
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 28.09.2010, 16:19
|
|

Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
|
|
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
|
Last edited by sx9 on 05.06.2015, 15:21; edited 1 time in total
|
|
|
|
 |
sx9
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 28.09.2010, 16:21
|
|

Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
|
|
Oh, sorry Lat...
Havn't seen your post... |
_________________ My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
|
|
|
|
 |
piper
|
|
Post subject: RE: Re: RE: dist-upgrade WARNING if you are not in init 3
Posted: 07.10.2010, 22:31
|
|
Moderator

Joined: 2010-09-11
Posts: 481
Location: cheektowaga, ny
Status: Offline
|
|
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  |
|
|
|
|
 |
oddball
|
|
Post subject: Re: RE: Re: RE: dist-upgrade WARNING if you are not in init
Posted: 08.10.2010, 14:30
|
|

Joined: 2010-09-11
Posts: 109
Location: Skåne, Sweden
Status: Offline
|
|
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
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. |
|
|
|
|
 |
|