Files
@ 42155469350e
Branch filter:
Location: majic-scripts/templates/init.d_debian.tpl - annotation
42155469350e
5.2 KiB
application/vnd.groove-tool-template
Noticket: Added a small script for creating quick backups of files before making changes to them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 9eb26b78a711 | #!/bin/bash
### BEGIN INIT INFO
# Provides: (>>>PROVIDES<<<)
# Required-Start: (>>>REQ_START<<<)
# Required-Stop: (>>>REQ_STOP<<<)
# Default-Start: (>>>DEFAULT_START<<<)
# Default-Stop: (>>>DEFAULT_STOP<<<)
# Short-Description: (>>>SHORT_DESCRIPTION<<<)
# Description: (>>>DESCRIPTION<<<)
### END INIT INFO
# Include the LSB library functions
. /lib/lsb/init-functions
# Setup static variables
configFile='(>>>CONFIG_FILE<<<)'
daemonExec='(>>>DAEMON_EXEC<<<)'
daemonArgs='(>>>DAEMON_ARGS<<<)'
daemonName="$(basename "$daemonExec")"
pidFile='/var/run/(>>>FILE<<<).pid'
#
# Checks if the environment is capable of running the script (such as
# availability of programs etc).
#
# Return: 0 if the environmnt is properly setup for execution of init script, 1
# if not all conditions have been met.
#
function checkEnvironment() {
# Verify that the necessary binaries are available for execution.
local binaries=((>>>REQ_BINARIES<<<))
for bin in "${binaries[@]}"; do
if ! which "$bin" > /dev/null; then
log_failure_msg "Binary '$bin' is not available. Please install \
package containing it."
exit 5
fi
done
# Verify that the necessary environment variables have been set.
local envVars=((>>>REQ_ENV_VARIABLES<<<))
for var in "${envVars[@]}"; do
if printenv "$var" > /dev/null; then
log_failure_msg "Environment variable '$var' is not set. Please \
check your global environment settings."
exit 6
fi
done
}
#
# Checks if the configuration files are available and properly setup.
#
# Return: 0 if irssid if properly configured, 1 otherwise.
#
function checkConfig() {
# Make sure the configuration file has been created
if ! [[ -f $configFile ]]; then
log_failure_msg "Please populate the configuration file '$configFile' \
before running."
exit 6
fi
# Make sure the required options have been set
local reqOptions=((>>>REQ_OPTIONS<<<))
for option in "${reqOptions[@]}"; do
if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
log_failure_msg "Mandatory option '$option' was not specified in \
'$configFile'"
exit 6
fi
done
}
#
# Loads the configuration file and performs any additional configuration steps.
#
function configure() {
. "$configFile"
daemonCommand="$daemonExec $daemonArgs"
}
#
# Checks if the daemon is already running or not. If the daemon is running, its
# process id is stored within variable 'pid'.
#
# Return: 0 if the daemon is running, 1 otherwise.
#
function checkRunning() {
for pid in $(pidofproc "$daemonExec"); do
ps $pid | grep -qe "$daemonCommand" && return 0
done
return 1
}
#
# Starts the daemon.
#
# Return: LSB-compliant code.
#
function start() {
start-stop-daemon --start --quiet --oknodo --pidfile "$pidFile" \
--make-pidfile --exec "$daemonExec" -- $daemonArgs
}
#
# Stops the daemon.
#
# Return: LSB-compliant code.
#
function stop() {
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "$pidFile" \
--exec "$daemonExec" -- $daemonArgs
}
#
# Checks the status of the running daemon.
#
# Return: LSB-compliant status code.
#
function status() {
status_of_proc -p "$pidFile" "$daemonExec" "$(basename $daemonExec)"
}
#
# Starts the daemon using custom code.
#
# Return: LSB-compliant code.
#
function startCustom() {
if checkRunning; then
return 0
elif start-stop-daemon --start --quiet --pidfile $pidFile --make-pidfile \
--exec "$daemonExec" -- $daemonArgs; then
return 0
else
return 1
fi
}
#
# Stops the daemon using custom code.
#
# Return: LSB-compliant code.
#
function stopCustom() {
if checkRunning; then
# Try to stop the daemon using SIGTERM first
count=0
while checkRunning && (( $count < 5 )); do
kill $pid
let count=count+1
sleep 1
done
# If SIGTERM fails, use SIGKILL
if checkRunning; then
kill -9 $pid
rm '/var/run/(>>>FILE<<<).pid'
return 0
else
rm '/var/run/(>>>FILE<<<).pid'
return 0
fi
else
return 0
fi
}
#
# Checks the status of the running daemon.
#
# Return: LSB-compliant status code.
#
function statusCustom() {
if checkRunning; then
log_success_msg "irssid ($pid) is running"
return 0
else
log_success_msg "irssid is not running"
return 3
fi
}
checkEnvironment
checkConfig
configure
case "$1" in
start)
log_daemon_msg "Starting daemon" "(>>>FILE<<<)"
start && log_end_msg 0 || log_end_msg $?
;;
stop)
log_daemon_msg "Stopping daemon" "(>>>FILE<<<)"
stop && log_end_msg 0 || log_end_msg $?
;;
restart)
log_daemon_msg "Restarting daemon" "(>>>FILE<<<)"
stop
start && log_end_msg 0 || log_end_msg $?
;;
force-reload)
log_daemon_msg "Restarting daemon" "(>>>FILE<<<)"
stop
start && log_end_msg 0 || log_end_msg $?
;;
status)
status && exit 0 || exit $?
;;
*)
echo "(>>>FILE<<<) (start|stop|restart|force-reload|status|help)"
;;
esac
|