Skip to content

Instantly share code, notes, and snippets.

@willcharlton
Created August 20, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willcharlton/05c42b8344497d7e80c0da31aa43c980 to your computer and use it in GitHub Desktop.
Save willcharlton/05c42b8344497d7e80c0da31aa43c980 to your computer and use it in GitHub Desktop.
SysV Init Script for ExoEdge
#!/bin/bash
# SysV init script for edged
# Installation:
# 1. cp edged /etc/init.d/
# 2. chmod 755 /etc/init.d/edged
# 3. chown root:root /etc/init.d/edged
# 4. update-rc.d edged defaults 90 90
NAME="edged"
LOCK="/var/lock/$NAME"
ENABLED="yes"
run_dir=/var/run/edged
conf_dir=/var/config/edged
conf_file=$conf_dir/edged.ini
config_io_file=$conf_dir/edged.json
edged=/usr/bin/edged
edged_log=/var/log/edged.log
edged_pidfile=$run_dir/$NAME.pid
do_start() {
# create run directory
mkdir -p $run_dir/1
rm -rf $run_dir/1/*
echo -n "Starting $NAME: "
# start edged
start-stop-daemon \
--start \
--background \
--make-pidfile \
--pidfile $edged_pidfile \
--startas /bin/bash \
-- \
-c "exec $edged \
--ini-file $conf_file \
--config-io-file $config_io_file \
--local-strategy \
go \
>> $edged_log 2>&1"
sleep 2
echo "OK"
}
do_stop() {
echo -n "Stopping $NAME: "
start-stop-daemon \
--stop \
--quiet \
--oknodo \
--pidfile $edged_pidfile \
--retry TERM/60/KILL/5
echo "OK"
}
if [ "$ENABLED" != "yes" ]; then
echo "$NAME: disabled in /etc/default"
exit
fi
force_stop() {
do_stop
rm -fr $LOCK
}
function try_lock() {
if mkdir $LOCK; then
trap "rm -fr $LOCK" EXIT
else
echo "ExoEdge Daemon lock not acquired, resource in use."
exit 1
fi
}
case "$1" in
"start")
try_lock
do_start
;;
"stop")
force_stop
;;
"restart")
## Stop the service and regardless of whether it was
## running or not, start it again.
try_lock
do_stop
do_start
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment