-
Notifications
You must be signed in to change notification settings - Fork 108
Daemon Scripts
looter edited this page Jul 6, 2016
·
8 revisions
Some parameters may require your attention, such as path and executable name.
Create /etc/systemd/services/grimd.service
and paste in the following.
[Unit]
Description=grimd dns proxy
Documentation=https://github.com/looterz/grimd
After=network.target
[Service]
User=root
WorkingDirectory=/root/grim
LimitNOFILE=4096
PIDFile=/var/run/grimd/grimd.pid
ExecStart=/root/grim/grimd_linux_x64 -update
Restart=always
StartLimitInterval=30
[Install]
WantedBy=multi-user.target
Create /etc/init.d/grimd
and paste in the following.
#!/bin/bash
# grimd daemon
# chkconfig: 345 20 80
# description: grimd daemon
# processname: grimd
DAEMON_PATH="/root/grim"
DAEMON=grimd
DAEMONOPTS="-update"
NAME=grimd
DESC="https://github.com/looterz/grimd"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
cd $DAEMON_PATH
PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
#echo "Saving PID" $PID " to " $PIDFILE
if [ -z $PID ]; then
printf "%s\n" "Fail"
else
echo $PID > $PIDFILE
printf "%s\n" "Ok"
fi
;;
status)
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
printf "%s\n" "Process dead but pidfile exists"
else
echo "Running"
fi
else
printf "%s\n" "Service not running"
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
PID=`cat $PIDFILE`
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -HUP $PID
printf "%s\n" "Ok"
rm -f $PIDFILE
else
printf "%s\n" "pidfile not found"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
Create /etc/rc.d/grimd
and paste in the following.
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: grimd
# REQUIRE: NETWORKING SYSLOG
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable grimd:
#
#grimd_enable="YES"
. /etc/rc.subr
name="grimd"
rcvar="grimd_enable"
load_rc_config $name
: ${grimd_user:="root"}
: ${grimd_enable:="NO"}
: ${grimd_directory:="/root/grim"}
command="${grimd_directory}/grimd -update"
pidfile="${grimd_directory}/${name}.pid"
start_cmd="export USER=${grimd_user}; export HOME=${grimd_directory}; /usr/sbin/daemon -f -u ${grimd_user} -p ${pidfile} $command"
#stop_cmd="kill $(cat $pidfile)"
stop_cmd="${name}_stop"
grimd_stop() {
if [ ! -f $pidfile ]; then
echo "grimd PID File not found. Maybe grimd is not running?"
else
kill $(cat $pidfile)
fi
}
run_rc_command "$1"
or
#
# OpenBSD
#
daemon="<path_to_daemon>"
. /etc/rc.d/rc.subr
rc_bg=YES
rc_reload=NO
rc_cmd $1