Turn off and on Elastix server automatically?

Discussion in 'General' started by eiger3970, Feb 10, 2011.

  1. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Dear Elastix,
    is there a way to automatically turn off and on the Elastix server?
    Maybe a task scheduler?

    Cheers,
    eiger3970.
     
  2. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    service asterisk stop; service httpd stop; service postfix stop

    will pretty well kill it dead

    service asterisk start; service httpd start; service postfix start

    will revive it magically, look into cron jobs to do that on schedule (cron is what we call the "task scheduler" in Linux, tasks are generally services . . . Elastix is more than one service), you can also use the linux program "at" or some BIOS's to do that also, pretty well anything you want to do is covered in linux, just RTFM's :)

    If that isn't enough, then

    init 1

    will remove your box from the network

    init 3

    will add it back
     
  3. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Hi Dicko,
    thanks for the reply.
    I have been looking at cron to turn off the Elastix server at a certain time each night and turn on at a certain time each morning.

    I have been searching for a tutorial on cron as I'm a bit weak in the bash commands.

    Would you know a command or point me to a tutorial to set this up.

    Thanks.
     
  4. netaires

    Joined:
    Apr 13, 2010
    Messages:
    218
    Likes Received:
    1
    Hello. Yes, you can.

    Add this line under your file etc/rc.local

    shutdown hh:mm

    Where hh and mm are the hours and minutes respectively that you want your Elastix off.

    The onset can be done with the setup of the BIOS of your motherboard called Power Management.

    If you want to shut down or restart your computer outside these times should take the following measures:

    Login with putty.exe
    shutdown -c
     
  5. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Thank you netaires:

    Although your idea would work, it is cracking a walnut with a sledgehammer, he asked to stop asterisk, not shutdown the whole system.

    How would you do the corollary of

    . . .restart your computer INSIDE these times . . . ? yes it's possible but please put that sledghammer down.

    Be careful in linux to not "shoot yourself in the foot", please always use the least impactful method to achieve your desire. that applies to firewalls, services and run levels, without local access you are generally stuck twiddling your thumbs and waiting for a "truck-roll" if you get it wrong.

    regards

    dicko
     
  6. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Hi and thanks for the replies.

    I do actually need the whole PC shutdown, and the turned on.

    I didn't quite understand netaires comments on 'If you want to shutdown or restart your computer outside these times'.

    What do you mean outside these times?

    Also, I couldn't find the file etc /rc.local.

    I went to Elastix, System, Updates, Packages and searched for the file etc and rc but there were no search results.
     
  7. netaires

    Joined:
    Apr 13, 2010
    Messages:
    218
    Likes Received:
    1
    Hello. Sorry if I understand correctly.
    My language is Spanish. I only saw the question and try to help. I have no fluent English.
    With the information provided my computer shuts down at 0:15 am and then turned on at 6:15 am.

    I think that is what initially consulted on the forum.

    Thanks and good luck.
     
  8. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Indeed netaires, you understood eiger3970 better than I, ++karma to you from me.
     
  9. netaires

    Joined:
    Apr 13, 2010
    Messages:
    218
    Likes Received:
    1
    I read this forum almost daily and especially their responses. You have very high knowledge of VoIP. Thank you very much for your work in this forum.
    I tell you, I have an Elastix server in my house and some "extensions" elsewhere. Like much research on VoIP.
     
  10. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Thank you,

    Look into WOL (Wake On Lan) for more flexibility. Where a "magic Packet" with the right MAC address sent to your properly configured router can save you a whole bunch of waiting until 6:15am :)
     
  11. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Thanks, karma for Dicko and netaires.

    Unfortunately, while I've been started and have read the tutorials I can't complete the shutdown at 2200 every night.

    I can't access the file etc/rc.local.

    In root folder I have run shutdown -c but receive error:
    shutdown: cannot find pid of running shutdown.

    In asterisk -r I have run shutdown -c but receive error:
    No such command 'shutdown -c' (type 'core show help shutdown -c) for other possible command).

    In root folder I have run shutdown -h 22:00. This seems to acknowledge the command, however I don't think it's for every night.

    In root folder I also don't know how to undo the command shutdown -h 22:00.

    In root folder I have run 22 0 * * * root /sbin/shutdown -h +5 but receive error:
    -bash: 22: command not found

    Please help.
     
  12. netaires

    Joined:
    Apr 13, 2010
    Messages:
    218
    Likes Received:
    1
    Do you have an Elastix distro?

    Centos 5.2 is in Elastix distro.

    If you don´t find your shutdown file/program try this:

    whereis shutdown

    Also Elastix distro has the /etc/rc.local file

    rc.local es like autoexec.bat in MS DOS 6.2, do you remember?

    Claudio from Argentina.
     
  13. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Thanks for the reply netaires.

    I have Asterisk 1.6.2.10 running Elastix 2.x and FreePBX 2.7.0.3.

    whereis shutdown worked and gave me loads of information.

    No success yet so I'll have to work on it.
     
  14. netaires

    Joined:
    Apr 13, 2010
    Messages:
    218
    Likes Received:
    1
    Re: Re:Turn off and on Elastix server automatically?

    Try this alternative:

    su -l
    contrab -e
    59 23 * * * /sbin/poweroff

    I think it should be done before the following:
    "amportal stop"
     
  15. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Thanks again netaires, karma added.

    Here's where I'm up to.

    I’ve tried entering the following commands into the vi editor with no success.

    Ideally, I’m trying to shutdown gracefully every night at 2200 would be ideal, but I need to find the right file (/etc/rc.local) and put that command into.
    This would be commands 6. and 8. below. that I’ve picked up off the forums.

    1.
    BOX: ADD OR REMOVE
    Init 1 (will remove box from the network)
    Init 3 (will add the box back to the network)

    2.
    BOX: START
    Service asterisk start
    or
    Service httpd start
    or
    Service postfix start

    3.
    BOX: STOP
    Service asterisk stop
    or
    Service httpd stop
    or
    Service postfix stop

    4.
    SHUTDOWN: ALTERNATIVE
    Su –l
    Crontab –e
    59 23 * * * \sbin\poweroff
    (type in before amportal stop).

    5.
    SHUTDOWN: COMMANDS
    Shutdown –c (I think this cancels a shutdown command?)
    Shutdown hh:mm (add this command under the file etc/rc.local)
    Whereis shutdown (find the shutdown file/program)

    6.
    SHUTDOWN: FREQUENCY/TIME/WARNING
    Crontab –e
    /etc/rc.local
    22 0 * * * root /sbin/shutdown -h +5 (shutdown at 2200 every night whether on a call or not).

    7.
    SHUTDOWN: GRACEFULLY STOP RECEIVING NEW CALLS
    Asterisk –rx stop gracefully (stop receiving new calls and shut down at empty call volume).

    8.
    SHUTDOWN: GRACEFULLY WHEN NO CALLS
    Asterisk –rx stop when convenient (shutdown Asterisk at empty call volume).
    Shutdown –h now (to power off the server).

    9.
    TUTORIAL
    Bash scripting.
    Cron.
     
  16. eiger3970

    Joined:
    Apr 29, 2009
    Messages:
    112
    Likes Received:
    0
    Thanks again netaires, karma added.

    Here's where I'm up to.

    I’ve tried entering the following commands into the vi editor with no success.

    Ideally, I’m trying to shutdown gracefully every night at 2200 would be ideal, but I need to find the right file (/etc/rc.local) and put that command into.
    This would be commands 6. and 8. below. that I’ve picked up off the forums.

    1.
    BOX: ADD OR REMOVE
    Init 1 (will remove box from the network)
    Init 3 (will add the box back to the network)

    2.
    BOX: START
    Service asterisk start
    or
    Service httpd start
    or
    Service postfix start

    3.
    BOX: STOP
    Service asterisk stop
    or
    Service httpd stop
    or
    Service postfix stop

    4.
    SHUTDOWN: ALTERNATIVE
    Su –l
    Crontab –e
    59 23 * * * \sbin\poweroff
    (type in before amportal stop).

    5.
    SHUTDOWN: COMMANDS
    Shutdown –c (I think this cancels a shutdown command?)
    Shutdown hh:mm (add this command under the file etc/rc.local)
    Whereis shutdown (find the shutdown file/program)

    6.
    SHUTDOWN: FREQUENCY/TIME/WARNING
    Crontab –e
    /etc/rc.local
    22 0 * * * root /sbin/shutdown -h +5 (shutdown at 2200 every night whether on a call or not).

    7.
    SHUTDOWN: GRACEFULLY STOP RECEIVING NEW CALLS
    Asterisk –rx stop gracefully (stop receiving new calls and shut down at empty call volume).

    8.
    SHUTDOWN: GRACEFULLY WHEN NO CALLS
    Asterisk –rx stop when convenient (shutdown Asterisk at empty call volume).
    Shutdown –h now (to power off the server).

    9.
    TUTORIAL
    Bash scripting.
    Cron.
     
  17. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    I suggest you find a good bash tutorial and be aware that cron runs under sh not bash so has a limited "path" be explicit

    either add to the cron table

    22 0 * * * root /sbin/shutdown -h +5


    /etc/rc.d is in effect a linux version of autoexec as stated, but does not belong in the crontab (point 6) , remove that line

    or perhaps a little shell scripting tutorial and hopefully a little more orderly shutdown . . .

    A) get an easier editor (or two) or get familiar with vi

    yum -y install mc nano

    then use nano mcedit or vi as you choose

    mcedit /var/lib/asterisk/bin/gotobed

    /var/lib/asterisk/ is the asterisk user's home directory , bin is where we conventionally put runnable programs, in that file put


    #!/bin/sh # use a simple shell like cron does (investigate hash/bang)

    #shutdown services sanely
    /sbin/service postfix stop # stop processing mail
    /sbin/service httpd stop # stop the web interface
    /usr/sbin/rasterisk -x 'stop when convenient' # commands to asterisk generally need quoting
    /sbin/service mysqld stop # stop the mysql server
    /sbin/shutdown -h +5 # shutdown in five minutes with a "wall" notice to all users




    save the file and make it executable or cron won't run it

    chmod +x /var/lib/asterisk/bin/gotobed


    add it to cron with cron -e

    22 0 * * * root /var/lib/asterisk/bin/gotobed


    at 10:05 the machine will orderly shut down, after all calls are hungup, five minutes later it will shutdown providing no-one with root privileges types shutdown -c in response to the shutdown message on the user's console

    You can check it's efficacy by issuing from a shell:


    /var/lib/asterisk/bin/gotobed
     
  18. danardf

    Joined:
    Dec 3, 2007
    Messages:
    8,069
    Likes Received:
    12
    Hi all, Hi dicko.

    Maybe make a little sync before shutdown ?

    Regards
     
  19. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Hi Franck, I believe shutdown will handle the file system's integrity, I suggest that active processes need more orderly termination.

    [edit]
    For elucidation, shutdown will run the kill scripts in the run-level you are at, presumably those in

    /etc/rc3.d

    K99* downwards, to save any ongoing calls I choose to prempt that order here.
     

Share This Page