ebaauw / homebridge-music

Homebridge plugin for iTunes with AirPlay speakers
Apache License 2.0
92 stars 7 forks source link

Homebridge running in Background #2

Closed beatpaul closed 6 years ago

beatpaul commented 6 years ago

Hi! When installing your music app i cannot run home bridge in the background any more using

launchctl load ~/Library/LaunchAgents/com.homebridge.server.plist

do u have nay suggestion how to solve this ?

(im not a programmer and would be very happy about some kind of instructions) (by the way: your homebred hue plugin is fantastic :)

paul

ebaauw commented 6 years ago

homebridge-music uses Applescript to communicate with iTunes. I think that only runs in a login session, as it basically emulates user actions. I don’t think I ever tried to run it as a service. What errors do you get?

beatpaul commented 6 years ago

Here ist my Log and Errorlog

logfile.log logfile_error.log

would be great tu run as service or is there another way to restart homebridge after a crash so it keeps running ?

ebaauw commented 6 years ago

I don't think your issue is related to homebridge-music. I setup homebridge as a launch agent on my MacBook Pro, and homebridge-music works as expected. I use the following ~/Librarry/LaunchAgents/org.nodejs.homebridge.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
        <false/>
    <key>KeepAlive</key>
        <true/>
    <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
                <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin</string>
        </dict>
        <key>Label</key>
                <string>org.nodejs.homebridge</string>
        <key>ProgramArguments</key>
                <array>
                        <string>/usr/local/bin/homebridge</string>
                </array>
    <key>WorkingDirectory</key>
        <string>/Users/ebaauw/.homebridge</string>
    <key>StandardErrorPath</key>
        <string>/Users/ebaauw/.homebridge/homebridge.log</string>
    <key>StandardOutPath</key>
        <string>/Users/ebaauw/.homebridge/homebridge.log</string>
</dict>
</plist>

Looking at your error log:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: spawn osascript ENOENT
    at _errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

ENOENT is a file not found error. I think nodejs fails to find the osascript executable, which is used by homebridge-music (through the applescript library) to execute AppleScript. On my macbook (macOS 10.13.4), osascript is in /usr/bin. There maybe something wrong with the PATH setting in your .plist file. If you run homebridge in a chroot-ed environment, make sure to include /usr/bin/osascript in the new root.

beatpaul commented 6 years ago

Works in the background now! I am using your launchagent file so probably it was a pathproblem as youexpected.

One more question: Play/pause music with the switch only works if once done manually in itunes, any idea about that?

ebaauw commented 6 years ago

Did you set a track in config.json?

beatpaul commented 6 years ago

no i did't set a Track, (I will try this when home again)

Would there also be a possibility to set a certain playlist as default?

thx for your help!

beatpaul commented 6 years ago

I set a Track now and it works perfect after restart from the beginning --> thx for advice!