peterldowns / localias

custom local domain aliases for local dev servers
MIT License
583 stars 3 forks source link

Automatically start the deamon during boot #24

Closed JanStevens closed 5 months ago

JanStevens commented 6 months ago

Hi,

I've been using Hotel for a very long time and I'm glad that finally there is a great replacement. Would it be possible to add support for starting localias during boot (using plist on Mac and systemd unit on linux) or at least some instructions on how to do it?

Example for mac (I guess it should be stored in ~/Library/LaunchAgents/com.peterldowns.localias.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>com.peterldowns.localias</string>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/homebrew/bin/localias</string>
    <string>start</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>StandardOutPath</key>
  <string>/Library/Logs/com.peterldowns.localias.out.log</string>
  <key>StandardErrorPath</key>
  <string>/Library/Logs/com.peterldowns.localias.err.log</string>
  <key>KeepAlive</key>
  <dict>
    <key>SuccessfulExit</key>
    <false/>
  </dict>
  <key>ThrottleInterval</key>
  <integer>5</integer>
  </dict>
</plist>
peterldowns commented 6 months ago

This is a solid idea — yes, I can add documentation about how to install it as a boot service. It will take me a little while to test but expect something soon. Thanks for the suggestion 🙇

JanStevens commented 6 months ago

I've been messing with the above and It's not working 100% atm since the daemon needs root access sometimes 🤔

error: failed to save file /etc/hosts: exit status 1: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
peterldowns commented 6 months ago

Ah, yeah — the daemo needs sudo in order to update /etc/hosts, and either sudo or at least +netcap for binding to ports 80 and 443. So maybe this is a no go.

How often do you restart your computer? If you localias start, it should work across sleeps (on macOS at least), so hopefully this isn't that big of a deal?

peterldowns commented 5 months ago

Closing this since I don't think it's a particuarly important feature and the setup/installation would be quite complicated --- the daemon would need to start as root on macOS, which I generally don't want to encourage. If other people write in requesting this I'll consider it again.