Only restart services when the corresponding file has been modified recently
This commit is contained in:
parent
7d6e339e08
commit
44a7cb6f5a
10
README.md
10
README.md
@ -86,8 +86,14 @@ The options are as follows:
|
||||
|
||||
> An optional file that contains a list of services to enable on the remote
|
||||
> host.
|
||||
> If a service is already enabled, it will be restarted each run of
|
||||
> **boxctl**.
|
||||
> Each line in the file should contain "name:path".
|
||||
> Where "name" is the name of a service (httpd for example) and "path" is the
|
||||
> full path to a file that when modified, should trigger a restart of the named
|
||||
> service.
|
||||
> For example, the entry "httpd:/etc/httpd.conf" would restart
|
||||
> httpd(8)
|
||||
> if the mtime on "/etc/httpd.conf" is less than 100 seconds from the current
|
||||
> time.
|
||||
|
||||
*$CWD/groups*
|
||||
|
||||
|
23
boxctl.sh
23
boxctl.sh
@ -69,10 +69,19 @@ EOF
|
||||
)
|
||||
|
||||
SERVICE_START_RESTART=$(cat <<EOF
|
||||
/usr/sbin/rcctl enable %s; \
|
||||
/usr/sbin/rcctl check %s && \
|
||||
/usr/sbin/rcctl restart %s || \
|
||||
/usr/sbin/rcctl enable %s;
|
||||
if /usr/sbin/rcctl check %s; then
|
||||
AGE=\$(stat -s %s | awk -v now=\$(date +%%s) \
|
||||
'{split(\$10,a,"="); print now - a[2]}')
|
||||
if [ \$AGE -lt 100 ]; then
|
||||
logger -t boxctl "restarting %s (\$AGE seconds old)"
|
||||
/usr/sbin/rcctl restart %s
|
||||
else
|
||||
logger -t boxctl "not restarting %s (\$AGE seconds old)"
|
||||
fi
|
||||
else
|
||||
/usr/sbin/rcctl start %s
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
@ -258,10 +267,14 @@ fi
|
||||
|
||||
if [ -f ./services ]; then
|
||||
msg 0 "enabling services $(wc -l services | awk '{print $1 " " $2}')"
|
||||
local _svc _chfile
|
||||
for service in $(cat services); do
|
||||
msg 1 "\tenabling/restarting ${service}"
|
||||
read _svc _chfile <<EOF
|
||||
$(echo $service | sed 's/:/ /g')
|
||||
EOF
|
||||
msg 1 "\tenabling/restarting ${_svc}"
|
||||
cmd="$(printf "$SERVICE_START_RESTART" \
|
||||
$service $service $service $service)"
|
||||
$_svc $_svc $_chfile $_svc $_svc $_svc $_svc)"
|
||||
_ssh ${RUN_USER}@${SERVER} "${cmd}"
|
||||
done
|
||||
fi
|
||||
|
@ -1 +1 @@
|
||||
httpd
|
||||
httpd:/etc/httpd.conf
|
||||
|
10
man/boxctl.8
10
man/boxctl.8
@ -83,8 +83,14 @@ If this file does not exist, no files are copied.
|
||||
.It Pa $CWD/services
|
||||
An optional file that contains a list of services to enable on the remote
|
||||
host.
|
||||
If a service is already enabled, it will be restarted each run of
|
||||
.Nm .
|
||||
Each line in the file should contain "name:path".
|
||||
Where "name" is the name of a service (httpd for example) and "path" is the
|
||||
full path to a file that when modified, should trigger a restart of the named
|
||||
service.
|
||||
For example, the entry "httpd:/etc/httpd.conf" would restart
|
||||
.Xr httpd 8
|
||||
if the mtime on "/etc/httpd.conf" is less than 100 seconds from the current
|
||||
time.
|
||||
.It Pa $CWD/groups
|
||||
A ":" delimited list of groups to be added to the remote host.
|
||||
Entries should follow a "group:gid" pattern.
|
||||
|
Loading…
Reference in New Issue
Block a user