tmux in CoreOS?

2,451 views
Skip to first unread message

Carl Su

unread,
Mar 10, 2014, 1:54:24 AM3/10/14
to coreo...@googlegroups.com
I'd like to do some tasks (e.g. docker pull/push) in tmux to make sure that
it's running even when I lost my SSH connections. Can I have a tmux installed
in CoreOS? If not, what can I do?

Alex Polvi

unread,
Mar 10, 2014, 11:04:28 AM3/10/14
to coreos-dev
Carl, you might consider writing a systemd unit file, or running systemd-run. Having your process controlled by the init system will make sure it works regardless of your ssh connection. 

Futhermore, a docker pull actually causes the docker daemon to do the download... meaning if you lose your ssh connection it will still be running. 

-Alex

Carl

unread,
Mar 10, 2014, 11:48:08 AM3/10/14
to coreo...@googlegroups.com
I see. Thank you very much.

Philip Southam

unread,
Sep 16, 2014, 5:43:14 PM9/16/14
to coreo...@googlegroups.com
Carl,

You can try the following (I realize this may be a little late, but in case others want to do the same).

------------------------------------
 

Build a static TMUX (modified from this)

On your local system (or system with a build environment), create build-tmux.sh with the following conents:

#!/usr/bin/env bash
pushd $(dirname $0) > /dev/null; CURRABSPATH=$(readlink -nf "$(pwd)"); popd > /dev/null; # Get the directory in which the script resides
set -x
MUSLPKG="musl:musl.tgz:http://www.musl-libc.org/releases/musl-1.1.4.tar.gz"
LEVTPKG="libevent:libevent2.tgz:https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz"
TMUXPKG="tmux:tmux.tgz:http://iweb.dl.sourceforge.net/project/tmux/tmux/tmux-1.9/tmux-1.9a.tar.gz"
NCRSPKG="ncurses:ncurses.tgz:http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz"
TEMPDIR="$CURRABSPATH/tmp"
TMPLIB="tempinstall/lib"
TMPINC="tempinstall/include"
MUSLCC="$TEMPDIR/musl/tempinstall/bin/musl-gcc"
[[ -d "$TEMPDIR" ]] || mkdir "$TEMPDIR" || { echo "FATAL: Could not create $TEMPDIR."; exit 1; }
for i in "$MUSLPKG" "$NCRSPKG" "$LEVTPKG" "$TMUXPKG"; do
    NAME=${i%%:*}
    i=${i#*:}
    TGZ=${i%%:*}
    URL=${i#*:}
    [[ -d "$TEMPDIR/$NAME" ]] && rm -rf "$TEMPDIR/$NAME"
    [[ -d "$TEMPDIR/$NAME" ]] || mkdir  "$TEMPDIR/$NAME" || { echo "FATAL: Could not create $TEMPDIR/$NAME."; exit 1; }
    [[ -f "$CURRABSPATH/$TGZ" ]] || curl -o "$CURRABSPATH/$TGZ" "$URL" || wget -O "$CURRABSPATH/$TGZ" "$URL" || { echo "FATAL: failed to fetch $URL."; exit 1; }
    echo "Unpacking $NAME" && tar --strip-components=1 -C "$TEMPDIR/$NAME" -xf "$TGZ" && mkdir "$TEMPDIR/$NAME/tempinstall" \
        || { echo "FATAL: Could not unpack one of the required source packages. Check above output for clues."; exit 1; }
    echo "Building $NAME (this may take some time)"
    (
        PREFIX="$TEMPDIR/$NAME/tempinstall"
        case $NAME in
            musl )
                (cd "$TEMPDIR/$NAME" && ./configure --enable-gcc-wrapper --prefix="$PREFIX") && \
                make -C "$TEMPDIR/$NAME" && make -C "$TEMPDIR/$NAME" install
                ;;
            ncurses )
                (cd "$TEMPDIR/$NAME" && ./configure --without-ada --without-cxx --without-progs --without-manpages --disable-db-install --without-tests --with-default-terminfo-dir=/usr/share/terminfo --with-terminfo-dirs="/etc/terminfo:/lib/terminfo:/usr/share/terminfo" --prefix="$PREFIX" CC="$MUSLCC") && \
                make -C "$TEMPDIR/$NAME" && make -C "$TEMPDIR/$NAME" install
                ;;
            libevent )
                (cd "$TEMPDIR/$NAME" && ./configure --enable-static --enable-shared --disable-openssl --prefix="$PREFIX" CC="$MUSLCC") && \
                make -C "$TEMPDIR/$NAME" && make -C "$TEMPDIR/$NAME" install
                ;;
            tmux )
                (cd "$TEMPDIR/$NAME" && ./configure --enable-static --prefix="$PREFIX" CC="$MUSLCC" CPPFLAGS="-I$TEMPDIR/libevent/$TMPINC -I$TEMPDIR/ncurses/$TMPINC -I$TEMPDIR/ncurses/$TMPINC/ncurses" LDFLAGS="-L$TEMPDIR/libevent/$TMPLIB -L$TEMPDIR/ncurses/$TMPLIB" LIBS=-lncurses) && \
                make -C "$TEMPDIR/$NAME" && make -C "$TEMPDIR/$NAME" install
                strip $PREFIX/bin/tmux
                ;;
        esac
    ) 2>&1 |tee "$TEMPDIR/${NAME}.log" > /dev/null || { echo "FATAL: failed to build $NAME. Consult $TEMPDIR/${NAME}.log for details."; exit 1; }
    unset CC
