Permanent automatic startup solution Ubuntu

Discussion in 'Systems Administration' started by ssamjh, Oct 19, 2014.

  1. ssamjh

    Moderator

    I am looking for a way to automatically start the server on boot and restart it if it crashes. I have found remote toolkit which looks like it'll help with restarting on crash. But if there any way I can make the remote toolkit start on startup. I saw somewhere you can make it a service. Like...

    Code (Text):
    service minecraft start

    Which would be brilliant! As the hoster could just type service minecraft stop into chat then reboot his computer without affecting the files. So any help is greatly appreciated!

    Thanks.
     
  2. ssamjh

    Moderator

  3. You could work with Cronjobs and have it execute service minecraft start on @reboot
     
  4. God no, that is a horrible way of doing it. If his box crashes, it won't flag it as a reboot, so when he boots back up, it won't come on.

    The easiest way to have it start on boot is by adding your start command to /etc/rc.local depending on your system, it may be there or at /etc/init.d/rc.local

    Another way is creating an init script. You'd do this by creating your own init script.

    Code (Text):

    #!/bin/bash
    #
    # chkconfig: 35 90 12
    # description: Multicraft
    #
    # Get function from functions library
    . /etc/init.d/functions
    # Start the service Multicraft
    start() {
    initlog -c "echo -n Starting Multicraft: "
    /path/to/multicraft&
    ### Create the lock file ###
    touch /var/lock/subsys/multicraft
    success $"Multicraft server startup"
    echo
    }
    # Restart the service Multicraft
    stop() {
    initlog -c "echo -n Stopping Multicraft server: "
    killproc Multicraft
    ### Now, delete the lock file ###
    rm -f /var/lock/subsys/multicraft
    echo
    }
    ### main logic ###
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status multicraft
    ;;
    restart|reload|condrestart)
    stop
    start
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|reload|status}"
    exit 1
    esac
    exit 0
     
    Edit that file to your needs, and save it in /etc/init.d/multicraft and let root own it and make it executable.
    Now, you can use chkconfig to set this to run at boot.

    Starting it is as simple as running /etc/init.d/multicraft start or service multicraft start.
     
    • Like Like x 1
  5. @reboot is basically at startup.
    Source: http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
     
  6. ssamjh

    Moderator

    I woudn't call myself an expert, but as long as I change most of the paths for that script @IXGY posted. It should work. Ill go and change it now. Then post what I got.

    I also saw this, but it does use crontab.
     
    #7 ssamjh, Oct 20, 2014
    Last edited: Oct 20, 2014
  7. ssamjh

    Moderator

    Does this look right??

    Code (Text):
    #!/bin/bash
    #
    # chkconfig: 35 90 12
    # description: rtk
    #
    # Get function from functions library
    . /etc/init.d/functions
    # Start the service Remote Toolkit
    start() {
    initlog -c "echo -n Starting Remote Toolkit: "
    /root/mc.start.sh&
    ### Create the lock file ###
    touch /var/lock/subsys/rtk
    success $"Remote Toolkit has been started"
    echo
    }
    # Restart the service
    stop() {
    initlog -c "echo -n Stopping Remote Toolkit: "
    killproc rtk
    ### Now, delete the lock file ###
    rm -f /var/lock/subsys/rtk
    echo
    }
    ### main logic ###
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status multicraft
    ;;
    restart|reload|condrestart)
    stop
    start
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|reload|status}"
    exit 1
    esac
    exit 0
     
  8. Yea, that looks good. I see you left some multicraft in there, when you're using remote toolkit.
     
  9. ssamjh

    Moderator

    Oh. Oops. Nearly ;)