Results 1 to 10 of 10

Thread: Restart all services on restart onRestart.sh

  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts

    Restart all services on restart onRestart.sh

    I added now a crontab reboot script to restart all services provided so far, these are the scripts:

    Services:
    http://tracker.killtube.org/
    http://iznogod.killtube.org/ (depends on mariadb)

    Code:
    # install script:
    # chmod +x onReboot.sh
    # crontab -e
    # add line: @reboot bash onReboot.sh &
    
    # for some reason screen doesn't start without sleep
    sleep 10
    
    screen -AmdS kung_tracker
    screen -S kung_tracker -p 0 -X stuff "cd tracker; ./tracker.sh
    "
    
    screen -AmdS mariadb
    screen -S mariadb -p 0 -X stuff "cd mariadb; ./run.sh
    "
    
    screen -AmdS iznogod_tracker
    screen -S iznogod_tracker -p 0 -X stuff "cd tracker_iznogod; ./tracker.sh
    "
    
    
    echo "screen restarted! $(date)" >> reboot_log.txt
    haproxy user account:

    Code:
    # install script:
    # chmod +x onReboot.sh
    # crontab -e
    # add line: @reboot bash onReboot.sh &
    
    # for some reason screen doesn't start without sleep
    sleep 10
    
    screen -AmdS haproxy
    screen -S haproxy -p 0 -X stuff "./haproxy.sh
    "
    
    echo "screen restarted! $(date)" >> reboot_log.txt

    Since apache2 was always started on reboot, this was changed with:

    Code:
    update-rc.d -f apache2 remove
    update-rc.d lighttpd enable

    Just tried a reboot, seems to work nice so far to restart all services.

    Any suggestions? Never did this restart-services-on-reboot-stuff, so no experience.
    timescale 0.01

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,688
    Thanks
    17
    Thanked 1,029 Times in 651 Posts
    Using
    Code:
    @reboot sleep 10 && screen -AmdS screenname ./script.sh
    myself
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (16th December 2021)

  4. #3
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts
    I don't get it, that syntax is used all over stackoverflow, but it just doesn't work for me. Like this:

    Code:
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ echo "echo hi" > echo.sh
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ chmod +x echo.sh
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ screen -AmdS foo echo.sh
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ screen -ls
    No Sockets found in /var/run/screen/S-ns_zombies.
    timescale 0.01

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,688
    Thanks
    17
    Thanked 1,029 Times in 651 Posts
    Thats because your script ends immediately, and screen closes after that.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (16th December 2021)

  7. #5
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts
    Still doesn't work, or something else is still going on:

    Code:
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ echo "echo hi; sleep 10" > echo.sh
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ screen -AmdS foo echo.sh
    ns_zombies@5.9.90.148 10.0.3.1 2a01:4f8:162:14cf::2 ~ $ screen -ls
    No Sockets found in /var/run/screen/S-ns_zombies.
    timescale 0.01

  8. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,688
    Thanks
    17
    Thanked 1,029 Times in 651 Posts
    aaaand now you forgot to 1) chmod +x echo.sh and 2) ./echo.sh instead of echo.sh in your screen -AmdS line
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (27th March 2016)

  10. #7
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts
    Thanks, yea, forgot the dot-slash. The +x is still present after overwriting.
    timescale 0.01

  11. #8
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,688
    Thanks
    17
    Thanked 1,029 Times in 651 Posts
    Code:
    k_tracker@euve78301:~$ echo "echo hi; sleep 100" > echo.sh
    k_tracker@euve78301:~$ chmod +x echo.sh
    k_tracker@euve78301:~$ screen -AmdS foo ./echo.sh
    k_tracker@euve78301:~$ screen -ls
    There are screens on:
            1146.foo        (27.03.2016 22:02:14)   (Detached)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  12. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (16th December 2021)

  13. #9
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts
    The difference is now:

    two line version: keeps screen-session open after crash/quit, gives the chance to take a look at the crash message
    one-liner: closes screen-session as soon the command ends
    timescale 0.01

  14. #10
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,992
    Thanks
    2,069
    Thanked 1,070 Times in 744 Posts
    I just figured that you can send "Enter" via ^M, for testing all commands:

    Start a new session called hurra: screen -AmdS hurra

    Send a command (or do it multiple times for testing): screen -S hurra -p 0 -X stuff "date^M"

    Quit session: screen -S hurra -X quit

    (just figured this out to continue work on automatic ssl/LetsEncrypt updater)
    timescale 0.01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •