cli: add a startservice.ps1 script

Summary:
This script deals with obtaining the right privilege to start the EdenFS
service. This effectively enables `edenfsctl start`.

Reviewed By: wez

Differential Revision: D21585739

fbshipit-source-id: 7b835434d865fa4c4c8473e13665ae669fd86108
This commit is contained in:
Xavier Deguillard 2020-05-19 12:58:23 -07:00 committed by Facebook GitHub Bot
parent c2f85710d3
commit 6cdc2782b3
4 changed files with 70 additions and 8 deletions

View File

@ -152,6 +152,12 @@ if(WIN32)
get_filename_component(python_dll_dir "${python_dll}" DIRECTORY)
file(TO_NATIVE_PATH "${python_dll_dir}" python_dll_dir)
file(WRITE "${CMAKE_BINARY_DIR}/LIBRARY_DEP_DIRS.txt" "${python_dll_dir}\n")
# The following powershell script is required to start the EdenFS service.
install(
FILES "${CMAKE_SOURCE_DIR}/eden/scripts/startservice.ps1"
DESTINATION scripts
)
endif()
configure_file(

View File

@ -164,9 +164,7 @@ def _start_edenfs_service(
if sys.platform == "win32":
from . import winproc
winproc.start_edenfs_service(cmd)
print("EdenFS started")
return 0
return winproc.start_edenfs_service(cmd)
eden_env = get_edenfs_environment()

View File

@ -7,17 +7,18 @@
# pyre-strict
import subprocess
import sys
from pathlib import Path
from typing import List, Optional
from . import proc_utils_win
from .config import EdenInstance
def start_edenfs_service(cmd: List[str]) -> None:
# TODO: At the moment this isn't actually using the Windows service code
cmd_str = subprocess.list2cmdline(cmd)
proc_utils_win.create_process_shim(cmd_str)
print("EdenFS started")
def start_edenfs_service(_cmd: List[str]) -> int:
script = Path(sys.executable).parent.parent / "scripts" / "startservice.ps1"
cmd = ["powershell.exe", str(script)]
return subprocess.call(cmd)
def run_edenfs_foreground(cmd: List[str]) -> int:

View File

@ -0,0 +1,57 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
function Is-Admin {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Start-EdenFS {
Param($Service)
if (Is-Admin) {
Start-Service $Service
} else {
$serviceName = $edenfsService.Name
$command = "Start-Service", "$serviceName"
$powershellPath = Get-Command powershell.exe
Start-Process $powershellPath -ArgumentList $command -Wait -Verb RunAs -WindowStyle Hidden
if ($Service.Status -ne "Running") {
exit 1
}
}
}
function Start-Foreground {
Start-Process "edenfs.exe" -ArgumentList "--foreground" -WindowStyle Hidden
}
Write-Output "Starting EdenFS service ..."
$edenfsService = Get-Service "edenfs_*"
if ($edenfsService) {
if ($edenfsService.Status -eq "Running") {
Write-Output "EdenFS is already running."
exit
} else {
Start-EdenFS -Service $edenfsService
}
} else {
# Use a wildcard to avoid Get-Service erroring out.
$mainService = Get-Service "edenfs*"
if ($mainService) {
Write-Warning "Couldn't start the EdenFS service as it was recently installed."
Write-Warning "When you next login it will be registered. I will continue and spawn it outside of the service manager for now!"
} else {
Write-Warning "EdenFS doesn't appear to have been installed properly. Run:"
Write-Warning "choco uninstall fb.eden"
Write-Warning "choco install fb.eden"
}
Write-Warning "Attempting to start EdenFS manually."
Start-Foreground
}