Sunday, June 26, 2016

Creating Start-up Script in Ubuntu

I installed Redmine in an Ubuntu Server at Windows Azure and was successful in doing so. However, Azure did some maintenance in my server and has to restart it. So, when I accessed Redmine again, Nginx redirected me to its Error 502 page. Upon checking, I realized that  there was really a restart that happened and I thought I have to create a start-up script to avoid this since it was not only me who is using the Redmine which I installed but also my clients' testers and BA's.

Here's how my script look like.

#!/bin/sh

REDMINE_START=/home/tsiminiya/redmine-3.3.0/run.sh
REDMINE_STOP=/home/tsiminiya/redmine-3.3.0/stop.sh
REDMINE_USER=tsiminiya
REDMINE_COMMAND=

executeCommand() {
    start-stop-daemon -S -u $REDMINE_USER -c $REDMINE_USER -o -x $REDMINE_COMMAND
}

case $1 in
    start)
        REDMINE_COMMAND=$REDMINE_START
        executeCommand
        ;;
    stop)
        REDMINE_COMMAND=$REDMINE_STOP
        executeCommand
        ;;
    *)
        echo "Usage: $(basename $0) (start | stop)"
        ;;
esac


You may modify the variables above to point to your start and stop scripts. I didn't put here the contents of my run.sh and stop.sh. What is important here is the start-stop-daemon line. And, also after constructing your start-up script:

1. Save the file at /etc/init.d/<filename-of-your-choice>.
2. sudo chmod +x /etc/init.d/<filename-of-your-choice>
3. sudo update-rc.d <filename-of-your-choice> defaults

Note: at #3, we don't specify the full path but just the script name.

Restart the server after Step 3 to test whether your start-up script is working.






1 comment: