mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

Modernized `start`, `stop`, `restart` and new `ensure` command

Open Nico8345 opened this issue 10 months ago • 10 comments

Modernized start, stop, restart commands which now also support directories, see the examples below, and a new ensure command, which restarts the already running resources specified as parameters, and starts the stopped ones. Closes #2549.

start play
start admin ip2c playercolors
start [web]

stop play
stop admin ip2c playercolors
stop [web]

ensure play
ensure admin ip2c playercolors
ensure [web]

restart play
restart admin ip2c playercolors
restart [web]

Nico8345 avatar Feb 13 '25 22:02 Nico8345

We should probably add an argument ensure to restartResource (defaulting to false)?

The reason I don't suggest adding a separate API function for this (e.g: ensureResource), is because we'd need to repeat the arguments and associated logic for those anyway.

Edit: since you'd need to upgrade restartResource to the new arg parser anyway, the code would actually end up being reasonably sized; having an additional function such as ensureResource wouldn't be so bad.

So, it's up to you and whatever others think is best.

Lpsd avatar Feb 14 '25 01:02 Lpsd

We should probably add an argument ensure to restartResource (defaulting to false)?

Why do you need that when you can get the state of your resource before calling? A new argument doesn't improve readability

TheNormalnij avatar Feb 14 '25 01:02 TheNormalnij

I suggest to remove a new 'ensure' command and just change 'restart' behavior. Current 'restart' behavior is disappointing.

TheNormalnij avatar Feb 14 '25 01:02 TheNormalnij

I suggest to remove a new 'ensure' command and just change 'restart' behavior. Current 'restart' behavior is disappointing.

I agree with this too, but would we want to change the behaviour of restartResource function by default?

Technically that isn't backwards compatible, someone may rely on the fact a resource must be running when this function or command is called.

Nonetheless, it would be much better behaviour for the restart command and function to start resources that aren't running, instead of doing nothing/returning false.

Lpsd avatar Feb 14 '25 01:02 Lpsd

Changing restart command functionality to support starting a resource even if it is stopped does not make sense, as the name implies a stop then a start, not just a start.

New ensure command makes sense, it's practical. I support it.

Fernando-A-Rocha avatar Feb 14 '25 09:02 Fernando-A-Rocha

We should probably add an argument ensure to restartResource (defaulting to false)?

The reason I don't suggest adding a separate API function for this (e.g: ensureResource), is because we'd need to repeat the arguments and associated logic for those anyway.

Edit: since you'd need to upgrade restartResource to the new arg parser anyway, the code would actually end up being reasonably sized; having an additional function such as ensureResource wouldn't be so bad.

So, it's up to you and whatever others think is best.

I guess we can discuss that later, but in a separate issue or pull request, this one is focused solely on improving the commands

Nico8345 avatar Feb 14 '25 13:02 Nico8345

Changing restart command functionality to support starting a resource even if it is stopped does not make sense, as the name implies a stop then a start, not just a start.

New ensure command makes sense, it's practical. I support it.

I want to introduce the new command because restart is well known and widely used, and I don't want to change that. ensure is also common in other game engine like multiplayer modifications, so it should feel familiar to developers interested in modern stuff

Nico8345 avatar Feb 14 '25 13:02 Nico8345

I want to introduce the new command because restart is well known and widely used, and I don't want to change that. ensure is also common in other game engine like multiplayer modifications, so it should feel familiar to developers interested in modern stuff

As far as I know, only FiveM has the ensure command. The suggested restart behavior is much more common in Linux, e.g. the service command works in this way. I expect that the restart command starts stopped services and resources. I can't imagine that somebody wouldn't expect to start a resource using the restart command.

I see no reason to have two commands with almost identical behavior instead of using one command with expected name.

Technically that isn't backwards compatible, someone may rely on the fact a resource must be running when this function or command is called.

I can't imagine a scenario when you need that. I would suggest writing a function that implements the old behavior if someone needs that. A failed restart commad forced me to use start in all my cases.

TheNormalnij avatar Feb 14 '25 21:02 TheNormalnij

Up

lynconsix avatar May 08 '25 01:05 lynconsix

This should have been merged a long time ago, pr dessa is very economical in some factors

lynconsix avatar Jun 01 '25 23:06 lynconsix

I'm okay with renaming the ensure command to restart if it matters in merging the pull request.

Nico8345 avatar Jul 15 '25 04:07 Nico8345

Good job 🥳🤙🏻 I think it might be better to integrate the behavior of ensure into the existing restart command. Users who want the behavior of ensure will likely use restart instinctively anyway. If a script isn't running, and someone uses restart, it's usually because they want it to start so letting restart handle both running and stopped resources could reduce confusion and eliminate the need to introduce a new command

MohabCodeX avatar Jul 31 '25 11:07 MohabCodeX

GG Good job

Kinimel avatar Jul 31 '25 19:07 Kinimel

I'm okay with renaming the ensure command to restart if it matters in merging the pull request.

Done. Now, the restart command is more Linux like.

Nico8345 avatar Jul 31 '25 21:07 Nico8345