1
0
mirror of https://github.com/marcan/takeover.sh.git synced 2020-11-18 19:38:40 -08:00

Merge pull request #4 from chewi/master

Support systemd and potentially other inits with a telinit wrapper
This commit is contained in:
Hector Martin 2017-02-25 18:11:26 +09:00 committed by GitHub
commit 9778c7de22
3 changed files with 11 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/fakeinit

View File

@ -28,9 +28,10 @@ handholding, this script is not for you.
## Compatibility ## Compatibility
This script is designed for systems using sysvinit that support the `telinit u` This script is designed for init systems that support the `telinit u` command to
command to reload `/sbin/init`. If your system uses something else, you will reload the init binary. This includes sysvinit and systemd. If your init system
have to adapt it, or this might not work at all. You're on your own here. works a different way, you will have to adapt it, or this might not work at
all. You're on your own here.
You should always test this in a VM first. You can grab a tarball of your live You should always test this in a VM first. You can grab a tarball of your live
root filesystem, extract it into a VM image, get your VM up and running (boot root filesystem, extract it into a VM image, get your VM up and running (boot

View File

@ -2,7 +2,7 @@
set -e set -e
TO=/takeover TO=/takeover
OLD_TELINIT=/sbin/telinit OLD_INIT=$(readlink /proc/1/exe)
PORT=80 PORT=80
cd "$TO" cd "$TO"
@ -47,8 +47,7 @@ if [ "$a" != "OK" ] ; then
fi fi
./busybox echo "Preparing init..." ./busybox echo "Preparing init..."
./busybox cp $OLD_TELINIT tmp/telinit ./busybox cat >tmp/${OLD_INIT##*/} <<EOF
./busybox cat >tmp/init <<EOF
#!${TO}/busybox sh #!${TO}/busybox sh
exec <"${TO}/${TTY}" >"${TO}/${TTY}" 2>"${TO}/${TTY}" exec <"${TO}/${TTY}" >"${TO}/${TTY}" 2>"${TO}/${TTY}"
@ -56,11 +55,12 @@ cd "${TO}"
./busybox echo "Init takeover successful" ./busybox echo "Init takeover successful"
./busybox echo "Pivoting root..." ./busybox echo "Pivoting root..."
./busybox mount --make-rprivate /
./busybox pivot_root . old_root ./busybox pivot_root . old_root
./busybox echo "Chrooting and running init..." ./busybox echo "Chrooting and running init..."
exec ./busybox chroot . /fakeinit exec ./busybox chroot . /fakeinit
EOF EOF
./busybox chmod +x tmp/init ./busybox chmod +x tmp/${OLD_INIT##*/}
./busybox echo "Starting secondary sshd" ./busybox echo "Starting secondary sshd"
@ -80,9 +80,9 @@ fi
./busybox echo "You may then kill the remnants of this session and any remaining" ./busybox echo "You may then kill the remnants of this session and any remaining"
./busybox echo "processes from your new SSH session, and umount the old root filesystem." ./busybox echo "processes from your new SSH session, and umount the old root filesystem."
./busybox mount --bind tmp /sbin ./busybox mount --bind tmp/${OLD_INIT##*/} ${OLD_INIT}
./tmp/telinit u telinit u
./busybox sleep 10 ./busybox sleep 10