Learn about Centmin Mod LEMP Stack today
Register Now

Sysadmin Run a script on reboot

Discussion in 'System Administration' started by EckyBrazzz, Aug 20, 2019.

  1. EckyBrazzz

    EckyBrazzz Active Member

    868
    182
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +333
    Local Time:
    8:28 AM
    Latest
    Latest
    Hi there,

    I have a issue with a program that needs some extra for MariaDB and to get that I made a script. But I tried, Googled around but could not find a good way to have the script auto started when the server starts / reboots. If I run these manual on a reboot it won't be in the settings and have to do it again.
    Code (Text):
    #!/bin/bash
    mysql  <<MY_QUERY
    SET GLOBAL local_infile = 'ON';
    SET GLOBAL local_infile = 1;
    SET GLOBAL local_infile = true;
    FLUSH PRIVILEGES;
    exit
    MY_QUERY
    

     
  2. pamamolf

    pamamolf Premium Member Premium Member

    3,811
    369
    83
    May 31, 2014
    Ratings:
    +711
    Local Time:
    2:28 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    bash script and use a cron?

    @reboot
     
  3. EckyBrazzz

    EckyBrazzz Active Member

    868
    182
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +333
    Local Time:
    8:28 AM
    Latest
    Latest
    Tried that but did not work. It looked like it took longer to boot, but did not execute the script. And yes, it executable. ./init1.sh works
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    3,811
    369
    83
    May 31, 2014
    Ratings:
    +711
    Local Time:
    2:28 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    I know it may not be the best to do but you can try to add a delay maybe as the service may need a few seconds to start after booting?

    Code:
    @reboot sleep 10 && script.sh
     
  5. eva2000

    eva2000 Administrator Staff Member

    44,490
    10,164
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,727
    Local Time:
    9:28 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    you should be able to place the full path to script in your /etc/rc.local file which runs whatever is in it on reboot. Just don't remove existing /etc/rc.local contents which on default Centmin Mod would look something similar to below
    Code (Text):
    #!/bin/bash
    # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
    #
    # It is highly advisable to create own systemd services or udev rules
    # to run scripts during boot instead of using this file.
    #
    # In contrast to previous versions due to parallel execution during boot
    # this script will NOT be run after all other services.
    #
    # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
    # that this script will be executed during boot.
    
    touch /var/lock/subsys/local
    ulimit -n 524288
    if [ ! -d /var/run/php-fpm/ ]; then mkdir -p /var/run/php-fpm/; fi
    echo 65536 > /sys/module/nf_conntrack/parameters/hashsize
    
     
  6. EckyBrazzz

    EckyBrazzz Active Member

    868
    182
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +333
    Local Time:
    8:28 AM
    Latest
    Latest
    Resolved it. Most easy way was to use the @reboot
    Code (Text):
    @reboot ( sleep 90 ; sh /root/tools/inifile1.sh )