-
-
Save kirelagin/099098c7418ddc66f3f3 to your computer and use it in GitHub Desktop.
OpenRC init-script for ncdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sbin/runscript | |
### | |
# | |
# OpenRC init-script for ncdc | |
# | |
# Distributed under the terms of the GNU General Public License, v3 or later. | |
# | |
# © 2014 Kirill Elagin <[email protected]> | |
# http://kir.elagin.me/ | |
# | |
# Based on Gentoo Linux `deluged` init script: | |
## Copyright 1999-2013 Gentoo Foundation | |
## Distributed under the terms of the GNU General Public License, v2 or later | |
## $Header: /var/cvsroot/gentoo-x86/net-p2p/deluge/files/deluged.init,v 1.11 2013/04/01 08:30:44 heroxbd Exp $ | |
# Based on tmux-magic: | |
## https://gist.github.com/kirelagin/d4e13b027a384cb6ab65 | |
# | |
### | |
PIDFILE="/var/run/${RC_SVCNAME}/${RC_SVCNAME}.pid" | |
depend() { | |
need net | |
} | |
checkconfig() { | |
if [ "${NCDC_USER}" = "" ] ; then | |
eerror "Please edit /etc/conf.d/ncdc" | |
eerror "You have to specify a user to run ncdc as, as we will not run it as root!" | |
eerror "Modify NCDC_USER to your needs" | |
return 1 | |
fi | |
if ! getent passwd "${NCDC_USER}" >/dev/null ; then | |
eerror "Please edit /etc/conf.d/ncdc" | |
eerror "Your user has to exist!" | |
return 1 | |
fi | |
checkpath -d -o "${NCDC_USER}":root ${PIDFILE%/*} | |
} | |
start() { | |
checkconfig || return $? | |
ebegin "Starting ncdc" | |
tmux_magic_start | |
eend $? | |
} | |
stop() { | |
ebegin "Stopping ncdc" | |
tmux_magic_stop | |
eend $? | |
} | |
TMAGIC_USER="${NCDC_USER}" | |
TMAGIC_CMD="ncdc" | |
TMAGIC_PIDFILE="${PIDFILE}" | |
extra_started_commands="attach" | |
description_attach="Show the console" | |
tmux_magic_start() { | |
start-stop-daemon --start --user "${TMAGIC_USER}" \ | |
--pidfile "${TMAGIC_PIDFILE}" \ | |
--exec tmux -- -L _rc new-session -s "${RC_SVCNAME}" -d "echo \$\$ > \"${TMAGIC_PIDFILE}\" && exec ${TMAGIC_CMD}" | |
} | |
tmux_magic_stop() { | |
start-stop-daemon --stop --user "${TMAGIC_USER}" \ | |
--pidfile "${TMAGIC_PIDFILE}" | |
} | |
attach() { | |
sudo -u "${TMAGIC_USER}" tmux -L _rc attach-session -t "${RC_SVCNAME}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment