LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 11:17 AM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 450

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, 11:29 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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, 01:11 PM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
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, 02:30 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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, 10:49 PM   #5
Doug G
Member
 
Registered: Jul 2013
Posts: 595

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 03:52 PM
i dont really understand this. Brain Drop General 3 08-18-2003 09:54 PM
i dont understand!!!! Fathonkey Linux - Software 17 05-29-2003 12:37 PM
Dont Understand Sifvion Slackware 27 03-26-2003 02:49 PM
Things dont work when you dont understand withoutaclue Linux - Newbie 3 03-12-2003 10:51 AM


All times are GMT -5. The time now is 11:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration