You are not logged in.

#1 2015-04-12 18:34:49

Jason P.
Member
Registered: 2015-02-26
Posts: 171

[SOLVED] Unable to start tmux at boot as a systemd user service

I'm starting to play with tmux. So far I've read the Arch Wiki article and added a few settings in my ~/.tmux.conf

## Prefix is Ctrl-a
unbind C-b
set -g prefix C-a
bind C-a send-prefix

## Set scrollback buffer
set -g history-limit 10000

## Set the default TERM
set -g default-terminal screen

## Update the TERM variable of terminal emulator when creating a new session or attaching a existing session
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY TERM'

## Determine if we should enable 256-colour support
if "[[ ${TERM} =~ 256color || ${TERM} == fbterm ]]" 'set -g default-terminal screen-256color'

## Copy tmux paste buffer to CLIPBOARD
bind C-c run "tmux show-buffer | xsel -i -b"

## Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind C-v run "tmux set-buffer -- \"$(xsel -o -b)\"; tmux paste-buffer"

## Mouse works as expected
setw -g mode-mouse on
set -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-select-window on

I've also made a unit file as the mentioned article suggests because my intention is to run a detached session of tmux in every boot.

~/.config/systemd/user/tmux.service

[Unit]
Description=Start tmux in detached session

[Service]
Type=forking
ExecStart=/usr/bin/tmux new-session -s %u -d
ExecStop=/usr/bin/tmux kill-session -t %u

[Install]
WantedBy=multi-user.target

The problem arises when in enable the service like: systemctl --user enable tmux.service. In the next boot there is no active session (checked with tmux ls) and systemd reports the unit as not loaded (systemctl --user status tmux.service).

But, if I started it manually like systemctl --user start tmux.service, everything goes fine. Any ideas?

I've also read this other topic that is somewhat related to my problem.

Last edited by Jason P. (2015-04-12 21:37:22)

Offline

#2 2015-04-12 19:09:34

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

Enabling that service with that [Install] section created a symlink, right? So when you start multi-user.target, tmux.service will also be started. The thing is, there is no multi-user.target for your user instance of systemd, unless you created one.

If you haven't set up any other targets, you can use default.target instead.

Offline

#3 2015-04-12 19:23:40

Jason P.
Member
Registered: 2015-02-26
Posts: 171

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

Enabling that service with that [Install] section created a symlink, right?

Yep. There is a symlink to tmux.service inside ~/.config/systemd/user/multi-user.target

If you haven't set up any other targets, you can use default.target instead.

I was thinking that when I log in as my regular user through gdm I was actually reaching multi-user.target. I mean, the system is supposed to be multi seat ready. It seems I get it the wrong way:

multi-user.target
A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical.target.

Offline

#4 2015-04-12 20:03:44

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

Jason P. wrote:

It seems I get it the wrong way:

multi-user.target
A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical.target.

That seems to be from the man page systemd.special, but it is under SPECIAL SYSTEM UNITS. Further down, there is a (much shorter) list of SPECIAL USER UNITS.

Offline

#5 2015-04-12 21:28:58

Jason P.
Member
Registered: 2015-02-26
Posts: 171

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

I've changed multi-user.target to default.target and the service is started as expected. Cool smile

Maybe this line of the wiki entry about tmux should be clarified:

Alternatively, you can place this file within your systemd/User directory (without User=%I), for example ~/.config/systemd/user/tmux.service. This way the tmux service will start when you log in.

As it is, the unit file doesn't serve for the purpose of starting tmux as a user service.

Offline

#6 2015-04-12 21:30:45

Jason P.
Member
Registered: 2015-02-26
Posts: 171

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

How can I mark the thread as solved?

Offline

#7 2015-04-12 21:32:51

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,744
Website

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

Jason P. wrote:

How can I mark the thread as solved?

Edit the title of the thread & put "[SOLVED]" at the start wink

Offline

#8 2015-04-12 21:46:19

Jason P.
Member
Registered: 2015-02-26
Posts: 171

Re: [SOLVED] Unable to start tmux at boot as a systemd user service

I was looking for an option itself to edit the title. Having to edit the first post is not the most obvious solution I guess.

Anyway, thank you all.

Offline

Board footer

Powered by FluxBB