0

I have development servers that are paid by the hour.
Some of the machines are not really in use for fiew days in a week, is there a mechanism that will shout down the server after X time that it is not active.
by active I mean, no ssh connctions, no disk changes and shuch...

Thanks

Cameron Kerr
  • 4,069
  • 19
  • 25
fatNjazzy
  • 69
  • 3
  • 11
  • 2
    That's tough... because a Linux system usually has a little activity going on. – Ryan Babchishin Aug 02 '16 at 06:36
  • 1
    You have to create this mechanism yourself. Use `w` to get currently logged in users, use `/var/log/auth.log` (or similar) to get latest logins, use something like `find /mydir -exec stat {} \; | md5sum` the detect changes in directory, etc. And prepare yourself for all the problems such "automation" is bound to cause :) – Erki Aring Aug 02 '16 at 07:43

2 Answers2

1

The server is always doing something (writing logs, running the init process, kernel stuff, etc). Are you actually asking, How do I tell when a user isn't utilizing the server?

User Activity

If you're after user activity, I'd look at the pinky command. I suggest you write a cronjob that runs every hour or so, and parses the output of pinky. It will show you when any of the active TTYs last had activity, and with what user.

$ pinky
Login    Name                 TTY      Idle   When             Where
jdoe      John Doe           ?:0       ?????  2016-07-28 13:13 :0
jdoe      John Doe           pts/1     00:14  2016-07-28 13:15 :1

Socket Activity

This is way less reliable, but if you just need to know if there are external connections to the server (HTTP, etc), you could parse the output of netstat -tupn. If the server makes outgoing connections, you'll probably need to filter those out.

Unless you know exactly what connections you're looking for, I don't recommend doing this. If you aren't extremely specific, your false positive rate (and accidental shutdowns) will probably be quite high.

BobTuckerman
  • 448
  • 3
  • 8
0

Usually these days, this is the basically done by autoscaling -- but that refers more to container instances running within some container environment such as Kubernetes (its a common feature in such environments).

You don't say whether these machines are hardware or virtual. If they were hardware machines, one somewhat classical solution would be to migrate to a virtualised environment (perhaps reusing the servers and improving server density and likely reducing server count), which would allow you to hot-migrate guests onto fewer hosts when fewer hosts are needed. I imagine VMWare probably already has tooling that does this already.

But you have said that this is a development environment, and so I offer you a couple of potential solutions.

1) Have something that simply shuts them down and starts them up on a schedule; whether the shutdown is activated via the likes of cron or some other enterprise job schedular is up to you; and you may not have access to start up the machines remotely. One consideration you need to factor is that you will want the machines to be available for patching and policy updates. A schedule would make for more consistent user expectations too. If hardware, BIOS settings could be used for booting, or a script against your/their virtual environment.

2) As this is a development environment, you could take a look at Vagrant, and move from one (presumably shared) development environment to one on each developers workstation... this is likely to be more of a shift than you would be prepared to make though. There is a bit of a learning curve, and you may need to increase resources available to developers, but your developers might jump at the chance, depending very much on how much you might want to embrace the concept of Infrastructure as Code (IaC) for repeatably provisioning environments.

... 3) Depending on your environment and the nature of the development system... I could imagine a HTTP load-balancer that when all member-servers were down, would redirect a client to a page that gave them the ability to request the environment be started.

Hope that gives you some fruitful ideas.

Cheers, Cameron

Cameron Kerr
  • 4,069
  • 19
  • 25