Skip to main content
Copy editing (primarily minor formatting)
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

I tried to make use of the properties considered for unit names containing dashes ("-"-) according to the archlinux man pages, and it worked:

Moreover for unit names containing dashes ("-"-), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.servicefoo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/foo-bar-.service.d/ and foo-.service.d/foo-.service.d/.

Along with a unit file foo.servicefoo.service, a "drop-in" directory foo.service.d/foo.service.d/ may exist. All files with the suffix ".conf".conf from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed.

In my working example, this is the final structure of the files at the root of my unit search path (i.e., /etc/systemd/system//etc/systemd/system/):

Also, "dockerdocker.conf"conf and "dockerdocker-a.service"service files are:

  1. Firstly, create a drop-in directory like "dockerdocker-.service.d"d at the root of a unit search path directory (e.g. /etc/systemd/system/etc/systemd/system).
  2. Then, create a ".conf".conf file like "dockerdocker.conf"conf at the created drop-in directory and write your [Unit] and [Service] sections in that file using the %j specifier:

"%j"%j: This is the string between the last "-"- and the end of the prefix name.

  1. After that, create one service file for each of your intended services next to the drop-in directory in the root search path. They should just consist of the [Install] section to explicitly determine their alias name with the Alias option. (I also tried to put this section in the "dockerdocker.conf"conf file too, but the [Install] section could not be found when the services started.) Be careful that the names of these services should satisfy the constraints.
  2. Now, If you run systemctl enable docker-{alias}.service for each created service, you'll be able to control the service just by its {alias}. That's it!

I tried to make use of the properties considered for unit names containing dashes ("-") according to the archlinux man pages, and it worked:

Moreover for unit names containing dashes ("-"), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/ and foo-.service.d/.

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed.

In my working example, this is the final structure of the files at the root of my unit search path (i.e., /etc/systemd/system/):

Also, "docker.conf" and "docker-a.service" files are:

  1. Firstly, create a drop-in directory like "docker-.service.d" at the root of a unit search path directory (e.g. /etc/systemd/system).
  2. Then, create a ".conf" file like "docker.conf" at the created drop-in directory and write your [Unit] and [Service] sections in that file using the %j specifier:

"%j": This is the string between the last "-" and the end of the prefix name.

  1. After that, create one service file for each of your intended services next to the drop-in directory in the root search path. They should just consist of the [Install] section to explicitly determine their alias name with the Alias option. (I also tried to put this section in the "docker.conf" file too, but the [Install] section could not be found when the services started.) Be careful that the names of these services should satisfy the constraints.
  2. Now, If you run systemctl enable docker-{alias}.service for each created service, you'll be able to control the service just by its {alias}. That's it!

I tried to make use of the properties considered for unit names containing dashes (-) according to the archlinux man pages, and it worked:

Moreover for unit names containing dashes (-), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/ and foo-.service.d/.

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix .conf from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed.

In my working example, this is the final structure of the files at the root of my unit search path (i.e., /etc/systemd/system/):

Also, docker.conf and docker-a.service files are:

  1. Firstly, create a drop-in directory like docker-.service.d at the root of a unit search path directory (e.g. /etc/systemd/system).
  2. Then, create a .conf file like docker.conf at the created drop-in directory and write your [Unit] and [Service] sections in that file using the %j specifier:

%j: This is the string between the last - and the end of the prefix name.

  1. After that, create one service file for each of your intended services next to the drop-in directory in the root search path. They should just consist of the [Install] section to explicitly determine their alias name with the Alias option. (I also tried to put this section in the docker.conf file too, but the [Install] section could not be found when the services started.) Be careful that the names of these services should satisfy the constraints.
  2. Now, If you run systemctl enable docker-{alias}.service for each created service, you'll be able to control the service just by its {alias}. That's it!
Source Link

I tried to make use of the properties considered for unit names containing dashes ("-") according to the archlinux man pages, and it worked:

Moreover for unit names containing dashes ("-"), the set of directories generated by repeatedly truncating the unit name after all dashes is searched too. Specifically, for a unit name foo-bar-baz.service not only the regular drop-in directory foo-bar-baz.service.d/ is searched but also both foo-bar-.service.d/ and foo-.service.d/.

and as another note from the man page:

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed.

In my working example, this is the final structure of the files at the root of my unit search path (i.e., /etc/systemd/system/):

│    docker-a.service
│    docker-b.service  
│    docker-c.service
│
└─── docker-.service.d
    │    docker.conf
    │ 
             

Also, "docker.conf" and "docker-a.service" files are:

# /etc/systemd/system/docker-.service.d/docker.conf

[Unit]
Description=We named our service [%j] service
After=network.target

[Service]
WorkingDirectory=/home/arman/%j
ExecStartPre=/bin/bash -c 'echo "The prestart command for %j was done!" >> log.txt'
ExecStart=/bin/bash -c 'echo "The start command for %j was done!" >> log.txt'

# /etc/systemd/system/docker-a.service

[Install]
WantedBy=multi-user.target
Alias=a.service

I did it with the following steps:

  1. Firstly, create a drop-in directory like "docker-.service.d" at the root of a unit search path directory (e.g. /etc/systemd/system).
  2. Then, create a ".conf" file like "docker.conf" at the created drop-in directory and write your [Unit] and [Service] sections in that file using the %j specifier:

"%j": This is the string between the last "-" and the end of the prefix name.

  1. After that, create one service file for each of your intended services next to the drop-in directory in the root search path. They should just consist of the [Install] section to explicitly determine their alias name with the Alias option. (I also tried to put this section in the "docker.conf" file too, but the [Install] section could not be found when the services started.) Be careful that the names of these services should satisfy the constraints.
  2. Now, If you run systemctl enable docker-{alias}.service for each created service, you'll be able to control the service just by its {alias}. That's it!