Starting the CFML Server On Boot
CFML, ColdFusion, CommandBox, Raspberry PiTonight, AJ Mercer asked me on Twitter if it was possible to start the CommandBox server on boot. This is what I threw together to ensure this blog will come back online in the event of my Raspberry Pi losing power or just being rebooted for maintenance.
I followed these instructions on how to make a script that runs on startup. Here is the very quick run down. Note, I'm already running as root so I'm not using "sudo". First create a script in your /etc/init.d folder. The name of the script is entirely arbitrary.
nano /etc/init.d/piwww
Binding the host to whatever your external IP address is ensures the site can be hit externally
Update 3/27/2015 -- After originally posting this, AJ Mercer sent me a full script with start, stop, and restart implemented.
#!/bin/sh -e PATH="/usr/bin" case "$1" in start) sudo box start --rewritesEnable host=192.168.1.69 --!openbrowser name=wwwcontentbox --force ;; stop) sudo box stop wwwcontentbox;; restart|force-reload) sudo box restart wwwcontentbox;; status) sudo box server status wwwcontentbox;; *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;; esac exit 0
Now we make our script executable. You can test it by just running it directly.
chmod 755 /etc/init.d/piwww
And finally, register it as a startup script like so. If you use a different filename, just update it accordingly.
update-rc.d piwww defaults
That's pretty much it. The script will run when Linux boots and start up the CommandBox server automatically. What's cool is you can treat your CommandBox server as a regular Linux service now:
$> service piwww start $> service piwww status $> service piwww stop