systemd.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. service='[Unit]
  3. Description=NewFuture ddns
  4. After=network.target
  5. [Service]
  6. Type=simple
  7. WorkingDirectory=/usr/share/DDNS
  8. ExecStart=/usr/bin/env python /usr/share/DDNS/run.py -c /etc/DDNS/config.json
  9. [Install]
  10. WantedBy=multi-user.target'
  11. timer='[Unit]
  12. Description=NewFuture ddns timer
  13. [Timer]
  14. OnUnitActiveSec=5m
  15. Unit=ddns.service
  16. [Install]
  17. WantedBy=multi-user.target'
  18. if [[ "install" == $1 ]]; then
  19. echo "$service" > /usr/lib/systemd/system/ddns.service
  20. echo "$timer" > /usr/lib/systemd/system/ddns.timer
  21. cp -r `pwd` /usr/share/
  22. mkdir -p /etc/DDNS
  23. if [ ! -f "/etc/DDNS/config.json" ];then
  24. if [ -f "config.json" ];then
  25. cp config.json /etc/DDNS/config.json
  26. fi
  27. fi
  28. systemctl enable ddns.timer
  29. systemctl start ddns.timer
  30. echo "installed"
  31. echo "useful commands:"
  32. echo " systemctl status ddns view service status."
  33. echo " journalctl -u ddns.timer view the logs."
  34. echo "config file: /etc/DDNS/config.json"
  35. elif [[ "uninstall" == $1 ]]; then
  36. systemctl disable ddns.timer
  37. rm /usr/lib/systemd/system/ddns.service
  38. rm /usr/lib/systemd/system/ddns.timer
  39. rm -rf /etc/DDNS
  40. rm -rf /usr/share/DDNS
  41. systemctl daemon-reload
  42. echo "uninstalled"
  43. else
  44. echo "Tips:"
  45. echo " $0 install install the ddns systemd service."
  46. echo " $0 uninstall uninstall the ddns service."
  47. fi