Skip to content

Commit

Permalink
added pre_unmount, post_unmount, pre_mount, post_mount feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhangui committed Sep 12, 2024
1 parent 74bb186 commit dc0cc4f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ edit = sed \
create_service: create_service.in
$(edit) $@.in > $@
chmod +x $@
client: client.in
$(edit) $@.in > $@
chmod +x $@
pistopstart: pistopstart.in
$(edit) $@.in > $@
chmod +x $@
Expand Down
48 changes: 31 additions & 17 deletions pistopserver.9
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.\" vim: tw=75
.TH pistopclient 1 "June 30, 2022" "manual"
.SH NAME
.PP
Expand All @@ -20,20 +21,29 @@ EXAMPLE.
\fBpistopserver\fR needs to be run with fd 0 and 1 connected to some TCP/IP
port. This can be done using \fBtcpserver\fR(1), \fBxinetd\fR(1). It can be
any unused port, but having a port greater than 1024 will allow
\fBpistopserver\fR to be run as non-root user. Similarly
\fBpistopserver\fR needs to use TCP/IP port connected to port 5555, with fd
6 reading from the network and fd 7 writing to the network. This can be
easily done by using tcpclient(1). \fBpistopclient\fR must be run under
root if it has to start/stop system services. It will look for a script
named \fBpistopstart\fR under $HOME/.pistop directory. If this script is
not found, it will use \fBpistopstart\fR script in @pistoplibexecdir@. The
default \fBpistopstart\fR script starts/stops autofs and mpd service on
startup/shutdown and additionally mounts NFS/samba shares.
\fBpistopstart\fR script expects either \fIstart\fR or \fIstop\fR
arguments. If you have the script/program in $HOME/.pistop it will get
updated with the latest script in @pistoplibexecdir@. To prevent your
script from getting automatically upgraded, create a file named
\fI.pistopstart.noovewrite\fR in $HOME/.pistop directory.
\fBpistopserver\fR to be run as non-root user. Similarly \fBpistopclient\fR
needs to be connected to some TCP/IP port, with fd 6 reading from the
network and fd 7 writing to the network. This can be easily done by using
\fBtcpclient\fR(1). \fBpistopclient\fR must be run under root if it has to
start/stop system services. It will look for a script named
\fBpistopstart\fR under \fI$HOME/.pistop\fR directory. If this script is
not found, it will use \fBpistopstart\fR script in
\fI@pistoplibexecdir@\fR. The default \fBpistopstart\fR script starts/stops
autofs and mpd service on startup/shutdown and additionally mounts
NFS/samba shares. \fBpistopstart\fR script expects either \fBstart\fR or
\fBstop\fR arguments. If you have the script/program in \fI$HOME/.pistop\fR
it will get updated with the latest script in \fI@pistoplibexecdir@\fR. To
prevent your script from getting automatically upgraded, create a file
named \fI.pistopstart.noovewrite\fR in \fI$HOME/.pistop\fR directory.
\fBpistopstart\fR scripts executes the following user defined scripts (if
present) during mount and unmount of NFS/samba shares

.EX
1. \fI$HOME/.pistop/pre_mount\fR - before auto-mounting a share
2. \fI$HOME/.pistop/post_mount\fR - after auto-mounting a share
3. \fI$HOME/.pistop/pre_unmount\fR - before unmounting an auto-mounted share
4. \fI$HOME/.pistop/post_unmount\fR - after unmounting an auto-mounted share
.EE

You can have \fBpistopserver\fR and \fBpistopclient\fR to be automatically
started on bootup by creating appropriate configuration in rc, systemd(1)
Expand Down Expand Up @@ -69,10 +79,14 @@ what you need to do

.EX
1. run pistopserver on the host having the mpd database under tcpserver(1)
tcpserver -vDHRo 0 5555 @pistoplibexecdir@/pistopserver
$ tcpserver -vDHRo 0 5555 /usr/libexec/pistop/pistopserver
2. run pistopclient on all clients with IP of the above tcpserver host as
\fIipaddr\fR
tcpclient -vDHR -t 300 \fIipaddr\fR 5555 @pistoplibexecdir@/pistopclient
\fIipaddr\fR. Run this with root privileges so that it can start/stop
system services
$ sudo tcpclient -vDHR -t 300 \fIipaddr\fR 5555 /usr/libexec/pistop/pistopclient
.EE

.SH SEE ALSO
Expand Down
21 changes: 20 additions & 1 deletion pistopstart.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# $Id: pistopstart.in,v 1.19 2024-07-29 08:40:41+05:30 Cprogrammer Exp mbhangui $
# $Id: pistopstart.in,v 1.20 2024-09-12 08:55:42+05:30 Cprogrammer Exp mbhangui $
#

systemctl=$(which systemctl)
Expand Down Expand Up @@ -59,6 +59,10 @@ stop()
fi
if [ -n "$MDRIVE" ] ; then
count=1
if [ -x $HOME/.pistop/pre_unmount ] ; then
echo "Executing user command pre_unmount"
$HOME/.pistop/pre_unmount
fi
while true
do
if [ -n "$POWER_OFF" -a -n "$FORCE_UMOUNT" ] ; then
Expand Down Expand Up @@ -91,6 +95,10 @@ stop()
count=`expr $count + 1`
sleep 1
done
if [ -x $HOME/.pistop/post_unmount ] ; then
echo "Executing user command post_unmount"
$HOME/.pistop/post_unmount
fi
fi
if [ -x $systemctl ] ; then
while true
Expand Down Expand Up @@ -194,6 +202,10 @@ start()
give_up
break
fi
if [ $count -eq 0 -a -x $HOME/.pistop/pre_mount ] ; then
echo "Executing user command pre_mount"
$HOME/.pistop/pre_mount
fi
count=`expr $count + 1`
autofs_was_down=1
echo "$systemctl start autofs.service"
Expand All @@ -218,6 +230,10 @@ start()
sleep 5
continue
fi
if [ $mdrive_mounted -eq 0 -a -x $HOME/.pistop/post_mount ] ; then
echo "Executing user command post_mount"
$HOME/.pistop/post_mount
fi
[ $mdrive_mounted -eq 0 ] && mdrive_mounted=1 && echo "MDrive mounted"
if [ $mpd_present -eq 1 ] ; then
start_mpd
Expand Down Expand Up @@ -299,6 +315,9 @@ esac

#
# $Log: pistopstart.in,v $
# Revision 1.20 2024-09-12 08:55:42+05:30 Cprogrammer
# added pre_unmount, post_unmount, pre_mount, post_mount feature
#
# Revision 1.19 2024-07-29 08:40:41+05:30 Cprogrammer
# get MDRIVE from /etc/auto.master.d/mpd.autofs and /etc/autofs.mounts
#
Expand Down

0 comments on commit dc0cc4f

Please sign in to comment.