To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

Running ZNC as a system daemon

From ZNC
Revision as of 16:18, 2 July 2014 by >JayAdams0x1 (Switched the init.d script to be the one from CentOS (cross platform instead of Debian specific).)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Note: if you just want to run ZNC automatically, when server is turned on, look here instead.

To have ZNC run at boot time as a system daemon we will create a user and group to run ZNC from a configuration we created and then called at each time the system boots. All the commands are expected to run as an administrator.

  • Create a new system user with accompanying group and a shell that cannot be used to login with:
sudo adduser --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
  • Make the configuration we will run at startup:
sudo -u znc /usr/bin/znc --datadir=/var/lib/znc --makeconf
  • Install an init file:
  1. create a file /etc/init.d/znc with the following content:
#!/bin/sh
#
# znc - Advanced IRC Bouncer INIT script for Fedora #
# chkconfig: 35 99 14
# description: An Advanced IRC bouncer INIT script for
# Source function library.
. /etc/rc.d/init.d/functions

exec=/usr/bin/znc
prog=znc
config=/var/lib/znc
runas=znc

lockfile=/var/lock/subsys/$prog

start() {
	[ -x $exec ] || exit 5
	echo -n $"Starting $prog: "
	# if not running, start it up here, usually something like "daemon $exec"
	daemon --user $runas "$exec -d $config >/dev/null 2>&1"
	# If you're reckless with your system, comment the line above and
	# uncomment this one below... I just don't get it why
	# daemon "$exec -r -d $config >/dev/null 2>&1"
	retval=$?
	echo
	[ $retval -eq 0 ] && touch $lockfile
	return $retval
}

stop() {
	echo -n $"Stopping $prog: "
	# stop it here, often "killproc $prog"
	killproc $prog -TERM
	retval=$?
	echo
	[ $retval -eq 0 ] && rm -f $lockfile
	return $retval
}

reload() {
	echo -n $"Reloading $prog: "
	# stop it here, often "killproc $prog"
	killproc $prog -HUP
	retval=$?
	echo
}

restart() {
	stop
	start
}

rh_status() {
	# run checks to determine if the service is running or use generic status
	status $prog
}

rh_status_q() {
	rh_status >/dev/null 2>&1
}

case "$1" in
	start)
		rh_status_q && exit 0
		$1
		;;
	stop)
		rh_status_q || exit 0
		$1
		;;
	restart)
		$1
		;;
	reload)
		rh_status_q || exit 7
		$1
		;;
	status)
		rh_status
		;;
	condrestart|try-restart)
		rh_status_q || exit 0
		restart
		;;
	*)
		echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|try-restart}"
		exit 2
esac
exit $?
  1. Give the right permissions to this file:
chmod 755 /etc/init.d/znc
  1. Execute:
update-rc.d znc defaults


Now that all the pieces are in place you can now start the service yourself or restart the computer for the daemon to take its place.

  • Start the service:
service znc start
  • Verify that the service is running:
service znc status