done

Upload to Server

And place the binary where you can use it, say /opt/bin/.

$ scp tmp/tmux/tempinstall/bin/tmux core@example.com:
$ ssh core@example.com
$ sudo mv tmux /opt/bin # create this dir if it doesn't exist before moving

Run

$ sudo systemd-run --gid=core --uid=core -r  /bin/sh -c "/opt/bin/tmux -C"
$ /opt/bin/tmux a

You may be thinking, why not just run it via /opt/bin/tmux without using systemd-run? Go ahead and try it. As soon as you disconnect your ssh connection, the tmux session is killed. Running it via systemd-run keeps the session around.

Carl

unread,
Sep 17, 2014, 4:46:46 AM9/17/14
to coreo...@googlegroups.com
Philip,

Thank you so much for helping me. I never could have figured this out without your help.

I'll try to make my own tmux to see if it worked.

Philip Southam

unread,
Sep 17, 2014, 12:38:35 PM9/17/14
to coreo...@googlegroups.com
Carl,

If you trust me, you can download the static binary saving you the trouble of going through the aforementioned steps via the following link.

Igor Bukanov

unread,
Jan 19, 2015, 3:07:07 PM1/19/15
to coreo...@googlegroups.com

Philip,

When building on Fedora 21 the tmux static build script fails when configuring ncurses. To fix that I added --disable-shared to the configure command for musl. I also replaced --enable-shared with --disable-shared for libevent configure. After that the script successfully built tmux :)

Richard Phillips

unread,
Dec 8, 2016, 8:11:01 AM12/8/16
to CoreOS Dev
Old thread, but fantastically helpful. Thought I would share my systemd tmux.conf that is working for me..

[Unit]
Description=Tmux Startup
After=startups.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/bin/tmux -C
ExecStop=/opt/bin/tmux kill-server
KillMode=none

[Install]
WantedBy=multi-user.target

Sean Kane

unread,
Feb 8, 2017, 10:28:39 PM2/8/17
to CoreOS Dev
This is an easy option, assuming you trust the builds:

mkdir -p /opt/bin
export PATH=$PATH:/opt/bin
cd
/opt/bin
wget http
://s.minos.io/s -O static-get
chmod a
+rx ./static-get
cd
/opt
/opt/bin static-get tmux
tar xf tmux
-*.tar.xz
/opt/bin/tmux


For more information see:
Reply all
Reply to author
Forward
0 new messages