A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
945 B

  1. use std::path::Path;
  2. pub fn socket_service(
  3. socket_path: impl AsRef<Path>,
  4. exec: &str,
  5. dir: impl AsRef<Path>,
  6. additional: &str,
  7. ) -> String {
  8. format!(
  9. "[Service]
  10. ExecStartPre=/bin/rm -f {}
  11. ExecStart={}
  12. WorkingDirectory={}
  13. Restart=always
  14. {}
  15. [Install]
  16. WantedBy=default.target
  17. ",
  18. socket_path.as_ref().to_str().unwrap(),
  19. exec,
  20. dir.as_ref().to_str().unwrap(),
  21. additional
  22. )
  23. }
  24. pub fn nodejs_service<N: AsRef<Path>, S: AsRef<Path>>(
  25. nodejs_path: N,
  26. socket_path: S,
  27. dir: impl AsRef<Path>,
  28. ) -> String {
  29. socket_service(
  30. &socket_path,
  31. &format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()),
  32. dir,
  33. &format!(
  34. "Environment=NODE_ENV=production
  35. Environment=PORT={0}
  36. ExecStartPost=/bin/sh -c 'for i in 1 2 3 4 5 6 7 8 9 10; do sleep 0.5; chmod 666 {0} && break; done'
  37. #RuntimeDirectory=service
  38. #RuntimeDirectoryMode=766",
  39. socket_path.as_ref().to_str().unwrap()
  40. ),
  41. )
  42. }