tmux-continuum icon indicating copy to clipboard operation
tmux-continuum copied to clipboard

Run at startup on Ubuntu

Open jclem opened this issue 9 years ago • 6 comments

On Ubuntu 14.04, I'm starting Tmux with the following upstart script at /etc/init/start-tmux.conf:

description "Start Tmux"
start on runlevel [2345]

script
  su myuser -c "tmux new-session -d -s my-default-session-name"
end script

Not sure how you want to present this in your docs, but if someone else could verify that this works for them, as well, that'd be great. Now, I can ssh my-dev-box -t tmux attach and always attach to my Tmux session, even if the box has restarted.

jclem avatar Aug 24 '15 15:08 jclem

Hi, thank you for pasting this code snippet. It would be ideal if we could make this work for ANY linux so users doesn't have to copy-paste stuff around.

Do you know what other systems (?) apart from upstart are used in linux-land? Are there like top 3 solutions for this?

bruno- avatar Aug 31 '15 11:08 bruno-

Looks like systemd is the default for most distributions now. Probably better to work something using that in.

I have no idea how to systemd, but if I figure something out before someone else posts here, I'll post my findings.

On Aug 31, 2015, at 7:55 AM, Bruno Sutic [email protected] wrote:

Hi, thank you for pasting this code snippet. It would be ideal if we could make this work for ANY linux so users doesn't have to copy-paste stuff around.

Do you know what other systems (?) apart from upstart are used in linux-land? Are there like top 3 solutions for this?

— Reply to this email directly or view it on GitHub.

jclem avatar Aug 31 '15 14:08 jclem

I also use Ubuntu 14.04 - which uses upstart by default, but Ubuntu 15.04 has switched to systemd. I haven't tried the script - but it looks to me like it would work on upstart based systems. (But you probably wouldn't want to distribute to users as it won't handle any unusual situations gracefully - e.g. what happens if tmux was already started? what happens if other programs or services that tmux relied on weren't booted themselves yet?).
The whole linux init system and PID 1 (e.g. sysV, upstart or systemd) is unfortunately quite a mess at the moment, where all major distros literally use different versions - slackware even uses its own init system again.
But where things really get messy is the fact that just because a system uses e.g. upstart as the controlling init service - most packages still define their init processes as sysV init scripts - and only a select few important scripts get converted to the new fancy system.
So like most things in Unix like systems - if you wanted the script to work everywhere, you would likely want to write it in the oldest most established system (sysV init) and because the most of the unix world uses them - any new init systems have to (and do) support them.

michael-coleman avatar Nov 21 '15 00:11 michael-coleman

systemd is definitely the way to go. However, I'm (yet) sure how to deal with systemd-logind, as that's the new login manager that monitors sessions, powerbutton events, etc.

In the meantime, a workaround might be to provide a line in ~/.xinitrc and/or a ~/.config/autostart/tmux-start.desktop file with an exec command like:

''' xterm -e tmux new-session -d 'journalctl -fl' ; split-window -h -d ; attach & ''' Alternatively, make the line more "portable" by using xdg-open instead of xterm.

Furthermore, as per the Arch Wiki, cron can/should be used to autostart non-GUI applications.

ILMostro avatar Dec 24 '15 12:12 ILMostro

I just stumbled upon this ArchWiki page that might be of particular interest for creating/using user-specific startup scripts.

ILMostro avatar Dec 24 '15 12:12 ILMostro

We'll soon be merging PR #12 which adds Linux systemd support.

bruno- avatar Dec 26 '15 23:12 bruno-