| 1 |
#!/usr/bin/python3 |
| 2 |
# GPL. (C) 2007-2009 Paolo Patruno. |
| 3 |
|
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
# |
| 18 |
|
| 19 |
from autoradio import daemon |
| 20 |
import autoradio.settings |
| 21 |
|
| 22 |
dbusd = daemon.Daemon( |
| 23 |
stdin="/dev/null", |
| 24 |
stdout=autoradio.settings.logfiledbus, |
| 25 |
stderr=autoradio.settings.errfiledbus, |
| 26 |
pidfile=autoradio.settings.lockfiledbus, |
| 27 |
user=autoradio.settings.userdbus, |
| 28 |
group=autoradio.settings.groupdbus |
| 29 |
) |
| 30 |
|
| 31 |
def main(self): |
| 32 |
|
| 33 |
import subprocess |
| 34 |
|
| 35 |
busaddress = autoradio.settings.busaddressplayer |
| 36 |
|
| 37 |
|
| 38 |
if busaddress is not None: |
| 39 |
|
| 40 |
self.procs=[subprocess.Popen(["dbus-daemon", "--config-file="+autoradio.settings.conffiledbus, |
| 41 |
'--address='+busaddress, "--nofork"],cwd=self.cwd)] |
| 42 |
else: |
| 43 |
print ("busaddress is not defined in config file: dbus-daemon not started") |
| 44 |
|
| 45 |
if __name__ == '__main__': |
| 46 |
|
| 47 |
import sys, os |
| 48 |
dbusd.cwd=os.getcwd() |
| 49 |
|
| 50 |
if dbusd.service(): |
| 51 |
|
| 52 |
sys.stdout.write("Daemon started with pid %d\n" % os.getpid()) |
| 53 |
sys.stdout.write("Daemon stdout output\n") |
| 54 |
sys.stderr.write("Daemon stderr output\n") |
| 55 |
|
| 56 |
main(dbusd) # (this code was run as script) |
| 57 |
|
| 58 |
for proc in dbusd.procs: |
| 59 |
proc.wait() |
| 60 |
|
| 61 |
sys.exit(0) |
| 62 |
|
| 63 |
|