You are not logged in.

#1 2015-02-13 23:34:49

AlgoJerViA
Member
Registered: 2014-08-06
Posts: 24

Problems with multiple tmux services

Hi
I have two systemd services involving tmux, the first one starts rtorrent like this

[Unit]
Description=rTorrent
Requires=network.target local-fs.target

[Service]
Type=forking
KillMode=none
User=%I
ExecStart=/usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q
WorkingDirectory=/home/%I/
Restart=on-failure

[Install]
WantedBy=multi-user.target
[Unit]
Description=Irssi running with tmux
Requires=network.target local-fs.target

[Service]
RemainAfterExit=yes
Type=forking
KillMode=none
User=%I
ExecStart=/usr/bin/tmux new-session -s irc -n irssi -d irssi
ExecStop=/usr/bin/tmux send-keys -t irc:irssi /quit Enter
WorkingDirectory=/home/%I/
Restart=on-failure

[Install]
WantedBy=multi-user.target

That is enabled and started as rt@andreas. The other script starts irssi and is also enabled and started with the correct user.

ps -ax | grep tmux

gives

  289 ?        Ss     0:00 /usr/bin/tmux new-session -s irc -n irssi -d irssi
  291 ?        Ss     0:00 /usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
 2345 pts/3    S+     0:00 grep --color=auto tmux

So they both starts correctly but....

tmux list-sessions

only return this single line:

rt: 1 windows (created Fri Feb 13 23:40:12 2015) [213x76]

irssi has gone missing from tmux doesn't seem to be possible to attach either. sad

Offline

#2 2015-02-14 03:08:04

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Problems with multiple tmux services

I would guess the irssi session is owned by root. Run 'ps uax | grep tmux' to confirm.

Since you didn't post unit config file names or systemctl status output, my best guess is that the unit config file for the irssi session isn't named <whatever>@.service.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#3 2015-02-15 19:41:12

AlgoJerViA
Member
Registered: 2014-08-06
Posts: 24

Re: Problems with multiple tmux services

The output of 'ps aux | grep tmux' is this.

andreas    312  0.0  0.0  19648  2692 ?        Ss   Feb14   0:04 /usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
andreas    315  0.0  0.0  19648  2720 ?        Ss   Feb14   0:03 /usr/bin/tmux new-session -s irc -n irssi -d irssi
andreas  10382  0.0  0.0  10704  2260 pts/4    S+   20:31   0:00 grep --color=auto tmux

Output of 'sudo systemctl status irssi@andreas.service is:

