PDA

View Full Version : Restart all services on restart onRestart.sh



kung foo man
27th March 2016, 21:13
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)



# 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:



# 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:



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.

IzNoGoD
27th March 2016, 21:26
Using


@reboot sleep 10 && screen -AmdS screenname ./script.sh

myself

kung foo man
27th March 2016, 21:41
I don't get it, that syntax is used all over stackoverflow, but it just doesn't work for me. Like this:



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.

IzNoGoD
27th March 2016, 21:43
Thats because your script ends immediately, and screen closes after that.

kung foo man
27th March 2016, 21:45
Still doesn't work, or something else is still going on:




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.

IzNoGoD
27th March 2016, 21:58
aaaand now you forgot to 1) chmod +x echo.sh and 2) ./echo.sh instead of echo.sh in your screen -AmdS line

kung foo man
27th March 2016, 22:01
Thanks, yea, forgot the dot-slash. :D The +x is still present after overwriting.

IzNoGoD
27th March 2016, 22:03
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)

kung foo man
27th March 2016, 22:10
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

kung foo man
16th December 2021, 15:13
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)