Skip to content
Darosior edited this page Jan 2, 2020 · 4 revisions

Integration with launchd (Mac OS X)

On Mac OS X, you can set rdm can be run on demand, on your behalf, by launchd, and have it exit cleanly after a period of inactivity. The easiest way to do this is with Homebrew:

brew services start rtags

You can also do it manually using the following steps:

  1. Create a file, e.g., in emacs, with the following contents:
    <?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.andersbakken.rtags.agent</string>
        <key>ProgramArguments</key>
        <array>
          <string>sh</string>
          <string>-c</string>
          <string>$RDM -v --launchd --inactivity-timeout 300 --log-file ~/Library/Logs/rtags.launchd.log</string>
        </array>
        <key>Sockets</key>
        <dict>
          <key>Listener</key>
          <dict>
        <key>SockPathName</key>
        <string>$HOME/.rdm</string>
          </dict>
        </dict>
      </dict>
    </plist>
        
  2. Replace $HOME with the absolute path to your home folder. Replace $RDM with the path to your copy of rdm, and add any command line parameters you might usually use.

    (The SockPathName entry relates to the name of the domain socket that rdm uses. The settings above are for the default value; if your command line options direct it to use some other name, please modify it to suit. Unfortunately launchd’s configuration files are a bit naff, so you’ll have to repeat yourself.)

  3. Save the result as ~/Library/LaunchAgents/com.andersbakken.rtags.agent.plist.
  4. Run the following command from the terminal:
    launchctl load ~/Library/LaunchAgents/com.andersbakken.rtags.agent.plist
        

    (This will happen automatically next time you log back in.)

  5. Try using RTags, and you should find rdm will spring into life!

Notes

  • rdm will automatically quit after 5 minutes of inactivity (this is what the --inactivity-timeout 300 command line option is for), so it won’t stick around hogging memory. But launchd will still be watching its socket for activity, and will relaunch it if necessary.
  • You can watch launchd’s logging by tailing ~/Library/Logs/rtags.launchd.log.

Integration with systemd (GNU Linux)

On GNU/Linux distributions based on the systemd service manager, rdm can also be socket acivated.

  1. Add the following to ~/.config/systemd/user/rdm.socket
    [Unit]
    Description=RTags daemon socket
    
    [Socket]
    ListenStream=%t/rdm.socket
    
    [Install]
    WantedBy=default.target
        
  2. Add the following to ~/.config/systemd/user/rdm.service
    [Unit]
    Description=RTags daemon
    
    Requires=rdm.socket
    
    [Service]
    Type=simple
    ExecStart=$RDM -v --inactivity-timeout 300 --log-flush
    ExecStartPost=/bin/sh -c "echo +19 > /proc/$MAINPID/autogroup"
    Nice=19
    CPUSchedulingPolicy=idle
        
  3. Replace $RDM with the path to your copy of rdm, and add any command line parameters you might usually use.

    You have to use absolute paths here. %h is expanded to your home directory. Environment variables are not expanded inside strings.

  4. Run the following command from the terminal:
    systemctl --user enable rdm.socket
    systemctl --user start rdm.socket
        

    Systemd will create the rdm socket automatically.

    Note that user level systemd does not work on RHEL derivatives. See here for more info: https://bugs.centos.org/view.php?id=8767

If you prefer using SystemV something like this could be used:

#!/bin/bash
#
# chkconfig: 35 90 12
# description: Foo server
#

# Get function from functions library
. /etc/init.d/functions

# Start the service FOO
start() {
        initlog -c "echo -n Starting FOO server: "
        /path/to/FOO &
        ### Create the lock file ###
        touch /var/lock/subsys/FOO
        success $"FOO server startup"
        echo
}

# Restart the service FOO
stop() {
        initlog -c "echo -n Stopping FOO server: "
        killproc FOO
        ### Now, delete the lock file ###
        rm -f /var/lock/subsys/FOO
        echo
}

### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status FOO
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0

Setting rdm default options

You can specify default options for rdm by putting the options in the file /.rdmrc. Just put the options, one per line, in the configuration file. Lines starting with ‘#’ are ignored.

For example:

# This is a comment
--data-dir=~/my/rdm/data/dir
--start-suspended