Advertisement
Guest User

le shutdown with net

a guest
Apr 27th, 2016
2,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. service shutdown_with_net.service:
  2.  
  3. ----------------------------------------------------------------
  4. [Unit]
  5. Description=System shutdown script with network
  6. After=network.target
  7. Wants=network.target
  8.  
  9. [Service]
  10. Type=oneshot
  11. Environment=HOME=/storage
  12. ExecStart=/bin/true
  13. ExecStop=-/bin/sh -c ". /etc/profile; exec /bin/sh /storage/.config/shutdown_with_net.sh"
  14. RemainAfterExit=yes
  15. KillMode=none
  16. SendSIGKILL=no
  17. TimeoutSec=5min
  18. TimeoutStopSec=5min
  19.  
  20. [Install]
  21. WantedBy=multi-user.target
  22. ----------------------------------------------------------------
  23.  
  24. install and enable service:
  25. cp shutdown_with_net.service /storage/.config/system.d/
  26. systemctl enable shutdown_with_net.service
  27.  
  28. for testing I used
  29. file autostart.sh:
  30. ----------------------------------------------------------------
  31. echo "" >>/storage/ping
  32. echo -n "autostart " >>/storage/ping
  33. date "+%H:%M:%S" >>/storage/ping
  34.  
  35. (
  36. sleep 20
  37. reboot
  38. )&
  39. ----------------------------------------------------------------
  40.  
  41. and file shutdown_with_net.sh:
  42. ----------------------------------------------------------------
  43. echo -n "shutdown start " >>/storage/ping
  44. date "+%H:%M:%S" >>/storage/ping
  45. sync
  46.  
  47. ping -c 20 -q 10.0.0.1
  48.  
  49. echo -n "shutdown done " >>/storage/ping
  50. date "+%H:%M:%S" >>/storage/ping
  51. sync
  52.  
  53. ----------------------------------------------------------------
  54.  
  55. result:
  56. ----------------------------------------------------------------
  57. autostart 14:17:47
  58. shutdown start 14:18:05
  59. shutdown done 14:18:24
  60.  
  61. autostart 14:18:38
  62. shutdown start 14:18:57
  63. shutdown done 14:19:16
  64.  
  65. .......................
  66. ----------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement