usage question

42 views
Skip to first unread message

Oblio Leitch

unread,
Sep 7, 2020, 12:48:17 AM9/7/20
to tmux-...@googlegroups.com
I'd like to create a new session, multi-user (shared socket), give it a command and detach all at once.  However I'm not sure how to go about that.  I have the socket set up, and my syntax looks like this:

tmux -S /tmp/tmux/shared new -d 'command-to-run'

The trouble is, it does not persist - there's no sessions running.  I'm not sure how to go about this.

Thanks

Nicholas Marriott

unread,
Sep 7, 2020, 12:49:27 AM9/7/20
to Oblio Leitch, tmux-users
You could try adding ";sleep 1000" to your command and you should be able to attach and see if it is reporting an error message.

--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/CAHxWh4bJJGVY-i%2Bsf8DEYrA%2Bj5U1vQ3A0hnhwpJLHotfWhs9tw%40mail.gmail.com.

Oblio Leitch

unread,
Sep 7, 2020, 6:52:40 AM9/7/20
to tmux-users
So detached sessions have to be actively executing something or they're closed?  What if I just did tmux -S /tmp/tmux/shared new -d 'll'?

Nicholas Marriott

unread,
Sep 7, 2020, 6:53:57 AM9/7/20
to Oblio Leitch, tmux-users
Unless you turn remain-on-exit on, then there needs to be a running command in each pane. A session must have at least one pane (ie at least one window).

Oblio Leitch

unread,
Sep 7, 2020, 9:08:43 AM9/7/20
to tmux-users
Then, I'm not clear why tmux new -d -s mySession persists a detached session; it doesn't have any commands in it.

Nicholas Marriott

unread,
Sep 7, 2020, 9:09:59 AM9/7/20
to Oblio Leitch, tmux-users
if you don't give a command, tmux will start a shell

creating a session with -d is no different from creating it without except it does not attach

Oblio Leitch

unread,
Sep 7, 2020, 10:36:48 AM9/7/20
to tmux-users
Ok, so tmux new -d -s mySession is the same as tmux new -d -s mySession /bin/bash. And the bash command is running, but in a wait state.  Whereas, the example of ll executed and exit, but because it was not in a shell, didn't have a running command to fall back to.

The reason I'm asking is because I want to launch a command in a shared session on system start up so that it's running in the background, "owned" by one user, but accessible to others. I'm using systemd, and I have a service setup, but it's not working.  Do you know of any reason ExecStart=/usr/bin/tmux new -d -s mySession /bin/bash would not persist?  (I know this isn't multi user, I'm just looking to get a working example)

Nicholas Marriott

unread,
Sep 7, 2020, 10:59:40 AM9/7/20
to Oblio Leitch, tmux-users
Does it actually run? Try eg "tmux new 'date >/tmp/x; sleep 1000'" and see if it adds to the file.

Are you sure it is running as the user you think it is?




--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.

Oblio Leitch

unread,
Sep 7, 2020, 12:12:36 PM9/7/20
to tmux-users
No, it looks like if I do ExecStart=/usr/bin/tmux new -d 'date > /tmp/x; sleep 1000' it does not create the file.  If I leave off the -d I get "not a terminal".  When things do run, I'm sure that it's the user I expect.

Nicholas Marriott

unread,
Sep 7, 2020, 12:14:14 PM9/7/20
to Oblio Leitch, tmux-users
If you run something else instead of tmux, does it work?



Oblio Leitch

unread,
Sep 7, 2020, 2:17:00 PM9/7/20
to tmux-users
Ok, I think I figured it out.  I added Type=forking to the service stanza and now the session is persisting.  

Oblio Leitch

unread,
Sep 7, 2020, 2:34:53 PM9/7/20
to tmux-users
Now, when I stop the program running inside the session, it closes the session which stops the server.  Since this is being watched by the systemd service manager, it thinks there was an error (Control process exited, code=exited status=1).  Is there a graceful way to exit?  You said I could launch within a shell and that would drop back, but I think I actually want it to exit.

Nicholas Marriott

unread,
Sep 7, 2020, 2:40:50 PM9/7/20
to Oblio Leitch, tmux-users
What do you mean? All ways to exit tmux are the same.


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages