Skip to content

Instantly share code, notes, and snippets.

@abythell
Last active October 19, 2016 18:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abythell/5399914 to your computer and use it in GitHub Desktop.
Save abythell/5399914 to your computer and use it in GitHub Desktop.
Debian/Ubuntu LSB init script for udisks-glue (automount removable media). To use/install, make the script executable, copy to /etc/init.d/udisks-glue, then run "update-rc.d udisks-glue defaults"
#!/bin/bash
### BEGIN INIT INFO
# Provides: udisks-glue
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: udisks-glue automounter
# Description: Automounts removable media
### END INIT INFO
. /lib/lsb/init-functions
NAME=udisks-glue
PIDFILE=/var/run/udisks.pid
DAEMON="/usr/bin/udisks-glue"
DAEMON_OPTS="-c /etc/udisks-glue.conf"
case "$1" in
start)
log_daemon_msg "Starting Automounter" "$NAME"
start-stop-daemon --start --exec $DAEMON -- $DAEMON_OPTS -p $PIDFILE
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping Automounter" "$NAME"
start-stop-daemon --stop --exec $DAEMON
log_end_msg $?
rm -f $PIDFILE
;;
restart | force-reload)
$0 stop && sleep 2 && $0 start
;;
try-restart)
if $0 status >/dev/null; then
$0 restart
else
exit 0
fi
;;
reload)
exit 3
;;
status)
status_of_proc $DAEMON "udisks-glue"
;;
*)
echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 2
;;
esac
@abythell
Copy link
Author

When instructed, udisks-glue creates a PID file, but it is really more of a lock file, as it does not contain the actual process ID. This is why the start-stop-daemon uses 'exec' instead of 'startas' and 'pidfile'. udisks-glue is still passed the -p argument as the existence of a pidfile will prevent multiple instances.

@dennmtr
Copy link

dennmtr commented Jan 16, 2016

u re the best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment