Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mpDris2-remote.service, --abort-on-disconnect flag #165

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ dist_desktop_DATA = mpdris2.desktop
autostart_DATA = mpdris2.desktop
dist_doc_DATA = mpDris2.conf
nodist_dbus_DATA = org.mpris.MediaPlayer2.mpd.service
nodist_systemd_user_DATA = mpDris2.service
nodist_systemd_user_DATA = mpDris2.service mpDris2-remote.service

EXTRA_DIST = \
org.mpris.MediaPlayer2.mpd.service.in \
mpDris2.service.in \
mpDris2-remote.service.in \
mpDris2.in.py

CLEANFILES = \
org.mpris.MediaPlayer2.mpd.service \
mpDris2.service \
mpDris2-remote.service \
mpDris2

edit = sed -e 's|@bindir[@]|$(bindir)|g' \
Expand All @@ -29,8 +31,6 @@ mpDris2: mpDris2.in.py Makefile
$(AM_V_GEN) $(edit) $< > [email protected] && mv [email protected] $@
$(AM_V_at) chmod a+x $@

org.mpris.MediaPlayer2.mpd.service: org.mpris.MediaPlayer2.mpd.service.in Makefile
%.service: %.service.in Makefile
$(AM_V_GEN) $(edit) $< > [email protected] && mv [email protected] $@

mpDris2.service: mpDris2.service.in Makefile
$(AM_V_GEN) $(edit) $< > [email protected] && mv [email protected] $@
14 changes: 14 additions & 0 deletions src/mpDris2-remote.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=mpDris2 - Music Player Daemon D-Bus bridge
Conflicts=mpDris2.service

[Service]
Restart=on-failure
RestartSec=5
RestartMaxDelaySec=15min
RestartSteps=20
ExecStart=@bindir@/mpDris2 --use-journal --no-reconnect --abort-on-disconnect
BusName=org.mpris.MediaPlayer2.mpd

[Install]
WantedBy=default.target
36 changes: 25 additions & 11 deletions src/mpDris2.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'password': None,
'bus_name': None,
'reconnect': True,
'clean_exit': True,
# Library
'music_dir': '',
'cover_regex': None,
Expand Down Expand Up @@ -244,6 +245,7 @@ def __init__(self, params):
self._params = params
self._dbus_service = None
self._should_reconnect = params['reconnect']
self._disconnect_exit_code = 0 if params['clean_exit'] else 1

self._can_single = False
self._can_idle = False
Expand Down Expand Up @@ -271,11 +273,16 @@ def __init__(self, params):

def run(self):
"""
Try to connect to MPD; retry every 5 seconds on failure.
Try to connect to MPD
"""
if self.my_connect():
GLib.timeout_add_seconds(5, self.my_connect)
return False
if self._should_reconnect:
GLib.timeout_add_seconds(5, self.my_connect)
return False
else:
logger.debug("Initial connect failed. Not retrying.")
loop.quit()
sys.exit(self._disconnect_exit_code)
else:
return True

Expand Down Expand Up @@ -447,6 +454,7 @@ def handle_disconnect():
else:
logger.debug("Not reconnecting, quitting main loop")
loop.quit()
sys.exit(self._disconnect_exit_code)
return True

if event & GLib.IO_HUP:
Expand Down Expand Up @@ -1379,15 +1387,19 @@ def usage(params):
print("""\
Usage: %(progname)s [OPTION]...

-c, --config=PATH Read a custom configuration file
-c, --config=PATH Read a custom configuration file

-h, --host=ADDR Set the mpd server address
--port=PORT Set the TCP port
--music-dir=PATH Set the music library path
-h, --host=ADDR Set the mpd server address
--port=PORT Set the TCP port
--music-dir=PATH Set the music library path

-d, --debug Run in debug mode
-j, --use-journal Log to systemd journal instead of stderr
-v, --version mpDris2 version
-d, --debug Run in debug mode
-j, --use-journal Log to systemd journal instead of stderr
--no-reconnect Don't attempt to reconnect automatically,
just exit on disconnect.
--abort-on-disconnect Exit abnormally when disconnected. Use
with --no-reconnect.
-v, --version mpDris2 version

Environment variables MPD_HOST and MPD_PORT can be used.

Expand All @@ -1412,7 +1424,7 @@ def usage(params):
['help', 'bus-name=', 'config=',
'debug', 'host=', 'music-dir=',
'use-journal', 'path=', 'port=',
'no-reconnect',
'no-reconnect', 'abort-on-disconnect',
'version'])
except getopt.GetoptError as ex:
(msg, opt) = ex.args
Expand Down Expand Up @@ -1441,6 +1453,8 @@ def usage(params):
params['port'] = int(arg)
elif opt in ['--no-reconnect']:
params['reconnect'] = False
elif opt in ['--abort-on-disconnect']:
params['clean_exit'] = False
elif opt in ['-v', '--version']:
v = __version__
if __git_version__:
Expand Down
1 change: 1 addition & 0 deletions src/mpDris2.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=mpDris2 - Music Player Daemon D-Bus bridge
After=mpd.service
BindsTo=mpd.service
Conflicts=mpDris2-remote.service

[Service]
Restart=on-failure
Expand Down