Last active
June 27, 2018 22:08
-
-
Save henri/60a598a4bb96c67a3b8160d6107ad95d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2018 Henri Shustak - [email protected] | |
# Licence MIT : https://opensource.org/licenses/MIT | |
# This script is tested and works on macOS 10.12.6 - It is used to keep the PaperCut | |
# MobilityPrint service running and to regularly restart the MobilityPrint daemon. | |
function restart_pc_mobility_print_daemon { | |
result=`launchctl unload -w /Library/LaunchDaemons/pc-mobility-print.plist 2>&1` | |
if ! [ $? == 0 ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint daemon failed to stop." | |
exit -1 | |
fi | |
if [ "${result}" == "/Library/LaunchDaemons/pc-mobility-print.plist: Could not find specified service" ] ; then | |
echo "`date` : ----- Mobility Print Daemon Was Not Running" >> /tmp/mobilityprint-reboot.log | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint daemon was not running." | |
fi | |
# If it is not running we still want to start the Daemon | |
sleep 10 | |
result=`launchctl load -w /Library/LaunchDaemons/pc-mobility-print.plist 2>&1` | |
if ! [ $? == 0 ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint daemon failed to start." | |
echo "`date` : ----- MobilityPrint daemon failed to start." >> /tmp/mobilityprint-reboot.log | |
exit -1 | |
fi | |
if ! [ "${result}" == "" ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint daemon error while restarting ." | |
echo "`date` : ----- MobilityPrint daemon failed to start." >> /tmp/mobilityprint-reboot.log | |
exit -1 | |
fi | |
echo "`date` : Restarted Mobility Print Daemon" >> /tmp/mobilityprint-reboot.log | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint daemon successfully restarted." | |
} | |
function restart_event_monitor_daemon { | |
result=`launchctl unload -w /Library/LaunchDaemons/papercut-event-monitor.plist 2>&1` | |
if ! [ $? == 0 ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint Event Monitor daemon failed to stop." | |
exit -1 | |
fi | |
if [ "${result}" == "/Library/LaunchDaemons/papercut-event-monitor.plist: Could not find specified service" ] ; then | |
echo "`date` : ----- Mobility Print Event Monitor Daemon Was Not Running" >> /tmp/mobilityprint-reboot.log | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint Event Monitor daemon was not running." | |
fi | |
# If it is not running we still want to start the Daemon | |
sleep 10 | |
result=`launchctl load -w /Library/LaunchDaemons/papercut-event-monitor.plist 2>&1` | |
if ! [ $? == 0 ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint Event Monitor daemon failed to start." | |
echo "`date` : ----- MobilityPrint Event Monitor daemon failed to start." >> /tmp/mobilityprint-reboot.log | |
exit -1 | |
fi | |
if ! [ "${result}" == "" ] ; then | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint Event Monitor daemon error while restarting ." | |
echo "`date` : ----- MobilityPrint Event Monitor daemon failed to start." >> /tmp/mobilityprint-reboot.log | |
exit -1 | |
fi | |
echo "`date` : Restarted Mobility Print Event Monitor Daemon" >> /tmp/mobilityprint-reboot.log | |
logger -p "notice" -t "MobilityPrint-Reboot" "MobilityPrint Event Monitor daemon successfully restarted." | |
} | |
restart_pc_mobility_print_daemon | |
restart_event_monitor_daemon | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment