For a service written in c#.
We have it set to auto-restart so if it crashes it will restart itself.
This is fine, but we also want a way to force stop the service (the service could be deadlocked). This would happen once a week before taking a database backup.
If we use "net stop" the service might not shut down.
If we do a taskkill this will kill the service but then it will start up again in one minute.
Any ideas on how to get both use cases working?
We want to auto-restart if the service crashes, and we want to be able to run an unattended process that will stop the service (no matter what), take a backup of the database, and then restart the service after that.
http://www.codeproject.com/Articles/31688/Using-the-ServiceController-in-C-to-stop-and-start
You need to add a library, then it's just:
service.Stop() and service.Start()
Related
I got a website in Laravel where you can click on a button which sends a message to a Python daemon which is isolated in Docker. This works for an easy MVP to prove a concept, but it's not viable in production because a user would most likely want to pause, resume and stop that process as well because that service is designed to never stop otherwise considering it's a scanner which is looped.
I have thought about a couple of solutions for this, such as fixing it in the software layer but that would add complexity to the program. I have googled Docker and I have found that it is actually possible to do what I want to do with Docker itself with the commands pause, unpause, run and kill.
It would be optimal if I had a service which would interact with the Docker instances with the criteria of above and would be able to take commands from HTTP. Is Docker Swarm the right solution for this problem or is there an easier way?
There are both significant security and complexity concerns to using Docker this way and I would not recommend it.
The core rule of Docker security has always been, if you can run any docker command, then you can easily take over the entire host. (You cannot prevent someone from docker run a container, as container-root, bind-mounting any part of the host filesystem; so they can reset host-root's password in the /etc/shadow file to something they know, allow remote-root ssh access, and reboot the host, as one example.) I'd be extremely careful about connecting this ability to my web tier. Strongly coupling your application to Docker will also make it more difficult to develop and test.
Instead of launching a process per crawling job, a better approach might be to set up some sort of job queue (perhaps RabbitMQ), and have a multi-user worker that pulls jobs from the queue to do work. You could have a queue per user, and a separate control queue that receives the stop/start/cancel messages.
If you do this:
You can run your whole application without needing Docker: you need the front-end, the message queue system, and a worker, but these can all run on your local development system
If you need more crawlers, you can launch more workers (works well with Kubernetes deployments)
If you're generating too many crawl requests, you can launch fewer workers
If a worker dies unexpectedly, you can just restart it, and its jobs will still be in the queue
Nothing needs to keep track of which process or container belongs to a specific end user
I have looked for a bit on Stack Overflow for a way to have a container start up and wait for an external connection but have not seen anything.
Here is what my process looks like currently:
Non-Docker external process reaches out at X interval and tells system to run a command.
Command runs.
System should remain idle until the next interval.
Now I have seen a few options with --wait or sleep but I would think that would not allow the container to receive the connection.
I also looked at the wait for container script that is often recommended but in this case I need the container to wait for a script to call it on non defined intervals.
I have tried having this just run the help command for my process but it then fails the container after a bit of time and makes it a mess for finding anything.
Additionally I have tried to have the container start with no command just to run the base OS and wait for the call but that did not work either.
I was looking at this wrong.
Ended up just running like any other webserver and database server.
I'm setup a database container with a script rc.db which provide standard init commands like:
/etc/rc.db start
/etc/rc.db stop
/etc/rc.db status
In Is it possible to install a complex server inside a Docker container?, I know I could use a simple script to start the db container(for example name as /etc/db_run.sh:
#/bin/sh
/etc/rc.db start
wait
And the Dockerfile
...
RUN /etc/db_run.sh
Because close database correctly is important. I wish when the container be stopped, it could call the /etc/rc.db stop.
When Docker tries to stop a container, it sends a SIGTERM signal, followed by a SIGKILL after a grace period. Just catch this signal and either call your script or pass it onto the DB process, whichever is appropriate.
I suspect that if you make the DB the main process running in the foreground, it will handle the signals correctly itself.
I'm using Supervisor to manage my node.js applicaton on an EC2 instance with git for deployment. Supervisor does a good job of making sure my application stays up, but whenever I push new server-side code to my remote server, it tends to not recognize those changes. I need to kill the supervisor process and restart it. Is there something I'm doing wrong, or is this standard behavior?
This is standard behaviour; supervisord does not detect changes in code. It only restarts processes if they themselves stop or die.
Just instruct supervisord to restart the application whenever you push changes. supervisorctl restart programname is fine, no need to kill and restart supervisord itself.
If the supervisord configuration changed, use supervisorctl update.
I occasionally find myself starting and stopping multiple windows services. The only tool I'm aware of for stopping and starting windows services is the "Services" program under "Administrative Tools" (%SystemRoot%\system32\services.msc /s). This program seems to only allow you to manipulate one service at a time, often pausing while it waits for the service to stop. There is a "Close" button available, but I'd prefer to just select all the services I want to stop or start, and perform a single command on all of them at one time.
Is there an easier way to start and stop multiple windows services for Windows XP?
Use the "net start" and "net stop" commands in your cmd.exe to start and stop a service:
net start "Service name with space"
net stop SerivceNameWithoutSpace
Be aware that you will need quotes if the service name has spaces.
It possible to start/stop Windows services by using command-line tools such as net start and net stop and sc.exe, but as far as I known none of them allows to operate on more than one service at once.
The easiest solution is to invoke the command-line tool multiple times by specifying different service names in a batch file.
Also, note that the reason why there is a delay between issuing a stop command to a Windows Service and the time when the process actually exits, is due to the fact that the Windows Service Controller waits up to 30 seconds to allow services to shutdown properly.If a service doesn't exit by that time, a message will inform you that "the service didn't respond in a timely fashion". More details can be found here.
You could use powershell.
Something like :
get-service -displayname SQL | stop-service
This stops all services with SQL in their display name.
http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/stop-service.mspx
What about the command line?
The net start and net stop commands are where you're going...
Try msconfig (go to the "Run" dialog, type "msconfig"). Choose the "services" tab.
You could write a command/batch script that uses the command-line service controller, sc.exe.
Alternatively, you could check out the SysInternals psservice.exe command-line tool.