Skip to content

Instantly share code, notes, and snippets.

@TehPeGaSuS
Last active May 30, 2023 15:53
Show Gist options
  • Save TehPeGaSuS/d270f31d49a24f13728cc07978520788 to your computer and use it in GitHub Desktop.
Save TehPeGaSuS/d270f31d49a24f13728cc07978520788 to your computer and use it in GitHub Desktop.
WeeChat Systemd User Units for screen and tmux

Tested on Ubuntu 20.04+

This files are to be used with systemd.

NOTE: Make sure to have screen or tmux installed in your machine .
You can check if you have screen or tmux installed with the command whereis screen or whereis tmux.
If you terminal returns no output with paths, then you need to install one of them or ask the system admin to install it for you.

ENABLE LINGERING

To be ran as the user, so it doesn't require root

  • You need to enable lingering for your user with the following command:
    loginctl enable-linger

  • Create the ~/.config/systemd/user/ folder with the following command:
    mkdir -p ~/.config/systemd/user/

DOWNLOAD THE PROPER FILE

  • Go to the recently created directory with cd ~/.config/systemd/user/ and download weechat_screen.service or weechat_tmux.service with one of the following commands:

    • SCREEN
      wget https://gist.githubusercontent.com/PeGaSuS-Coder/d270f31d49a24f13728cc07978520788/raw/weechat_screen.service

    • TMUX
      wget https://gist.githubusercontent.com/PeGaSuS-Coder/d270f31d49a24f13728cc07978520788/raw/weechat_tmux.service

  • Use SYSTEMD CONTROL COMMANDS below to manage your instance

  • Basic screen and tmux usage are explained here

  • Useful extras can be found here

SYSTEMD CONTROL COMMANDS

  • To start an instance:

    • SCREEN
      systemctl --user start weechat_screen.service

    • TMUX
      systemctl --user start weechat_tmux.service

  • To stop an instance:

    • SCREEN
      systemctl --user stop weechat_screen.service

    • TMUX
      systemctl --user stop weechat_tmux.service

  • To restart an instance (after an upgrade, e.g):

    • SCREEN
      systemctl --user restart weechat_screen.service

    • TMUX
      systemctl --user restart weechat_tmux.service

  • To enable a systemd user unit so it starts after a crash or a machine reboot:

    • SCREEN
      systemctl --user enable weechat_screen.service

    • TMUX
      systemctl --user enable weechat_tmux.service

BASIC SESSION USAGE

SCREEN

  • To attach to a screen session:
    screen -dr weechat

  • To detach from a screen session:
    CTRL+A-D

TMUX

  • To attach to a tmux session:
    tmux attach -t weechat

  • To detach from a tmux session:
    CTRL+B-D

EXTRA

  • For proper colour handling by screen or tmux, be sure to have ~/.screenrc or ~/.tmux.conf with the following contents:
    • ~/.screenrc
      term screen-256color

    • ~/.tmux.conf
      set -g default-terminal "tmux-256color"

#############################
# WeeChat Systemd User Unit #
#############################
[Unit]
Description=Weechat Session (screen)
After=default.target
[Service]
Type=forking
ExecStart=/usr/bin/screen -dmSU weechat /usr/local/bin/weechat
ExecStop=/usr/bin/screen -XS weechat quit
Restart=on-failure
[Install]
WantedBy=default.target
#############################
# WeeChat Systemd User Unit #
#############################
[Unit]
Description=Weechat Session (tmux)
[Service]
Type=forking
ExecStart=/usr/bin/tmux -2 new-session -d -s weechat /usr/local/bin/weechat
ExecStop=/usr/bin/tmux kill-session -t weechat
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment