Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to gracefully stop emerge? (not ctrl-c)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Sat Apr 25, 2020 5:18 pm    Post subject: How to gracefully stop emerge? (not ctrl-c) Reply with quote

Hi, I may have missed something, but: how to gracefully stop a running emerge?
ctrl-c is what I usually do - but that's not graceful.

If emerge is interrupted during the "merge" phase, there could be incomplete merge, possibly rendering the merged package in non-working condition.
With higher "--jobs N" there is higher chance of of this to happen.

I found this old thread here
https://forums.gentoo.org/viewtopic-t-511398-start-0.html
there is no real solution to this question.

So I'd like to bring it up again.

I'd suggest something like "touch /run/stop-emerge" could work as a semaphore. Possibly stoping after the compile phase. Sure there could be way how to differentiate (possible) multiple emerges.
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3916

PostPosted: Sat Apr 25, 2020 5:38 pm    Post subject: Reply with quote

Open another terminal and run
Code:

kill -TERM $(ps -ef | grep emerge | grep -v colour | awk '{ print $2 }')
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22591

PostPosted: Sat Apr 25, 2020 6:43 pm    Post subject: Reply with quote

That ps could be simplified and made safer:
Code:
ps -C emerge -o pid=
No need for grep or awk. Also, if you did need to post-process the output for filtering, awk could do that and avoid the need for grep.

I'm not sure that using kill is much better though, because the user may have arranged for the termination of emerge to automatically terminate its children. It would be better to provide the mechanism that OP requested, where Portage can notice a stop request and gracefully stop itself at a good time.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sat Apr 25, 2020 7:56 pm    Post subject: Reply with quote

Move $DISTDIR out of the way, make it a symlink to /dev/null, then wait for emerge to give up when it can't start new jobs.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22591

PostPosted: Sat Apr 25, 2020 9:34 pm    Post subject: Reply with quote

That's an interesting solution. As a less disruptive form, you could mount an empty zero-sized tmpfs over $DISTDIR with mount -t tmpfs -o nr_inodes=1,ro $DISTDIR $DISTDIR. This leaves the directory untouched, but hidden, so the change is automatically lost on reboot.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sat Apr 25, 2020 11:28 pm    Post subject: Reply with quote

Oh, that's a much better trick, never would've thought of that.
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Apr 25, 2020 11:44 pm    Post subject: Reply with quote

Quote:
ctrl-c is what I usually do - but that's not graceful.

I really hope that emerge blocks SIGINT (Ctrl-C) before it starts operations that must not be interrupted.
Back to top
View user's profile Send private message
fpemud
Guru
Guru


Joined: 15 Feb 2012
Posts: 350

PostPosted: Sun Apr 26, 2020 1:23 am    Post subject: Reply with quote

I think the ultimate solution would be making the emerge process transactional.
Perhaps utilizing the lvm or btrfs snapshot.
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Sun Apr 26, 2020 8:25 am    Post subject: Reply with quote

Just tested that none of HUP, INT nor TERM stops gracefully - they all can stop emerge in the middle of ">>> Installing ..." phase (which is what I'm worried about the most).
Back to top
View user's profile Send private message
xaviermiller
Bodhisattva
Bodhisattva


Joined: 23 Jul 2004
Posts: 8717
Location: ~Brussels - Belgique

PostPosted: Mon Apr 27, 2020 7:16 am    Post subject: Reply with quote

Hi,

You can try a trick on the /etc/portage/bashrc file and add some hook at the place you want
_________________
Kind regards,
Xavier Miller
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Mon Apr 27, 2020 7:25 am    Post subject: Reply with quote

xaviermiller wrote:
Hi,

You can try a trick on the /etc/portage/bashrc file and add some hook at the place you want


Now that seems like a nudge in the right direction. Thanks a lot, xaviermiller!
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3938
Location: Hamburg

PostPosted: Wed Aug 16, 2023 8:01 pm    Post subject: Reply with quote

I'm playing now with sth like this in bashrc:
Code:
  case ${EBUILD_PHASE} in
  clean|setup|unpack|prepare|configure|compile|test) exit 1 ;;
  esac
.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum