Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Restart on if something changed?

0 views
Skip to first unread message

PAUL WILLIAMSON

unread,
Jan 26, 2006, 9:28:13 AM1/26/06
to help-c...@gnu.org
How can I tell a process to restart only if a certain file has changed?

We just changed the way our login banners are supposed to occur.
Before, they appeared prior to login, so I could just use the
sshd_config file and specify an banner in the file. Now, I need
to present the banner after login. In order to do this, I need to
restart sshd. But, I don't want to restart sshd during the
middle of the day or when the sshd_config file hasn't changed.

Paul

Brendan Strejcek

unread,
Jan 26, 2006, 11:32:00 AM1/26/06
to PAUL WILLIAMSON, help-c...@gnu.org
PAUL WILLIAMSON wrote:

How are you updating sshd_config? If it is via a cfengine copy action,
you can define a class in that statement and then make your processes or
shellcommands action conditional upon that class. If you are updating
the file with a system that is not under cfengine control, you can
maintain a datestamp file separate from the sshd_config file, and
restart sshd (along with updating the datestamp file) if the last
modified time of the sshd_config file is more recent than the last
modified time of the datestamp file. If you choose that strategy, you
will probably want to use the IsNewerThan evaluated class. You can
find details on that at:

http://www.cfengine.org/docs/cfengine-Reference.html#Evaluated-classes-and-special-functions

Let me know if you want some example cfengine code for this.

Best,
Brendan

--
Senior System Administrator
The University of Chicago
Department of Computer Science

http://www.cs.uchicago.edu/people/brendan
http://praksys.blogspot.com/


Marco van Beek

unread,
Jan 26, 2006, 11:40:24 AM1/26/06
to PAUL WILLIAMSON, help-c...@gnu.org
Hi Paul,

Use a copy command that copies this specific file, and then use define
to add the box to a "restart_ssh" class, that you use later with in a
shellcommand.

From the manual:

define
This option is followed by a list of classes which are to be
`switched on' if and only if the named file was copied. In multiple
(recursive) copy operations the classes become defined if any of the
files in the file tree were copied. This feature is useful for switching
on other actions which are to be performed after the installation of key
files (e.g. package installation scripts etc).

Regards,

Marco

PAUL WILLIAMSON wrote:
> How can I tell a process to restart only if a certain file has changed?
>
> We just changed the way our login banners are supposed to occur.
> Before, they appeared prior to login, so I could just use the
> sshd_config file and specify an banner in the file. Now, I need
> to present the banner after login. In order to do this, I need to
> restart sshd. But, I don't want to restart sshd during the
> middle of the day or when the sshd_config file hasn't changed.
>

> Paul
>
>
>
> _______________________________________________
> Help-cfengine mailing list
> Help-c...@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-cfengine
>


Luis Cerezo

unread,
Jan 26, 2006, 11:59:20 AM1/26/06
to PAUL WILLIAMSON, help-c...@gnu.org
Paul,

What I did was to use DefineClasses in the editfiles section. this sets
the class only if the file is edited..

eg..

linux::
{ /etc/ssh/sshd_config
ReplaceAll "#Banner /some/path" With "Banner
/etc/issue"
DefineClasses "HUPsshd"
}
shellcommands:

linux.HUPsshd::

"/sbin/service sshd restart" useshell=false

this would only run the shellcommands if the class is defined, and that
only happens if the file is edited. you could then add the
time.class.hup doo-hickie and all should be well..

hth.

-luis


PAUL WILLIAMSON wrote:

>How can I tell a process to restart only if a certain file has changed?
>
>We just changed the way our login banners are supposed to occur.
>Before, they appeared prior to login, so I could just use the
>sshd_config file and specify an banner in the file. Now, I need
>to present the banner after login. In order to do this, I need to
>restart sshd. But, I don't want to restart sshd during the
>middle of the day or when the sshd_config file hasn't changed.
>
>Paul
>
>
>
>_______________________________________________
>Help-cfengine mailing list
>Help-c...@gnu.org
>http://lists.gnu.org/mailman/listinfo/help-cfengine
>
>

--
Luis E. Cerezo


Jason Martin

unread,
Jan 26, 2006, 12:08:06 PM1/26/06
to help-c...@gnu.org
On Thu, Jan 26, 2006 at 09:28:13AM -0500, PAUL WILLIAMSON wrote:
> How can I tell a process to restart only if a certain file has changed?
Assuming that the banner is put in place by CFE, have the copy
statement 'define' a class when it updates the file. Then, put a
entry in processes that kills / restarts SSHD if that class is
true, and another stanza that is based on that class being false
that just verifies sshd is running.

copy:

any::
/some/file
dest=/other/file
define=restart_sshd

processes:

restart_sshd::
"sshd" signal=kill restart "/etc/init.d/sshd start"

!restart_sshd::
"sshd" restart "/etc/init.d/sshd start"


Or something along those lines.

-Jason Martin
--
"Apple" (c) 6024 b.c., Adam & Eve
This message is PGP/MIME signed.

Doug Chapman

unread,
Jan 26, 2006, 12:09:30 PM1/26/06
to PAUL WILLIAMSON, help-c...@gnu.org
For copy's, just use define=reloadsshd in your copy: stanza, then you can create a shell commands section to restart.  You'll need to hold back the copy operation with any time/date/machine classes to avoid a business hours restart.

shellcommands:
 reloadsshd::              
    "/sbin/service sshd restart" inform=false

(or use motd- no need to restart)

On 1/26/06, PAUL WILLIAMSON <pwill...@mandtbank.com> wrote:
How can I tell a process to restart only if a certain file has changed?

We just changed the way our login banners are supposed to occur.
Before, they appeared prior to login, so I could just use the
sshd_config file and specify an banner in the file.  Now, I need
to present the banner after login.  In order to do this, I need to
restart sshd.  But, I don't want to restart sshd during the
middle of the day or when the sshd_config file hasn't changed.

Paul



_______________________________________________
Help-cfengine mailing list
Help-c...@gnu.org
http://lists.gnu.org/mailman/listinfo/help-cfengine



--
Doug Chapman
prjctgeet at gmail dot com

Atom Powers

unread,
Jan 26, 2006, 12:10:18 PM1/26/06
to PAUL WILLIAMSON, help-c...@gnu.org
copy the new file at night, and define a class to restart sshd.
--
copy:
Hr01::
${masterfiles}/${ssh_banner}
dest=${ssh_banner}
define=newsshd

shellcommands:
newsshd::
"${restart_scripts}/sshd restart"
--

On 1/26/06, PAUL WILLIAMSON <pwill...@mandtbank.com> wrote:
> How can I tell a process to restart only if a certain file has changed?
>
> We just changed the way our login banners are supposed to occur.
> Before, they appeared prior to login, so I could just use the
> sshd_config file and specify an banner in the file. Now, I need
> to present the banner after login. In order to do this, I need to
> restart sshd. But, I don't want to restart sshd during the
> middle of the day or when the sshd_config file hasn't changed.
>
> Paul
>
>
>
> _______________________________________________
> Help-cfengine mailing list
> Help-c...@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-cfengine
>


--
--
Perfection is just a word I use occasionally with mustard.
--Atom Powers--


Mark Burgess

unread,
Jan 27, 2006, 5:37:16 AM1/27/06
to PAUL WILLIAMSON, help-c...@gnu.org

Here's arough sketch:

classes:
restart = ( IsNewerThan() )


or

files:

/file checksum=md5 define=xxx


processes:

restart||xxx::

"process" signal=term restart "/...."

christian pearce

unread,
Feb 2, 2006, 11:30:12 AM2/2/06
to PAUL WILLIAMSON, help-c...@gnu.org
http://cfwiki.org/cfwiki/index.php/Universal_SSHD_restart

This method is fairly universal. I have been in Sun environments that
didn't have a great set of standards for the /etc/init.d/ restart
script. Since packagers like SMC didn't provide them. Or maybe they
installed by source.

As far as the timing, I would just use a class of when you want it
check like Hr01 before the statement that is going to do the file
alternation. Whether it is a copy, editfiles, or shellcommand. Then
use define=sshd_config_modified to trigger the restart.

Christian

On 1/26/06, PAUL WILLIAMSON <pwill...@mandtbank.com> wrote:
> How can I tell a process to restart only if a certain file has changed?
>
> We just changed the way our login banners are supposed to occur.
> Before, they appeared prior to login, so I could just use the
> sshd_config file and specify an banner in the file. Now, I need
> to present the banner after login. In order to do this, I need to
> restart sshd. But, I don't want to restart sshd during the
> middle of the day or when the sshd_config file hasn't changed.
>
> Paul
>
>
>
> _______________________________________________
> Help-cfengine mailing list
> Help-c...@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-cfengine
>


--
Christian Pearce


0 new messages