arkmanager / ark-server-tools

Set of server tools used to manage ARK: Survival Evolved servers on Linux
MIT License
680 stars 144 forks source link

Add a RESTful API #335

Open FezVrasta opened 8 years ago

FezVrasta commented 8 years ago

Relevant discussion: #255


I've pushed to the new API branch a simple REST server.

To run it cd in /api and then:

npm install
npm start

On the server you need to install npm (on ubuntu it's apt-get install npm if I remember right).

A RESTful API will enable 3rd party apps to use ARK Server Tools remotely.

Possible useful applications:

Lihis commented 8 years ago

Referencing to our discussion on #255. The bash script you wrote seems to work ok. Tested also by replacing the package.json line 7 with "/path/to/start.sh" it worked good so this looks to be good workaround between distros that provide either node or nodejs.

FezVrasta commented 8 years ago

Ok I've pushed the new script

benzon commented 8 years ago

My conserne about the API will it wait until the exec is done before delivering output or will it give me the output live?

What i wanted to do is liveout put "console" so the user is sure that something is happening.

benzon commented 8 years ago

or adleest we should make it wright to a log file every time a line is outputtet so we can open that true ajax and parse the log semi live.

FezVrasta commented 8 years ago

I think you should just put some spinner when you expect the command to take some time, and when the ajax call ends you show an error, if any, or the result

In jQuery it would be something like this:

$.get('/api/update')
  .done(function() { console.log('success'); })
  .fail(function() { console.log('error'); });
benzon commented 8 years ago

Would look better if we had a scrolling div with the output from the server to be honest, just so you can see whats happening most using a tool like arkmanager use it because it's easy or they dont got a clue about how to setup things.

So just want to make the web interface easy for the user to use, and doing a log with FS should be easy enough, and the webinterface is easy to get running we should be able to do that true NodeJS and just do a plain HTML output.

benzon commented 8 years ago

https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

FezVrasta commented 8 years ago

a GUI is done so that user don't have to play with the console.

Handle the results of the API and show whatever you prefer.

Lihis commented 8 years ago

Um.. Do you mean that API should show html code? As far as I know the reason for API is to enable 3rd party apps that generates the user interfaces from the different API calls.

benzon commented 8 years ago

Lihis the API has to do a log of the process running since the API is the one calling the arkmanager, so the interface cant generate a log file or the live output from the process the API spawned.

@FezVrasta think we are talking about the same more or less. what i did in php is have buttons for the different options, start, stop, restart, the different update options etc. but when a user push ex. update it shows a textbox(div) that outputs the contet from the exec.

FezVrasta commented 8 years ago

Here a better example, I hope it will be clear enough.

the result of /api/status will be:

{
  "running": false,
  "listening": false,
  "version": "0.0.0"
}

You may use it from JS in this way:

$.get('/api/status')
  .done(function(res) {
    alert(`Running: ${res.running.toString()}, Listening: ${res.listening.toString()}, Version: ${res.version}`);
  })
  .fail(function() { alert('something went wrong, is your API up?'); });
FezVrasta commented 8 years ago

Replying to your last comment, if I just want to have an online console I would run tty.js and use it...

We want a full RESTful API to be able to use every feature of ARK Server Tools from any 3rd party app.

benzon commented 8 years ago

Again thing we are talking about the same just me that cant explain it the right way.

What i got currently, page with buttons to call the different function could be converted to use the RestAPI with in an hour.

What i did tho is when a user push start it shows a window with the same output you would get via SSH, just so they can se things running, think this is important for updates, since steam quite often have the idea about hanging on mod updates for 5 min or more.

FezVrasta commented 8 years ago

The point is that the user doesn't care about the output of the CLI. He just need the result.

If you want to show a verbose output (eg: "updating mod1, updating mod2, etc") then we should add a specific API endpoint to retrieve the list of installed mods and another endpoint to update a specific mod.

In this way you could show the user the progress. Is this what you need?

eg:

get mods list GET /api/mods

{
  "mods": [ "mod1", "mod2" ]
}

update mod PUT /api/mod?id=mod1

{
  "success": true
}
benzon commented 8 years ago

Okay i might have to do the api my way then hehe for me it's important that the end user knows whats happening and not waiting 5 min until ex mod updates are done.

Just found a nother thing that would be nice integrating in to the API.

https://github.com/gpittarelli/node-ssq

Then we could do API call's and get current users online, stuff like that.

FezVrasta commented 8 years ago

Read my updated answer.

About node-ssq, you can directly use the ARK Server Tools RCON implementation I guess.

benzon commented 8 years ago

Ye but thats raw text not easy to work with where node-ssq is JSON.

FezVrasta commented 8 years ago

Ok this is up to you and it's out of the scope of this issue. Once an API is ready, everyone will be able to do what they prefer on their 3rd party apps

Lihis commented 8 years ago

@benzon Sorry, I misunderstood you. Yeah, logging for only errors maybe might be good idea.

Before going to that I think we should start from basic features like getting number of players in server etc. first?

FezVrasta commented 8 years ago

Waiting @klightspeed to implement some kind of JSON output from ARK Server Tools, then we can quickly implement the end-points in the REST server.

FezVrasta commented 8 years ago

@Lihis I'm not sure if you have bash knowledge, if so, and if you have time, you may try to implement the JSON output by yourself.

Lihis commented 8 years ago

@FezVrasta I have some (look the arkwrapper in my profile). I'll start working on that.

What do you think about separating the API from arkmanager? I mean creating new repository for the API. I'm just thinking about the future and that situation when the API and arkmanager issues are messed up in here.

FezVrasta commented 8 years ago

For now I think that just a different branch is okay, then we can create a new repository and pubblish everything there once done. Is it okay?

Lihis commented 8 years ago

Sounds good for me.

klightspeed commented 8 years ago

The status stuff should be easy enough to do as JSON.

For long-running tasks such as installing mods, updating, or restarting with a warning, it may be necessary to make the background process that runs the server be a server manager, and have updates etc. run under that process, with e.g. a command pipe to send commands to the server manager. The API can then monitor the server log for the progress of any commands.

ronindesign commented 1 month ago

Still interested in this. Obviously, I'm sure there's lower interest in ARK these days, but we still play and use this awesome tool. A basic JSON status response would be fantastic!

Thanks for all the work on this tool over the years, we wouldn't still be playing without this tool!

klightspeed commented 1 month ago

I had moved the contents of https://github.com/arkmanager/ark-server-tools/tree/api/api to https://github.com/arkmanager/arkmanager-nodejs, though I haven't done anything with it.