PDA

View Full Version : maxs shutdown script



Roger the Shrubber
2005-10-26, 00:15
>If you're running your server on Linux, I've got a
>perl script that will shut down the server after a
>particular time if no player's are currently
>playing. If they are, it tries again later. Before
>shutting down, it displays a warning on each
>player. http://www.thespicers.net/slim.html#misc
>
>Max

Hey Max, I was hoping for a solution just like that, thanks!
But can you tell me: Do I need to set the permission of the file in some special way? And how exactly do I 'cron' something like this?

I'd like it to look for an open SSH/SFTP connection (when I'm working on the server), but I'll try and have a go at that myself.

max.spicer
2005-10-26, 00:39
What level of linux/unix knowledge do you have?

You need to make sure that the file is executable by root. Do something like "chmod u+x shutdown.pl".

There's a comment at the top of the script with an example cron entry. To find out about cron, type "man crontab". Ask in the UNIX/Linux forum if you need more help and I'll do my best!

You probably don't want to look for an open connection. If you're logged in, you'll get a console message telling you that the server will shut down in 5 minutes anyway. At this point, just stop it. I can't actually remember how to stop it right now - I'll get back to you on that!

Max


Hey Max, I was hoping for a solution just like that, thanks!
But can you tell me: Do I need to set the permission of the file in some special way? And how exactly do I 'cron' something like this?

I'd like it to look for an open SSH/SFTP connection (when I'm working on the server), but I'll try and have a go at that myself.

max.spicer
2005-10-26, 04:37
Just noticed that you were in the linux/unix forum. Still haven't woken up yet!

If you want to cancel a shutdown that is started by my script, you currently have to log on to the server and type "shutdown -c". Unfortunately, the script will run again in x minutes time and so start another shutdown. I'm thinking of having it check for a file and not shutdown if it's present. I could then make shutdown.pl take a command line argument of -c that would create this file for you and cancel a scheduled shutdown. The script itself could then be made to delete the file the next day, so the automatic shutdown then carries on as normal. Does this sound sensible?

Max


What level of linux/unix knowledge do you have?

You need to make sure that the file is executable by root. Do something like "chmod u+x shutdown.pl".

There's a comment at the top of the script with an example cron entry. To find out about cron, type "man crontab". Ask in the UNIX/Linux forum if you need more help and I'll do my best!

You probably don't want to look for an open connection. If you're logged in, you'll get a console message telling you that the server will shut down in 5 minutes anyway. At this point, just stop it. I can't actually remember how to stop it right now - I'll get back to you on that!

Max

Roger the Shrubber
2005-10-26, 05:02
Awake, but at work. I'll try this evening and let you know how it went.
The thing is, I could copy my files across the network over night with SFTP and let the SFTP program close the connection, after which the server could shut down. I checked once before and there is a SSH process involved with the SFTP connection too, so just checking for that would be enough.
The backup might last anywhere between ten minutes and several hours and maybe even a day or more.
More later...

Roger the Shrubber
2005-10-26, 14:28
I got it running pretty quickly with cron after putting the CLI port back to default.
For ease of use it would really be best if the script would check for some process running instead of manually having to put a file somewhere or having to log in to prompt seperately.

Also, would it be possible to write the status of the players to a file? It could work like:
- run the script more frequently (every 5 minutes or so)
- somehow keep track of when a player was last active
- next time it runs and players are off AND have been inactive for 30 minutes shutdown.

That way it would avoid shutting down while you're finding the next album to play or something. It's quite a bit more complicated of course.

Roger the Shrubber
2005-11-01, 15:30
I've been trying to code what I wanted and I came up with this. I guess it will look funny to anyone actually any good with perl :) Suggestions entierly welcome.

The server will shutdown if:
- none of the players have been playing for a certain time
- the server is not scanning the music library
- a specified process is not running (works with ssh, should work for telnet or ftp too, I reckon)

It's quite different from Maxs version in that it doesn't shut down when no player happens to be playing at the very moment the script is running, but tries to keep a bit of history in a file. It therefore needs to run more regularly. To me it does seem like a fairly heavy script to run so often. (Is it?)

