Skip to contentSkip to conversation

make systemd service start in proper way

PATCH In review [email protected] 2 participants 6 messages Jan 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make systemd service start in proper way

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot
2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
 	$(MKDIR_P) -m 0755 \
-		$(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-	( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+		$(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+	( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
 		rm -f alsa-state.service alsa-restore.service && \
 		$(LN_S) ../alsa-state.service alsa-state.service && \
 		$(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -1
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
Signature · 1 line
2.7.0
#1 lore raw
Quoted 6 lines · On Sun, 24 Jan 2016 01:30:23 +0100, [email protected] wrote:

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

Has this target existed in all released versions of systemd? Just to be sure...

Quoted 2 lines

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot

Actually this should be seen as a bug of alsactl itself. In the daemon mode, it should be allowed to run without the sound card at start.

Quoted 2 lines

2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

... unless reloading or starting the service later.

Quoted 9 lines

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

... or with a hotplug device.

Quoted 2 lines

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

That's superfluous indeed.

thanks,

Takashi

Quoted 49 lines
alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
 	$(MKDIR_P) -m 0755 \
-		$(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-	( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+		$(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+	( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
 		rm -f alsa-state.service alsa-restore.service && \
 		$(LN_S) ../alsa-state.service alsa-state.service && \
 		$(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -1
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
Signature · 1 line
2.7.0
author
#2 lore raw

Since v18:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=88dfa2938af09e511e4911e6984360ded0e2cd8d
http://cgit.freedesktop.org/systemd/systemd/tag/?id=v18

Quoted 96 lines · Takashi Iwai
Quoted 6 lines · On Sun, 24 Jan 2016 01:30:23 +0100, [email protected] wrote:

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

Has this target existed in all released versions of systemd? Just to be sure...

Quoted 2 lines

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot

Actually this should be seen as a bug of alsactl itself. In the daemon mode, it should be allowed to run without the sound card at start.

Quoted 2 lines

2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

... unless reloading or starting the service later.

Quoted 9 lines

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

... or with a hotplug device.

Quoted 2 lines

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

That's superfluous indeed.

thanks,

Takashi

Quoted 49 lines
alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
      $(MKDIR_P) -m 0755 \
-             $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-     ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+             $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+     ( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
              rm -f alsa-state.service alsa-restore.service && \
              $(LN_S) ../alsa-state.service alsa-state.service && \
              $(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -2
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
--

2.7.0

#3 lore raw
Quoted 4 lines · Tom Yan

Since v18:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=88dfa2938af09e511e4911e6984360ded0e2cd8d
http://cgit.freedesktop.org/systemd/systemd/tag/?id=v18

OK, it's old enough, but maybe safer to have some check in configure script?

Takashi

Quoted 99 lines · Takashi Iwai
Quoted 96 lines
Quoted 6 lines · On Sun, 24 Jan 2016 01:30:23 +0100, [email protected] wrote:

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

Has this target existed in all released versions of systemd? Just to be sure...

Quoted 2 lines

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot

Actually this should be seen as a bug of alsactl itself. In the daemon mode, it should be allowed to run without the sound card at start.

Quoted 2 lines

2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

... unless reloading or starting the service later.

Quoted 9 lines

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

... or with a hotplug device.

Quoted 2 lines

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

That's superfluous indeed.

thanks,

Takashi

Quoted 49 lines
alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
      $(MKDIR_P) -m 0755 \
-             $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-     ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+             $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+     ( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
              rm -f alsa-state.service alsa-restore.service && \
              $(LN_S) ../alsa-state.service alsa-state.service && \
              $(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -2
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
--

2.7.0

author
#4 lore raw

How do you think the check should be? The symlinks will just be no-op if sound.target doesn't exist. I'm not gonna introduce some dirty switch to make it fall back to basic.target.wants for systemd<v18.

Quoted 112 lines · Takashi Iwai
Quoted 4 lines · Tom Yan

Since v18:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=88dfa2938af09e511e4911e6984360ded0e2cd8d
http://cgit.freedesktop.org/systemd/systemd/tag/?id=v18

OK, it's old enough, but maybe safer to have some check in configure script?

Takashi

Quoted 99 lines · Takashi Iwai
Quoted 96 lines
Quoted 6 lines · On Sun, 24 Jan 2016 01:30:23 +0100, [email protected] wrote:

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

Has this target existed in all released versions of systemd? Just to be sure...

Quoted 2 lines

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot

Actually this should be seen as a bug of alsactl itself. In the daemon mode, it should be allowed to run without the sound card at start.

Quoted 2 lines

2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

... unless reloading or starting the service later.

Quoted 9 lines

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

... or with a hotplug device.

Quoted 2 lines

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

That's superfluous indeed.

thanks,

Takashi

Quoted 49 lines
alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
      $(MKDIR_P) -m 0755 \
-             $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-     ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+             $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+     ( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
              rm -f alsa-state.service alsa-restore.service && \
              $(LN_S) ../alsa-state.service alsa-state.service && \
              $(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -2
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
--

2.7.0

#5 lore raw
Quoted 4 lines · Tom Yan

How do you think the check should be? The symlinks will just be no-op if sound.target doesn't exist. I'm not gonna introduce some dirty switch to make it fall back to basic.target.wants for systemd<v18.

Well, for example, we may add a check of systemd version in configure script and gives a warning if it's under v18, at least. It's very unlikely that user still runs such an old version, but we still should be careful and need some excuse for dropping the support. And this should be documented explicitly.

thanks,

Takashi

Quoted 114 lines · Takashi Iwai
Quoted 112 lines
Quoted 4 lines · Tom Yan

Since v18:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=88dfa2938af09e511e4911e6984360ded0e2cd8d
http://cgit.freedesktop.org/systemd/systemd/tag/?id=v18

OK, it's old enough, but maybe safer to have some check in configure script?

Takashi

Quoted 99 lines · Takashi Iwai
Quoted 96 lines
Quoted 6 lines · On Sun, 24 Jan 2016 01:30:23 +0100, [email protected] wrote:

From: Tom Yan <[email protected]>

Use sound.target to trigger the service, which is the proper way to start a service related to sound card. This also makes sure that the service will only start if a sound card exists in the system.

Has this target existed in all released versions of systemd? Just to be sure...

Quoted 2 lines

basic.target is too early for either of the service:
1. alsa-state.service will spam "No soundcards found" on every boot

Actually this should be seen as a bug of alsactl itself. In the daemon mode, it should be allowed to run without the sound card at start.

Quoted 2 lines

2. alsa-restore.service will never start because of "ConditionPathExistsGlob=/dev/snd/control*"

... unless reloading or starting the service later.

Quoted 9 lines

"After=sysinit.target" is removed from alsa-state.service because it never made any sense.

"After=alsa-state.service" is removed from alsa-restore.service because it is completely unnecessary with the daemon conf switch.

Now either of serivce is enough to manage the state all by itself without the udev rules if only ONE sound card exists in the system, while the rules are still necessary in system with multiple sound cards.

... or with a hotplug device.

Quoted 2 lines

"StandardOutput=syslog" is also removed from alsa-restore.service because it makes little sense (if it has ever switched the behaviour away from default).

That's superfluous indeed.

thanks,

Takashi

Quoted 49 lines
alsactl/Makefile.am +2 -2
index cac8094..90fab9d 100644
@@ -29,8 +29,8 @@ systemdsystemunit_DATA = \
 
 install-data-hook:
      $(MKDIR_P) -m 0755 \
-             $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants
-     ( cd $(DESTDIR)$(systemdsystemunitdir)/basic.target.wants && \
+             $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants
+     ( cd $(DESTDIR)$(systemdsystemunitdir)/sound.target.wants && \
              rm -f alsa-state.service alsa-restore.service && \
              $(LN_S) ../alsa-state.service alsa-state.service && \
              $(LN_S) ../alsa-restore.service alsa-restore.service)
alsactl/alsa-restore.service.in +0 -3
index 2884098..fbcf983 100644
@@ -6,12 +6,9 @@
 [Unit]
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
-ConditionPathExistsGlob=/dev/snd/control*
-After=alsa-state.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=true
 ExecStart=-@sbindir@/alsactl restore
 ExecStop=-@sbindir@/alsactl store
-StandardOutput=syslog
alsactl/alsa-state.service.in +0 -2
index f1321d6..5a8fe5e 100644
@@ -6,7 +6,6 @@
 [Unit]
 Description=Manage Sound Card State (restore and store)
 ConditionPathExists=@daemonswitch@
-After=sysinit.target
 
 [Service]
 Type=simple
--

2.7.0