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

How to set up a launch daemon? #63

Closed
ddebernardy opened this issue Jun 26, 2011 · 4 comments
Closed

How to set up a launch daemon? #63

ddebernardy opened this issue Jun 26, 2011 · 4 comments

Comments

@ddebernardy
Copy link

The docs suggest that this is possible:

You can also install Thin as a runlevel script (under /etc/init.d/thin) that will start all your servers after boot.

sudo thin install

When trying it on my Mac, however, it yields:

$ sudo thin install
Unknown command: install. Use one of start, stop, restart, config

I'll keep googling around, but some extra documentation on this (and on the recommended way to monitor things) would be quite welcome.

@imanel
Copy link

imanel commented Jun 26, 2011

It's because of "install" command is linux only command, and linux is defined by ruby platform variable. It could be easy implemented for Mac after detection of this system will be pulled from pull request #64

@imanel
Copy link

imanel commented Jun 26, 2011

Responding to (yet) unanswered question - I can implement config file for autostart(it will be simple XML file copied to directory, so nothing fancy;) is @macournoyer will accept Mac-detection patch.

@ddebernardy
Copy link
Author

Well, for the note, I eventually got it to work.

Config file:

DB:~/Sites/rubyapp $ cat config/thin.yml 
--- 
chdir: /Users/denis/Sites/rubyapp
environment: development
address: 0.0.0.0
port: 5000
timeout: 30
log: log/thin/thin.log
pid: tmp/thin/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []

wait: 30
servers: 1
daemonize: true

shell wrapper:

DB:~/Sites/rubyapp $ cat scripts/thin/thin.sh
#!/bin/sh
#

#
# Init
#
prefix=/opt/local

case $1 in
  start  )  [ -x /opt/local/bin/thin ] && \
            /opt/local/bin/thin start -C /Users/denis/Sites/rubyapp/config/thin.yml #> /dev/null
            ;;
  stop   )  [ -x /opt/local/bin/thin ] && \
            /opt/local/bin/thin stop -C /Users/denis/Sites/rubyapp/config/thin.yml #> /dev/null
            ;;
  restart)  [ -x /opt/local/bin/thin ] && \
            /opt/local/bin/thin restart -C /Users/denis/Sites/rubyapp/config/thin.yml #> /dev/null
            ;;
  *      )  echo "$0: unknown argument: $1";;
esac

plist file:

DB:~/Sites/rubyapp $ cat scripts/thin/thin.plist 
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key><string>local.rubyapp.thin</string>
<key>ProgramArguments</key>
<array>
    <string>/opt/local/bin/daemondo</string>
    <string>--label=rubyapp</string>
    <string>--start-cmd</string>
    <string>/Users/denis/Sites/rubyapp/scripts/thin/thin.sh</string>
    <string>start</string>
    <string>;</string>
    <string>--stop-cmd</string>
    <string>/Users/denis/Sites/rubyapp/scripts/thin/thin.sh</string>
    <string>stop</string>
    <string>;</string>
    <string>--restart-cmd</string>
    <string>/Users/denis/Sites/rubyapp/scripts/thin/thin.sh</string>
    <string>restart</string>
    <string>;</string>
    <string>--pid=none</string>
</array>
<key>Debug</key><false/>
<key>Disabled</key><true/>
<key>OnDemand</key><false/>
</dict>
</plist>

Auto-start:

DB:~/Sites/rubyapp $ sudo ln -s scripts/thin/thin.plist /Library/LaunchDaemons/local.rubyapp.thin.plist
DB:~/Sites/rubyapp $ sudo launchctl -v load -w /Library/LaunchDaemons/local.rubyapp.thin.plist

Hope this helps someone...

@macournoyer
Copy link
Owner

Indeed, didn't work because this command is linux only for now. If you can make a pull request to implement this, I'll merge for sure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants