bash

Run a script when the system starts up or reboots on Ubuntu.

1) Create script, on this example I'm starting the gluu-server service as the root user

$sudo nano /etc/init.d/MyScriptName

Copy/paste the following script, update accordingly:

#! /bin/sh
# /etc/init.d/MyScriptName
#

case "$1" in
  start)
    echo "Attempting to Start Gluu Server..."
    sudo -H -b service gluu-server start
    ;;
  stop)
    echo "Attempting to Stop Gluu Server..."
    sudo -H service gluu-server stop
    ;;
  *)
    echo "Usage: /etc/init.d/MyScriptName {start|stop}"
    exit 1
    ;;
esac

exit 0

2) Give the script executable permission

$sudo chmod +x /etc/init.d/MyScriptName

3) Tell script to run at startup. This tells the script be the first to shutdown and the last to…

Read more...
Monday, July 13, 2015