I'd like to add the possibility to not shut the server down within say 30 minutes after it was started (to avoid: WOL server, go make coffee, forget about server a bit, come back and find its shut down again). That seems pretty obvious with 'uptime', but I don't think that would work with a suspended/resumed system.
If possible I'd also like to avoid writing the status file to disk, but I'm not sure how to store stuff in environment variables if that's at all possible and good form.

stinga
2005-11-02, 00:10
On 01/11/05 22:30:51, Roger the Shrubber wrote:
>
> The server will shutdown if:
> - none of the players have been playing for a certain time
> - the server is not scanning the music library
> - a specified process is not running (works with ssh, should work
> for telnet or ftp too, I reckon)
>
> I'm not sure how to store stuff in environment variables if that's at
> all possible and good form.
>

Maybe you want to run it as a daemon and not from cron, startit at boot
time that way you don't need to bother with status files, env vars
won't work.

Seems to me that most of this code already exists in slimserver, in the
screen saver area.
Just need to add a shutdown option there.

--
'ooroo

stinga...(:)-)
---------------------------------------------------
Email: stinga (AT) wolf-rock (DOT) com o
You need only two tools. o /////
A hammer and duct tape. If it /@ `\ /) ~
doesn't move and it should, > (O) X< ~ Fish!!
use the hammer. If it moves and `\___/' \) ~
shouldn't, use the tape. \\\
---------------------------------------------------

jonolumb
2005-11-10, 06:47
are there any scripts available that allow a manual shutdown (as in not on a timer) via the remote.
I am running Fedora Core 4. If none are available- how would I go about making one.
Jono

max.spicer
2005-11-10, 07:09
I would imagine that this is very easy to do with the execute script plugin.

Max


are there any scripts available that allow a manual shutdown (as in not on a timer) via the remote.
I am running Fedora Core 4. If none are available- how would I go about making one.
Jono

jonolumb
2005-11-10, 09:08
Ok I'll go and have a look and a play.
Thanks
Jono

hellesangel
2006-10-25, 14:00
This might be a bit of a dim newbies question, but you've got to start somewhere.

When I run the Perl script to test it I always get the
Couldn't connect to server at shutdown.pl line 27.

Error message, which is the IO::Socket call. Checking to see what Perl modules are installed I'm not entirely sure this is installed, unless it's part of the standard Perl install. The Slimserver is running on this machine so the rest should be OK.

The computer has perl, v5.8.7 built for i586-linux-thread-multi installed, and is running SUSE 10.0.

shutdown.pl has the date stamp:
# $Date: 2005-10-30 14:26:26 +0000 (Sun, 30 Oct 2005) $ $Rev: 9 $

TIA

hellesangel
2006-10-29, 06:49
Ok, I got past the first problem by changing the TCP port mentioned in the script back from 9023 to 9000, but now when I run the script in a terminal it returns this:

Sent player count ? to server
Server replied: <HTML><HEAD><TITLE>405 Method Not Allowed</TITLE></HEAD>

<HTML><HEAD><TITLE>405 Method Not Allowed</TITLE></HEAD> players found
Argument "<HTML><HEAD><TITLE>405 Method Not Allowed</TITLE></HEAD>" isn't numeric in numeric lt (<) at ./shutdown.pl line 40, <GEN0> line 1.
0/<HTML><HEAD><TITLE>405 Method Not Allowed</TITLE></HEAD> players playing
Shutting down

And then proceeds to shut the server down. Now I could modify the Perl script so it doesn't do this but I don't know how the Slimserver works to find out which methods it supports. Server is Linux 6.5.0 9916.

Anyone able to help? I'd be very grateful.

Thanks in advance.

mherger
2006-10-29, 07:30
> Ok, I got past the first problem by changing the TCP port mentioned in
> the script back from 9023 to 9000, but now when I run the script in a
> terminal it returns this:

CLI is running on port 9090 - 9000 is the web server (hence the web
response)

--

Michael

-----------------------------------------------------------------
http://www.herger.net/SlimCD - your SlimServer on a CD
http://www.herger.net/slim - AlbumReview, Biography, MusicInfoSCR

hellesangel
2006-10-29, 08:11
That did the trick, many thanks.