systemd has ability to manage user units. all the user units will be placed in ~/.config/systemd/user/. this service autostarts screen:
~/.config/systemd/user/screen.service
[Unit]
Description=GNU screen
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/screen -DmS autoscreen -c ~/.screenrc_auto
ExecStop=/usr/bin/screen -S autoscreen -X quit
[Install]
WantedBy=default.targetscreen options on start:
-D -m Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-S sessionname When creating a new session, this option can be used to specify a meaningful name for the session.
-c file override the default configuration file from $HOME/.screenrc to file.
-X Send the specified command to a running screen session.
service needs to be enabled:
[user@host ~]$ systemctl --user enable screen.service
Created symlink '/home/user/.config/systemd/user/default.target.wants/screen.service' → '/home/user/.config/systemd/user/screen.service'.if user is not auto loggged in after a reboot, then the service will not start. to avoid this, lingering has to be enabled:
[user@host ~]$ loginctl enable-linger
[user@host ~]$ loginctl list-users
UID USER LINGER STATE
1000 user yes active
1 user listed.to autostart favorite apps after the screen service start, we need a screenrc configuration file:
~/.screenrc_auto
screen -t irc 0 weechat
screen -t mc 1 mc
screen -t process 2 htop
screen -t bash 3reboot or start the service:
[user@host ~]$ systemctl --user enable screen.serviceto attach to running screen sessions, use this command:
[user@host ~]$ screen -xif your host is remote and you want to attach to screen immediately after ssh, then you need to add '-t' option:
[user@local ~]$ ssh -t user@remote screen -x-t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services.
common screen commands:
Ctrl+a?Displays commands and their defaultsCtrl+a:Enter to the command prompt of screenCtrl+a"Window listCtrl+a0opens window 0Ctrl+aARename the current windowCtrl+aaSendsCtrl+ato the current windowCtrl+acCreate a new window (with shell)Ctrl+ak,Ctrl+aCtrl+kDestroy current window.Ctrl+aSSplit current region horizontally into two regionsCtrl+a|Split current region vertically into two regionsCtrl+atabSwitch the input focus to the next regionCtrl+aCtrl+aToggle between current and previous regionCtrl+a[Enter Copy Mode (use enter to select a range of text)Ctrl+a]Paste textCtrl+aQClose all regions but the current oneCtrl+aXClose the current regionCtrl+adDetach from the current screen session, and leave it running. Usescreen -rto resume
Comments