Init.d service script for OS X ?

Sorry for the recent posts. This one might be easier to answer.

I’ve been able to use the init.d script provided on the WIKI here https://book.orthanc-server.com/faq/debian-daemon.html?highlight=startup%20script

That works great with UBUNTU.

I am looking for something similar for OS X, mostly because I do most of my dev work on OS X initially because it is much more convenient for me sometimes.

I’m working on an Admin Control Panel using PHP and I’d like to be able to start and stop Orthanc remotely using the init.d script. That works with the Debian script, but I need an equivalent .sh script or daemon that I can use for OS X.

I’ve looked around a little and there isn’t much on the internet.

e.g. https://medium.com/@fahimhossain_16989/adding-startup-scripts-to-launch-daemon-on-mac-os-x-sierra-10-12-6-7e0318c74de1

and it probably varies a bit for OS X release version since it changes periodically from version to version.

I know that they often use .plist files.

A .sh script like this works, but that just starts it up from the terminal, not in the background of as a service / daemon.
`

#!/bin/bash

cd “$(dirname “$0”)”

script name is orthanc.sh, put it in the same directory as the Orthanc executable. e.g. /path/to/orthanc/Orthanc/orthanc.sh

/Users/sscotti/Desktop/orthancAndPluginsOSX.stable/orthanc.sh to execute from the command line, for my install

cd /Users/sscotti/Desktop/orthancAndPluginsOSX.stable #Directory for the executable Orthanc
./Orthanc ConfigOSX.json --verbose #ConfigOSX.json is in the same directory, although can probably have that somewhere else.
`

Thanks.

/sds

MacOs uses launchd to control startup agents and daemons. Here are a few links that may help https://alvinalexander.com/mac-os-x/launchd-examples-launchd-plist-file-examples-mac/

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

My recommendation is to use docker on a Mac. You get to use the prebuilt Osimis orthanc containers and docker automatically manages start up, restart if crashed for you.

James

Binary Logo

James Manners • Director
Suite 3, Level 2, 10 Queens Road, Melbourne, Victoria 3004, Australia

T: 03 9017 5230 M: 0422 973 235 E: james@binary.com.au W: binary.com.au

Thanks for the feedback. Unfortunately, my iMac is an older Mac:

Model Name: iMac Model Identifier: iMac11,3 Processor Name: Intel Core i7 Processor Speed: 2.93 GHz Number of Processors: 1 Total Number of Cores: 4 L2 Cache (per Core): 256 KB L3 Cache: 8 MB Memory: 32 GB Boot ROM Version: 99.0.0.0.0 SMC Version (system): 1.59f2

I don’t think it supports the Docker Desktop app because I tried to install and it won’t run on my Mac. I have a LINUX server that I am starting to use UBUNTU on. I mostly want to
use the iMac because I develop there mostly. I want to add a start and stop feature to an Admin Panel that I have through the API. The start stop just communicates with the system
that Orthanc is running on, not with Orthanc through the REST API>

`
Incompatible CPU detected

We are sorry, but your hardware is incompatible with Docker Desktop.

Docker requires a processor with virtualization capabilities and hypervisor support.

To learn more about this issue see:

https://docs.docker.com/docker-for-mac/troubleshoot
`

There is a way to install docker using the CLI and something like homebrew: e.g. https://medium.com/@yutafujii_59175/a-complete-one-by-one-guide-to-install-docker-on-your-mac-os-using-homebrew-e818eb4cfc3

That is kind of a pain, and not sure it would work anyways since my Mac can’t run anything higher than High Sierra. Might have to consider buying an more recent refurbished iMac if I want to use Docker on the Mac.

This link is helpful: https://alvinalexander.com/mac-os-x/launchd-examples-launchd-plist-file-examples-mac/

Sample .plist:

<?xml version="1.0" encoding="UTF-8"?>
http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>label</key>
        <string>com.devdaily.pingwebsites</string>

        <key>ProgramArguments</key>
        <array>
                <string>/Users/al/bin/crontab-test.sh</string>
        </array>

        <key>OnDemand</key>
        <false/>

        <key>Nice</key>
        <integer>1</integer>

        <key>StartInterval</key>
        <integer>60</integer>

        <key>StandardErrorPath</key>
        <string>/tmp/AlTest1.err</string>

        <key>StandardOutPath</key>
        <string>/tmp/AlTest1.out</string>
</dict>
</plist>

Is it possible to pass some args to the shell script or otherwise write separate start, stop and restart scripts for Orthanc ?
The example in the initial post seems to work for starting up using the terminal, but to stop Orthanc I have to hit Ctrl-C in the terminal
because it is running in the foreground.

I presume that if I use the launchd it would start up in the background , but I'm not sure how to stop Orthanc when it is started up using a launchd.

The Unix Debian script has this:

do_start()
{
 # Prepare a directory to store the Orthanc logs
 mkdir -p $LOGDIR
 chown $ORTHANC_USER $LOGDIR

 # Return
 # 0 if daemon has been started
 # 1 if daemon was already running
 # 2 if daemon could not be started

 start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $ORTHANC_USER --background --exec $DAEMON --test > /dev/null \
 >> return 1

 start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --chuid $ORTHANC_USER --background --exec $DAEMON -- $DAEMON_ARGS \
 >> return 2

 # Add code here, if necessary, that waits for the process to be ready
 # to handle requests from services started subsequently which depend
 # on this one. As a last resort, sleep for some time.
}