_common.sh 856 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. #
  3. # Common variables
  4. #
  5. pkg_dependencies="php5-fpm sipcalc dnsutils openvpn curl fake-hwclock"
  6. # Helper to start/stop/.. a systemd service from a yunohost context,
  7. # *and* the systemd service itself needs to be able to run yunohost
  8. # commands.
  9. #
  10. # Hence the need to release the lock during the operation
  11. #
  12. # usage : ynh_systemctl yolo restart
  13. #
  14. function ynh_systemctl()
  15. {
  16. local ACTION="$1"
  17. local SERVICE="$2"
  18. local LOCKFILE="/var/run/moulinette_yunohost.lock"
  19. # Launch the action
  20. sudo systemctl "$ACTION" "$SERVICE" &
  21. local SYSCTLACTION=$!
  22. # Save and release the lock...
  23. cp $LOCKFILE $LOCKFILE.bkp.$$
  24. rm $LOCKFILE
  25. # Wait for the end of the action
  26. wait $SYSCTLACTION
  27. # Make sure the lock is released...
  28. while [ -f $LOCKFILE ]
  29. do
  30. sleep 0.1
  31. done
  32. # Restore the old lock
  33. mv $LOCKFILE.bkp.$$ $LOCKFILE
  34. }