1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Services stop when upgrading ports?

Discussion in 'Installation and Maintenance of Ports or Packages' started by xy16644, Oct 2, 2009.

  1. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    One thing I have noticed when upgrading my ports is that after the upgrade is complete many services on my server have been stopped. Is this normal?

    For instance, yesterday there were a couple ports that I upgraded and my Courier Authlib, Courier IMAP and SpamAssassin service was stopped.

    Is this what happens when your ports are upgraded? Do I need to check ALL my services after upgrading my ports everytime?
     
  2. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,622
    Thanks Received:
    2,384
    That's normal. If a package is removed, the service is stopped. When a package is installed it's not started automatically.
     
  3. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Thank you!

    I need to get into the habit of making sure all services are started after updating all my ports...
     
  4. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Not all ports behave in exactly the same way. E.g. dovecot will ask you whether to stop the service or not. MySQL on the other hand simply stops the service, without giving any feedback about it. So yes, always check.
     
  5. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Yeah, I found that out the hard way! It stopped my authlib and IMAP services and people couldn't login to web mail anymore for a few hours. It had me puzzled until I went through the necessary logfiles...

    Thanks for the advice.
     
  6. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Code:
    for script in /usr/local/etc/rc.d/*
    do
    $script restart
    done
    

    ;)
     
  7. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    That looks helpful!

    Do I just copy that into a file and run it after I have run the upgrade of the ports?
     
  8. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Sure! Might be better to fine-tune it a little instead of just restarting everything. Lemme work on that and get back to you here.
     
  9. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    What if you just say start the services that are stopped:

    Code:
    for script in /usr/local/etc/rc.d/*
    do
    $script start
    done
    


    Or have I over simplified it? :e
     
  10. dennylin93

    dennylin93 New Member

    Messages:
    784
    Thanks Received:
    104
    It should only start the services that are enabled it /etc/rc.conf, so there shouldn't be a problem.
     
  11. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Code:
    #!/bin/sh
    for script in /usr/local/etc/rc.d/*; do if $script rcvar | grep -q "=[yY][eE][sS]" && \
    $script status | grep -q 'not running'; then $script start; fi; done
    


    This will only start services defined in /etc/rc.conf ("yes", "YES", combinations thereof) which are not running now. Ports-based services only, of course.
     
  12. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Wow thanks! I'm glad you wrote that.

    I created a file called restart and pasted everything into it but when I run it as follows:
    Code:
    ./restart
    


    It says: Permission denied (while I am logged in as root)
     
  13. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Make it executable ;) (chmod 500 should suffice).
     
  14. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Sorry blonde momoent, I had to run chmod 700 on it!

    It works like a charm! I stopped my ClamAV service and it restarted it...thank YOU!!
     
  15. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    How do I put a comment in the script so I know what this script does for when I look at the code in the future?
     
  16. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Just put a line in there starting with '#' (without the quotes).
     
  17. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Thats what I did and it says:
    Code:
    for: Command not found.
    script: Undefined variable.
    


    The script looks as follows now (I used your comments):
    Code:
    #This will only start services defined in /etc/rc.conf ("yes", "YES", combinations thereof)
    #which are not running now. Ports-based services only, of course.
    #!/bin/sh
    for script in /usr/local/etc/rc.d/*; do if $script rcvar | grep -q "=[yY][eE][sS]" && $script status | grep -q 'not running'; then $script start; fi; done
    
     
  18. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Put those two comments at the bottom of the script. This looks like (t)csh. It may be a bit picky when it comes to the location of the hashbang (the magic '#!' invocation). Other shells care less, but I guess (t)csh wants it front and center, i.e. at the start of the first line.
     
  19. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Final note: not all rc.d scripts appear to have the 'status' command. E.g. I found this one:

    Code:
    /usr/local/etc/rc.d/mailman: unknown directive 'status'.
    Usage: /usr/local/etc/rc.d/mailman [fast|force|one](start|stop|restart|rcvar|reload)
    


    So if you ever encounter one of those you'll have to check it by hand. Of course, I could just make the script increasingly/eerily adaptive and over half a page long ;)
     
  20. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    I moved the comments to the end and all worked like a charm.

    I think you wrote an awesome script in only 2 lines...;-)
     
  21. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,765
    Thanks Received:
    1,870
    Cheers!
     
    xy16644 thanks for this.
  22. xy16644

    xy16644 Member

    Messages:
    846
    Thanks Received:
    9
    Sorry to open this thread up again but the script I have been using to restart services that have stopped due to a port being upgraded no longer works :(

    I'm still running:
    Code:
    #!/bin/sh
    for script in /usr/local/etc/rc.d/*; do if $script rcvar | grep -q "=[yY][eE][sS]" && \
    $script status | grep -q 'not running'; then $script start; fi; done
    


    But even after running this, I still find that there are services that are in a stopped state and I have to start them up manually.

    What would have caused this script to stop working?
     
  23. aa

    aa New Member

    Messages:
    48
    Thanks Received:
    9
    Could be anything. What services actually are they?
    Try first to run those services in the correct order:
    Code:
    for script in `rcorder /usr/local/etc/rc.d/* 2>/dev/null`; do ..
    


    Maybe they depend also on then stopped /etc/rc.d/* services?