[LINUX] How to pass arguments using an instance with systemd's systemctl command

I will show you how to pass arguments using an instance with the systemctl command.

environment

1. Create a Unit definition file

Create the following Unit definition file.

/etc/systemd/system/[email protected]


[Unit]
Description=TestService

[Service]
ExecStart=/bin/echo %I

2. Start by specifying the argument (instance name) with the systemctl command

systemctl start [email protected]"arg1 arg2"

[[email protected] ~]# systemctl start [email protected]"arg1 arg2"
[[email protected] ~]#

Check with journalctl -u test @" arg1 arg2 ".

[[email protected] ~]# journalctl -u [email protected]"arg1 arg2"
--Logs begin at day 2019-12-29 17:19:15 JST,end at day 2019-12-29 20:06:21 JST.
December 29 20:06:21 CENTOS7 systemd[1]: Started TestService.
December 29 20:06:21 CENTOS7 echo[1602]: arg1 arg2

reference

The unit specifiers that are replaced when the unit file is loaded are:

Unit specifier meaning Details
%n Full unit name
%N Full unit name (no escape) %Same as n, but the string is not escaped.
%p prefix In the unit name that became an instance"@"Refer to the character string before the character.
For other units, the unit name without the suffix is used.
%P Prefix (no escape) %Same as p, but the string is not escaped.
%i Instance name Of the unit name that became an instance"@"Use the string between the character and the suffix.
%I Instance name(No escape) %Same as i, but the string is not escaped.
%f file name(No escape) Unescaped instance name.
%c Unit control group This group name has/sys/fs/cgroup/systemd/Does not include the prefix.
%r Control group parent group path "%c"The parent cgroup path of is used.
%R Route control group path where slices and units are placed For system instances, "/"become.
In the case of a container, use the root control group path of the container.
%t Runtime directory /run or$XDG_RUNTIME_DIR is used.
%u User name マネージャーを実行しているユーザのUser nameが使用される。
Usually root.
%U User UID マネージャーを実行しているUser UIDが使用される。
0 is used for system administrators.
%h User's home directory マネージャーを実行しているUser's home directoryが指定される。
If you are a system administrator,/"root" is used.
%s User's shell The shell used by the service manager.
If you are a system administrator,/bin/sh "is used.
%m Machine ID システムのMachine ID。
%b Boot ID System boot ID.
%H hostname ユニットがロードされた時点でのシステムhostname。
%v Release version of kernel 「uname -Use the character string that can be obtained from the output of "r".

that's all

Recommended Posts

How to pass arguments using an instance with systemd's systemctl command
[Python / Tkinter] How to pass arguments to command
"How to pass PATH" to learn with homebrew
How to use CUT command (with sample)
How to receive command line arguments in Python
Let's understand how to pass arguments (Python version)
How to crop an image with Python + OpenCV
How to deal with SessionNotCreatedException when using Selenium
How to read an array with Python's ConfigParser
How to create an article from the command line
How to write a GUI using the maya command
How to delete the specified string with the sed command! !! !!
How to pass args or environment variables with Makefile and make command on #Linux
How to make an HTTPS server with Go / Gin
How to pass arguments when invoking python script from blender on the command line
How to deploy a Go application to an ECS instance
Execute Python function from Powershell (how to pass arguments)
How to analyze with Google Colaboratory using Kaggle API
How to execute a command using subprocess in Python
How to create an instance of a particular class from dict using __new__ () in python
How to return to the previous directory with the Bash cd command
How to convert an array to a dictionary with Python [Application]
How to not load images when using PhantomJS with Selenium
How to manipulate the DOM in an iframe with Selenium
How to resolve CSRF Protection when using AngularJS with Django
How to specify command line arguments when debugging in PyCharm
How to run an app built with Python + py2app built with Anaconda
[Python Kivy] How to create an exe file with pyinstaller
How to update FC2 blog etc. using XMLRPC with python
How to read an Excel file (.xlsx) with Pandas [Python]
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to Delete with SQLAlchemy?
How to execute the sed command many times using the for statement
How to paste a CSV file into an Excel file using Pandas
How to pass arguments to a Python script in SPSS Modeler Batch
How to make a command to read the configuration file with pyramid
How to create a heatmap with an arbitrary domain in Python
[Python] Explains how to use the format function with an example
How to monitor the execution status of sqlldr with the pv command
How to use an external editor for Python development with Grasshopper
When you want to send an object with requests using flask
How to use Python with Jw_cad (Part 2 Command explanation and operation)
How to install python using anaconda
Python: How to use async with
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to deal with imbalanced data
How to use MBDyn (command setting)
How to get started with Scrapy
How to get started with Python
How to deal with DistributionNotFound errors
How to get started with Django
How to Data Augmentation with PyTorch
How to use FTP with Python
Using cgo with the go command
Pass arguments to Task in discord.py