Automatically starting TiddlyServer on System Startup

Hi,

Is there a documented way of starting TiddlyServer automatically as a service on MacOS?

You should be able to look up a generic solution to starting something on MAC’s. In windows I would use the scheduler app.

This turns out to be much more complicated that you’d think!

So far, the easiest way I’ve found is to create an exercutable shell script

# Start TiddlyWiki server
/path/to/tiddlyserver --config /path/to/config/settings.json

And use the System Settings app to launch the script at login. This isn’t satisfactory as it opens the terminal app to run the bash script, but it works.

The recommended way to do this sort of thing on a Mac is to use the launchctl app to launch the script from a plist file. But so far I haven’t managed to grok the plist format.

A good starting point for further research is: [ Mac crontab: Creating macOS startup jobs with crontab, er, launchd]( Mac crontab: Creating macOS startup jobs with crontab, er, launchd | alvinalexander.com.

I’ll make further reports as I find out more.

By TiddlyServer do you mean tiddlywiki under nodejs or one of the TiddlyServers mentioned among https://tiddlywiki.com/ contributions?

If the former, you might find it easier if you start tiddlywiki under node.js as a Login Item rather than as a System Startup item. If the latter then I think some of this, at least, will still apply and I would still suggest not trying via System Startup. I suspect that will run into increasing difficulty as macOS security gets tighter. As a Login Item you may have to account for the fact that, if you log out, the process can still be running. Me, I never log off unless I am re-starting my mac anyway.

The way I do this as a Login Item is somewhat convoluted, but it works. YMMV.

  • For macOS I use Platypus to wrap a bash script, actually more than one because I bundle all the things I want to start when I login together. I make this Platypus app be a Login Item for my user account.[1] That this Platypus app starts up a whole bunch of things makes this somewhat of a challenge to explain. If you go this route the key item you will want to be aware of is to do something like the following so that the process that gets started has the right PATH settings to find the bits and pieces. As a minimum that’s because I use homebrew to provide me with node that tiddlywiki requires.
    #!/usr/bin/env bash
    PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
    # Without the above PATH setting, other commands that my scripts rely on
    # won't work because Platypus creates x86_64 executables and, on Apple
    # Silicon those require Rosetta emulation, which I would rather avoid.
    
    ./start.sh # start tiddlywiki under node.js
  • The last, start.sh script is one I use on both macOS and Linux. You’ll find a copy in my tiddlywiki-nas GitHub repo, part of my Tiddlywiki on a Synology NAS efforts. Hopefully the documentation there will explain things sufficiently.

  • The key thing you want to take away from the mass of bash scripting there can be found here: If you run tiddlywiki (or tiddlyserver) under the screen command (standard on macOS, installable on Synology and on every Linux I’ve run across; tmux is the more modern equivalent.) then you can avoid a world of hurt you will otherwise encounter with spawning terminals, dealing with nohup and background processes, … and perhaps most importantly, being able to re-attach to the screen process so you can see what is working and when it is not, why.

You will also note that the Tiddlywiki on NAS scripts go to elaborate lengths to enable creating log files (in common.sh so I can track down why problems are occurring. I suspect you will encounter them.

Hope that helps.

[1] If you really want to go down the launchctl route then I find LaunchD Task Scheduler, from the macOS App Store, a handy way to not have to think hard about plists.

1 Like

Thanks @jwd for your detailed reply. I’ll explore at some point.