● irssi@andreas.service - Irssi running with tmux
   Loaded: loaded (/etc/systemd/system/irssi@.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2015-02-14 01:03:32 CET; 1 day 19h ago
  Process: 280 ExecStart=/usr/bin/tmux new-session -s irc -n irssi -d irssi (code=exited, status=0/SUCCESS)
 Main PID: 315 (tmux)
   CGroup: /system.slice/system-irssi.slice/irssi@andreas.service
           ├─315 /usr/bin/tmux new-session -s irc -n irssi -d irssi
           └─317 irssi

Feb 14 01:03:32 elliot systemd[1]: Started Irssi running with tmux.

And the output of 'sudo systemctl status rt@andreas.service is:

● rt@andreas.service - rTorrent
   Loaded: loaded (/etc/systemd/system/rt@.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2015-02-14 01:03:32 CET; 1 day 19h ago
  Process: 281 ExecStart=/usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent (code=exited, status=0/SUCCESS)
 Main PID: 312 (tmux)
   CGroup: /system.slice/system-rt.slice/rt@andreas.service
           ├─312 /usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
           └─316 rtorrent

Feb 14 01:03:32 elliot systemd[1]: Started rTorrent.

Also after the last restart it is the rtorrent session that is not listed with 'tmux list-session' but the irssi one show up fine.

Offline

#4 2015-02-16 02:27:08

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Problems with multiple tmux services

From what I've been able to gather it has something to do with the socket used by tmux, /tmp/tmux-<uid>/default. Presumably, the first service is started before /tmp is mounted. Then /tmp is mounted and that socket becomes inaccessible. Finally the second service is started, which will remain accessible (Edit1: After further investigation that doesn't seem to be the case, but it still seems to have to do with the socket somehow). My initial solution workaround is to make both After= tmp.mount:

[Unit]
Description=Irssi running with tmux
Requires=network.target tmp.mount
After=network.target tmp.mount

[Service]
RemainAfterExit=yes
Type=forking
KillMode=none
User=%I
ExecStart=/usr/bin/tmux new-session -s irc -n irssi -d irssi
ExecStop=/usr/bin/tmux send-keys -t irc:irssi /quit Enter
WorkingDirectory=/home/%I/

[Install]
WantedBy=multi-user.target
[Unit]
Description=rTorrent
Requires=network.target tmp.mount
After=network.target tmp.mount

[Service]
RemainAfterExit=yes
Type=forking
KillMode=none
User=%I
ExecStart=/usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q
WorkingDirectory=/home/%I/

[Install]
WantedBy=multi-user.target

But that seems hackish. I expect there's a cleaner way, but I haven't found it yet.

You may also notice the weird situation with the status of the units:

$ systemctl status irssi@alphaniner
● irssi@alphaniner.service - Irssi running with tmux
   Loaded: loaded (/etc/systemd/system/irssi@.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2015-02-15 16:03:28 EST; 9min ago
  Process: 226 ExecStart=/usr/bin/tmux new-session -s irc -n irssi -d irssi (code=exited, status=0/SUCCESS)
 Main PID: 230 (tmux)
   CGroup: /system.slice/system-irssi.slice/irssi@alphaniner.service
           ├─230 /usr/bin/tmux new-session -s irc -n irssi -d irssi
           ├─231 irssi
           └─232 rtorrent

Feb 15 16:03:28 wiwimaru systemd[1]: Starting Irssi running with tmux...
Feb 15 16:03:28 wiwimaru systemd[1]: Started Irssi running with tmux.

$ systemctl status rt@alphaniner
● rt@alphaniner.service - rTorrent
   Loaded: loaded (/etc/systemd/system/rt@.service; enabled; vendor preset: disabled)
   Active: active (exited) since Sun 2015-02-15 16:03:28 EST; 9min ago
  Process: 228 ExecStart=/usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent (code=exited, status=0/SUCCESS)

Feb 15 16:03:28 wiwimaru systemd[1]: Started rTorrent.

The same thing happens with your original services if manually started after login though.

----------

Edit 2: A slightly better idea of what's going on wrt the socket. When both of your original services are enabled, the result is two tmux processes, both 'attached to' the socket:

$ ps ax |grep tmux
   159 ?        Ss     0:00 /usr/bin/tmux new-session -s irc -n irssi -d irssi
   160 ?        Ss     0:00 /usr/bin/tmux new-session -s rt -n rtorrent -d rtorrent
   248 pts/2    S+     0:00 grep --color=auto tmux

$ lsof -U |grep tmux
tmux    159 alphaniner    3u  unix 0xffff880078c05b00      0t0  9793 type=STREAM
tmux    159 alphaniner    4u  unix 0xffff880078c05080      0t0  9794 type=STREAM
tmux    159 alphaniner    6u  unix 0xffff880078c04280      0t0  9795 /tmp/tmux-1000/default type=STREAM
tmux    160 alphaniner    3u  unix 0xffff880078c03480      0t0  9799 type=STREAM
tmux    160 alphaniner    4u  unix 0xffff880078c03b80      0t0  9800 type=STREAM
tmux    160 alphaniner    6u  unix 0xffff880078c00000      0t0  9801 /tmp/tmux-1000/default type=STREAM

But when the same services are started manually, only one process exists:

$ sudo systemctl start oldirssi@alphaniner
$ sudo systemctl start oldrt@alphaniner

$ tmux ls
irc: 1 windows (created Sun Feb 15 17:54:03 2015) [80x23]
rt: 1 windows (created Sun Feb 15 17:54:16 2015) [80x23]

$ ps ax |grep tmux
   241 ?        Ss     0:00 /usr/bin/tmux new-session -s irc -n irssi -d irssi
   258 pts/0    S+     0:00 grep --color=auto tmux

$ lsof -U |grep tmux
tmux    241 alphaniner    3u  unix 0xffff880078ea5b00      0t0 11477 type=STREAM
tmux    241 alphaniner    4u  unix 0xffff880078ea5400      0t0 11478 type=STREAM
tmux    241 alphaniner    6u  unix 0xffff880078ea5780      0t0 11479 /tmp/tmux-1000/default type=STREAM

The same is true if the tmux commands are just run manually.

I also tried both services as user instance services which also results in two processes when enabled. This makes me wonder why my tmp.mount workaround works at all. It's definitely not a solution in any case.

Last edited by alphaniner (2015-02-16 04:24:57)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#5 2015-02-19 10:44:30

AlgoJerViA
Member
Registered: 2014-08-06
Posts: 24

Re: Problems with multiple tmux services

I think I finally figured it out. The services are started very much the same time meaning that the second tmux process checks for a socket before the first one has finished creating it. Right know I simply added rt@.service to irssis After line but that is of course not good practice at all. I guess the best way would be to have a separate tmux service starting the server and then make anything else connect to that.

Offline

Board footer

Powered by FluxBB