oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.61k stars 235 forks source link

cs-script 4.8.5 doesn't show information about server on Linux #346

Closed shitpoet closed 10 months ago

shitpoet commented 11 months ago

cs-script 4.8.5 installed on Debian 12 Linux as

dotnet tool install --global cs-script.cli

doesn't show information about server:

~/tmp/cs$ css -server
Build server is not deployed.
Expected deployment: /usr/local/share/cs-script/bin/compiler/4.8.5.0/build.dll
Could not find file "-server".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$ css -server:start
Could not find file "-server:start".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$

It should show it according to the -help screen if I understand it correctly:

-server[:<start|stop|restart|add|remove|ping>]
    Prints the information about build server.
    Note, the server starts automatically on the script execution that is configured to use the 'csc'
    or 'roslyn' engine.

Config is default:

~/tmp/cs$ css -config
 UseAlternativeCompiler: ""
 ResolveRelativeFromParentScriptLocation: False
 DefaultArguments: "-c -ac:0"
 InjectScriptAssemblyAttribute: False
 EnableDbgPrint: True
 ResolveAutogenFilesRefs: True
 LegacyNugetSupport: True
 OpenEndDirectiveSyntax: True
 ConsoleEncoding: "default"
 LegacyTimestampCaching: False
 CustomTempDirectory: ""
 DefaultCompilerEngine: "csc"
 DefaultRefAssemblies: "System; System.Core;"
 SearchDirs: "%CSSCRIPT_ROOT%/lib;;%CSSCRIPT_INC%;"
 Precompiler: ""
 CustomHashing: True
 ReportDetailedErrorInfo: False
 HideCompilerWarnings: False
 InMemoryAssembly: True
 ConcurrencyControl: Standard

No env variables are set for cs-script:

~/tmp/cs$ env | grep CSSCRIPT
~/tmp/cs$
shitpoet commented 11 months ago

I tried also css -server:add, but it does nothing:

~/tmp/cs$ css -server:add
Access to the path '/usr/local/share/cs-script' is denied.
Could not find file "-server:add".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$

But if I manually create /usr/local/share/cs-script directory and make it fully accessible by anyone (0777 UNIX permissions):

~/tmp/cs$ sudo mkdir -p /usr/local/share/cs-script
~/tmp/cs$ sudo chmod 0777 /usr/local/share/cs-script

then execution of css -server:add gives some unrelated message

~/tmp/cs$ css -server:add
Could not find file "-server:add".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$

but at the same time it does create the following entires in the directory:

/usr/local/share/cs-script/bin
/usr/local/share/cs-script/bin/compiler
/usr/local/share/cs-script/bin/compiler/4.8.5.0
/usr/local/share/cs-script/bin/compiler/4.8.5.0/build.dll
/usr/local/share/cs-script/bin/compiler/4.8.5.0/build.runtimeconfig.json
/usr/local/share/cs-script/bin/compiler/4.8.5.0/build.deps.json

and now css -server:start starts the server.

The problem I see here is that cs-script tries to create a folder in system directories without having permissions to do so. But maybe the idea was to create these folders during installation and dotnet tool install --global didn't do it?

oleg-shilo commented 11 months ago

I am investigating it. It's most likely caused by the differences in installation of cs-script as debian package comparing to dotnet tool.

Will let you know the outcome

oleg-shilo commented 11 months ago

OK, it's an interesting one. It's not as bad as it looks like.

When you see this output:

Could not find file "<your command>".
Ensure it is in one of the CS-Script search/probing directories.

It is unconditionally printed at any server command regardless if it was successful or not. It was a mistake in the code and it is corrected now.

I tried also css -server:add, but it does nothing:

~/tmp/cs$ css -server:add
Access to the path '/usr/local/share/cs-script' is denied.
Could not find file "-server:add".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$

A few problems here:

  • Could not find file - I just described it above
  • Access to the path - this is because you need to have root access to execute this command. You need to run it with sudo. To make it more intuitive it prints the suggestion now: image

then execution of css -server:add gives some unrelated message

~/tmp/cs$ css -server:add
Could not find file "-server:add".
Ensure it is in one of the CS-Script search/probing directories.
~/tmp/cs$
  • Could not find file - still the same
  • But it actually deployed the build server. Just did not tell you about it. Now it does: image

    But maybe the idea was to create these folders during installation and dotnet tool install --global didn't do it?

Unfortunately, it's dotnet tool install does not allow you to have any behaviour. You cannot define any routine to create a folder and set its permissions. Thus it behaves as intended, except not communicating well to the user. This is fixed now and will be available in the very next release in a day or so.

BTW, after deploying the build server you do not need root permissions to operate it.

oleg-shilo commented 11 months ago

Done You can update your deployment with v4.8.6.0

shitpoet commented 10 months ago

Yes, now it works!) BTW, alternative way to run css under sudo is

sudo `which css` ...

(to allow css to be searched in the current user's PATH):

Everything looks good now:

~/tmp/cs$ sudo `which css` -server:ping
pid:2333395
file: /usr/local/share/cs-script/bin/compiler/4.8.6.0/build.dll
csc: /usr/share/dotnet/sdk/7.0.401/Roslyn/bincore/csc.dll
oleg-shilo commented 10 months ago

Great trick. Txs. Did not know that.