Raised This Month: $51 Target: $400
 12% 

Signals


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Robotex
Junior Member
Join Date: Mar 2016
Old 03-18-2017 , 21:13   Signals
Reply With Quote #1

I'm wondering is there something that allows a script to intercept signals such as SIGINT/SIGTERM on linux or CTRL_CLOSE_EVENT on Windows?
If not, is there a function/forward that will notify a script that the server is about to shutdown (after pressing CTRL+C for example) and allow me to cancel the shutdown process?

Thanks in advance.
Robotex is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-18-2017 , 22:09   Re: Signals
Reply With Quote #2

No.

You can implement a signal handler in an extension, I guess. On Linux, you could use bash's trap (probably also available in most shells) to set the server to ignore whatever signals you want before you start it.

It seems really weird that you would want this, though.
Fyren is offline
Robotex
Junior Member
Join Date: Mar 2016
Old 03-19-2017 , 06:13   Re: Signals
Reply With Quote #3

Quote:
Originally Posted by Fyren View Post
No.

You can implement a signal handler in an extension, I guess. On Linux, you could use bash's trap (probably also available in most shells) to set the server to ignore whatever signals you want before you start it.

It seems really weird that you would want this, though.
I don't want to ignore the signals but actually use them to notify my scripts to do some actions.
One common case is when you run SRCDS in a Docker container, whenever a stop command is performed it sends a SIGTERM signal to the process and I would like to run some triggers and cleanup before it shuts down gracefully.

Sure, I could find other ways to do the same like constantly polling for some specific files that have the only purpose of triggering actions, but it seems a bit "hackish" way to do what I want to achieve.
Robotex is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-19-2017 , 09:34   Re: Signals
Reply With Quote #4

In general, you can't just do whatever you want in a signal handler because they interrupt your main program flow. To be safe, an extension would probably do no more than set a flag in the handler with the flag(s) being polled elsewhere. It's conceptually not much different from files, though I suppose less expensive, relatively.

You have other choices for communication that don't require much work such as rcon or directly sending commands to the terminal (easily done with screen/tmux).
Fyren is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode