BlueBubblesApp / bluebubbles-server

Server for forwarding iMessages to clients within the BlueBubbles App ecosystem
https://bluebubbles.app
Apache License 2.0
554 stars 47 forks source link

auto restart if the server crashes #648

Closed cameronaaron closed 5 months ago

cameronaaron commented 6 months ago

It would be nice if the install created a launch agent that could allow it to restart it when if it crashes

Scr0nch commented 6 months ago

Here is what I did to achieve this:

  1. Copy the following file contents to ~/Library/LaunchAgents/app.bluebubbles.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>Label</key>
            <string>app.bluebubbles</string>
            <key>Program</key>
            <string>/Applications/BlueBubbles.app/Contents/MacOS/BlueBubbles</string>
            <key>RunAtLoad</key>
            <true/>
            <key>KeepAlive</key>
            <true/>
        </dict>
    </plist>

    Note that RunAtLoad will start this launch agent when loaded (which is determined below) and KeepAlive, since it is set to true, will indiscriminately restart BlueBubbles when it exits. As I was researching this, I found that not specifying that the agent should not be restarted when it exits successfully may cause problems with software updates (source), but I haven't had the chance to test this yet.

  2. Disable the built-in autostart: Screenshot 2024-05-17 at 12 43 40 PM

  3. Install the launch agent and load it after the current user graphically logs in:

    launchctl bootstrap gui/$(id -u $(whoami)) ~/Library/LaunchAgents/app.bluebubbles.plist
  4. Immediately start the launch agent (only necessary for the first time):

    launchctl kickstart gui/$(id -u $(whoami))/app.bluebubbles

Some additional notes:

zlshames commented 5 months ago

Thanks @Scr0nch I've turned this into an official guide! https://docs.bluebubbles.app/server/basic-guides/autostart-server-after-crash

cameronaaron commented 5 months ago

I have no clue why this has never worked for me in practice it would still be very nice if this was bundled into the bluebubbles application

zlshames commented 5 months ago

I have no clue why this has never worked for me in practice it would still be very nice if this was bundled into the bluebubbles application

I might be able to have the server do it, but it may require admin privileges. I'll have to see.

It probably didn't work for you because the path that he included as the program variable is in the system applications folder. Whole yours is likely in your User applications folder.

zlshames commented 5 months ago

Ok i was able to add it as a feature on the server

cameronaaron commented 5 months ago

Thank you!