You are not logged in.

#1 2013-05-04 13:45:24

morfik
Member
Registered: 2013-03-14
Posts: 22

How to restart pulseaudio via systemd?

As my sound is not working well after hibernation, I tried to use systemd to kill pulseaudio while my pc fall asleep and to start it when my pc wakes up. But I can't do this. Following the archwiki, I made to .service files:

root:/etc/systemd/system# cat suspend@.service 
[Unit]
Description=User suspend actions
Before=sleep.target 

[Service]
User=%I
Environment=DISPLAY=:0
Type=oneshot
ExecStart= /usr/bin/pulseaudio -k
ExecStart= /usr/bin/xscreensaver-command --lock

[Install]
WantedBy=sleep.target

and

root:/etc/systemd/system# cat resume@.service
[Unit]
Description=User resume actions
After=suspend.target

[Service]
User=%I
Environment=DISPLAY=:0
Type=oneshot
ExecStart= /usr/bin/start-pulseaudio-x11

[Install]
WantedBy=suspend.target

Next, I enabled them:

root:/etc/systemd/system# systemctl enable resume@morfik.service 
ln -s '/etc/systemd/system/resume@.service' '/etc/systemd/system/suspend.target.wants/resume@morfik.service'
root:/etc/systemd/system# systemctl enable suspend@morfik.service 
ln -s '/etc/systemd/system/suspend@.service' '/etc/systemd/system/sleep.target.wants/suspend@morfik.service'

I rebooted the system, but this doesn't work. This is what I got when I had started the suspend service.

root:/etc/systemd/system# systemctl start suspend@morfik.service
Job for suspend@morfik.service failed. See 'systemctl status suspend@morfik.service' and 'journalctl -xn' for details.
root:/etc/systemd/system# systemctl status suspend@morfik.service
suspend@morfik.service - User suspend actions
   Loaded: loaded (/etc/systemd/system/suspend@.service; enabled)
   Active: failed (Result: exit-code) since Tue 2013-04-30 23:09:08 CEST; 14s ago
  Process: 5186 ExecStart=/usr/bin/pulseaudio -k (code=exited, status=1/FAILURE)

Apr 30 23:09:08 morfina pulseaudio[5186]: E: [pulseaudio] main.c: Failed to kill daemon: No such process
Apr 30 23:09:08 morfina systemd[1]: suspend@morfik.service: main process exited, code=exited, status=1/FAILURE
Apr 30 23:09:08 morfina systemd[1]: Failed to start User suspend actions.
Apr 30 23:09:08 morfina systemd[1]: MESSAGE=Unit suspend@morfik.service entered failed state.
root:/etc/systemd/system# journalctl -xn
-- Logs begin at Sun 2013-04-28 00:14:17 CEST, end at Tue 2013-04-30 23:09:08 CEST. --
Apr 30 23:09:08 morfina systemd[1]: Starting User suspend actions...
-- Subject: Unit suspend@morfik.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit suspend@morfik.service has begun starting up.
Apr 30 23:09:08 morfina pulseaudio[5186]: E: [pulseaudio] main.c: Failed to kill daemon: No such process
Apr 30 23:09:08 morfina systemd[1]: suspend@morfik.service: main process exited, code=exited, status=1/FAILURE
Apr 30 23:09:08 morfina systemd[1]: Failed to start User suspend actions.
-- Subject: Unit suspend@morfik.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/catalog/be02cf6855d2428ba40df7e9d022f03d
-- 
-- Unit suspend@morfik.service has failed.
-- 
-- The result is failed.
Apr 30 23:09:08 morfina systemd[1]: MESSAGE=Unit suspend@morfik.service entered failed state.

The most important part:

pulseaudio[5186]: E: [pulseaudio] main.c: Failed to kill daemon: No such process

I don't know why this happens. Pulse demon exists, but systemd cannot kill it because it thinks there is no such process.

root:/etc/systemd/system# ps -eo "user args" | grep pulse
morfik   /usr/bin/pulseaudio --start
morfik   /usr/lib/pulse/gconf-helper
root     grep --color=auto pulse

I can kill pulse in terminal as normal user though.

morfik:~$ /usr/bin/pulseaudio -k
root:/etc/systemd/system# ps -eo "user args" | grep pulse
root     grep --color=auto pulse

The same with resume@.service

root:/etc/systemd/system# systemctl start resume@morfik.service
root:/etc/systemd/system# systemctl status resume@morfik.service
resume@morfik.service - User resume actions
   Loaded: loaded (/etc/systemd/system/resume@.service; enabled)
   Active: inactive (dead) since Tue 2013-04-30 23:32:09 CEST; 2s ago
  Process: 7183 ExecStart=/usr/bin/start-pulseaudio-x11 (code=exited, status=0/SUCCESS)

Apr 30 23:32:06 morfina systemd[1]: Starting User resume actions...
Apr 30 23:32:06 morfina pulseaudio[7187]: [pulseaudio] sink.c: Default and alternate sample rates are the same.
Apr 30 23:32:06 morfina pulseaudio[7187]: [pulseaudio] source.c: Default and alternate sample rates are the same.
Apr 30 23:32:09 morfina systemd[1]: Started User resume actions.

But there is no such process.

I tried to start pulse demon using:

/usr/bin/pulseaudio -D
/usr/bin/pulseaudio --start
/usr/bin/start-pulseaudio-x11

and everything goes smooth while I'm doing it as a normal user in a terminal, but when I try to put it into systemd service file, everything starts to break.

Offline

Board footer

Powered by FluxBB