use std::path::Path; pub fn socket_service( socket_path: impl AsRef, exec: &str, dir: impl AsRef, additional: &str, ) -> String { format!( "[Service] ExecStartPre=/bin/rm -f {} ExecStart={} WorkingDirectory={} Restart=always {} [Install] WantedBy=default.target ", socket_path.as_ref().to_str().unwrap(), exec, dir.as_ref().to_str().unwrap(), additional ) } pub fn nodejs_service, S: AsRef>( nodejs_path: N, socket_path: S, dir: impl AsRef, ) -> String { socket_service( &socket_path, &format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()), dir, &format!( "Environment=NODE_ENV=production Environment=PORT={0} 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' #RuntimeDirectory=service #RuntimeDirectoryMode=766", socket_path.as_ref().to_str().unwrap() ), ) }