Articles

Friday, April 5, 2013

Run ZNC IRC Bouncer as a Service

Below is a simple init script that will run your ZNC server as a service. Create a new file in /etc/init.d/ called znc and paste the following code in it. 


#!/bin/bash
### BEGIN INIT INFO
# Provides:          znc
# Required-Start:    $local_fs $syslog $network
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start ZNC at boot time
# Description:       Enable ZNC provided by /etc/init.d/znc.
### END INIT INFO

PID=`pidof znc`

case "$1" in
    start)
        if [[ $PID != "" ]]; then
            echo "ZNC is already running"
            exit 1
         else
            echo "Starting ZNC"
            sudo -u ubuntu znc > /dev/null 2>&1
        fi
        ;;
    stop)
        if [[ $PID != "" ]]; then
            echo "Stopping ZNC"
            kill -9 $PID > /dev/null 2>&1
        else
            echo "ZNC is not running"
            exit 1
        fi
        ;;
    restart|reload)
        if [[ $PID != '' ]]; then
            echo "Stopping ZNC"
            kill -9 $PID > /dev/null 2>&1
            echo "Starting ZNC"
            sudo -u ubuntu znc > /dev/null 2>&1
        else
            echo "ZNC is not running"
            exit 1
        fi
        ;;
    status)
        if [[ $PID != "" ]]; then
            echo "ZNC is running"
        else
            echo "ZNC is not running"
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|status}"
        exit 2
        ;;
esac



After you've created the file you need to make it executable:

chmod +x /etc/init.d/znc

Then to add it to your runlevels run:

sudo update-rc.d znc defaults

Edit:

Apparently I should have read the docs. In the ZNC wiki are instructions for doing this. Ah well...

http://wiki.znc.in/Running_ZNC_as_a_system_daemon

1 comment:

  1. Safehands Security Services is one stop shop for providing all kinds of security services in and around Adelaide, Australia. Our security guards are well experienced in providing Private Party Securities. Our security officers can watch the gate, escort the guests and celebrities, help in parking vehicles, secure the periphery, monitor electronic security systems, keep the gatecrashers at the bay, protect your assets, and also they even help you with your party arrangements without much ado. Your peace of mind is just a call away.


    Hire Security Guards | Security Guards Companies | Security Guards Services | Security Services Australia | Security Companies Australia | Event Security Services | Private Party Security | K9 Security Services | Mobile Patorls & Alarm Response Service | Crowd Control Services | Security Guards Agencies | Security Companies | Security Services | Security Agencies | Security Guards Services

    ReplyDelete