LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-15-2015, 10:17 AM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 508

Rep: Reputation: 29
Reading a tutorial on systemd...just dont understand this


Hi guys,

was reading a tutorial from archwiki on systemd...

Then read this:

"Note: Some unit names contain an @ sign (e.g. name@string.service): this means that they are instances of a template unit, whose actual file name does not contain the string part (e.g. name@.service). string is called the instance identifier, and is similar to an argument that is passed to the template unit when called with the systemctl command: in the unit file it will substitute the %i specifier.
To be more accurate, before trying to instantiate the name@.suffix template unit, systemd will actually look for a unit with the exact name@string.suffix file name, although by convention such a "clash" happens rarely, i.e. most unit files containing an @ sign are meant to be templates. Also, if a template unit is called without an instance identifier, it will just fail, since the %i specifier cannot be substituted.

I just dont understand the practical application of this...

can anybody help me clear this up...?
 
Old 11-15-2015, 10:29 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885
You can use this to start a specific service for different users or with different options. For example, this can be used to start a tmux session at boot for different users, using this template:
Code:
[Unit]
Description=Start tmux in detached session

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

[Install]
WantedBy=multi-user.target
When this template is saved as /etc/systemd/system/tmux@.service you can use
Code:
systemctl enable tmux@tobi.service
to start a tmux session for my user on boot. This is of course not limited to different users, it can be used to start different systemd-nspawn containers at boot, basically anything you can think of that benefits from specifying an option to a template.
 
Old 11-15-2015, 12:11 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 3,966

Rep: Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210Reputation: 1210
Systemd could have used an existing method, such as an argument:

Code:
systemctl enable tmux.service tobi
or a parameterized call:

Code:
systemctl enable tmux.service %i=tobi
or an environment variable:

Code:
USER=tobi systemctl enable tmux.service
but it is more in keeping with systemd's style to invent a new and unfamiliar mechanism which also creates an unexpected dependency between filenames and arguments. Also, unlike the more familiar methods, systemd's instance name cannot be extended to multiple arguments.
 
3 members found this post helpful.
Old 11-15-2015, 01:30 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885
Quote:
Originally Posted by smallpond View Post
Systemd could have used an existing method, such as an argument:

Code:
systemctl enable tmux.service tobi
or a parameterized call:

Code:
systemctl enable tmux.service %i=tobi
or an environment variable:

Code:
USER=tobi systemctl enable tmux.service
but it is more in keeping with systemd's style to invent a new and unfamiliar mechanism which also creates an unexpected dependency between filenames and arguments. Also, unlike the more familiar methods, systemd's instance name cannot be extended to multiple arguments.
Do you have anything meaningful to contribute or are you just here for ranting?
 
Old 11-15-2015, 09:49 PM   #5
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
Quote:
Do you have anything meaningful to contribute or are you just here for ranting?
My guess is just ranting.

Thank you for the explanation, I didn't have any understanding of systemd templates until I read your post.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I dont understand this! zeldafanfreak Linux - Hardware 1 08-12-2005 02:52 PM
i dont really understand this. Brain Drop General 3 08-18-2003 08:54 PM
i dont understand!!!! Fathonkey Linux - Software 17 05-29-2003 11:37 AM
Dont Understand Sifvion Slackware 27 03-26-2003 01:49 PM
Things dont work when you dont understand withoutaclue Linux - Newbie 3 03-12-2003 09:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration