Headline News
Secure Blackphone starts shipping (June 30, 2014 10:03 am)
Linux Mint KDE reviewed (June 24, 2014 2:06 pm)
Linux Mint 17 “Qiana” KDE released! (June 23, 2014 10:24 am)
7 Improvements The Linux Desktop Needs (June 21, 2014 12:48 am)

Autostart a process on GNU screen with systemd

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. – http://www.gnu.org/software/screen/

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. – http://freedesktop.org/wiki/Software/systemd/

For our purpose, we are gonna target rtorrent as an example of the auto start using systemd.

To install screen on Ubuntu

 sudo apt-get install screen 

To install screen on ArchLinux

 sudo pacman -S screen

We will need to create a file with our desired name of the service on /etc/systemd/system/

sudo YOUREDITOR /etc/systemd/system/rtorrent@.service

Fill the document with:

[Unit]
Description=rTorrent

[Service]
Type=forking
User=USERNAME
ExecStart=/usr/bin/screen -d -m -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 rtorrent
WorkingDirectory=/home/USERNAME

[Install]
WantedBy=multi-user.target

Now that’s just adding the service, we need to enable it so it runs at every boot, notice the ExecStop line, that will kill the rTorrent when the service is going off while ExecStart will start it detached with session name rtorrent.

To enable the service:

sudo systemctl enable rtorrent@.service

As soon as you reboot, rtorrent will be started on a detached screen

gnuscreen

If you want reattach the screen:

screen -R rtorrent

To detach:
Press Control + a then d

We are looking for aspiring bloggers and journalists for The Mukt. If you are interested, apply now!

For further information and examples, check out https://wiki.archlinux.org/index.php/Systemd/Services

Tags
,

1 Comments

  1. Pingback: Links 29/4/2014: New Debian, New Award for Torvalds | Techrights

Leave A Comment