├── .gitignore ├── AUTHORS ├── BUGS.md ├── COPYING ├── ChangeLog ├── ChangeLog-v0.12 ├── ChangeLog-v00 ├── Makefile ├── README.local ├── README.md ├── TODO ├── configure ├── crypttab ├── dmtab ├── lib ├── bin │ ├── envdir │ ├── envuidgid │ ├── fghack │ ├── pgrphack │ ├── setlock │ ├── setuidgid │ └── softlimit └── sh │ ├── SV-CONFIG │ ├── SV-OPTIONS.in │ ├── cgroup-functions │ ├── cgroup-release-agent │ ├── functions │ ├── run │ ├── runscript-functions │ ├── supervision-functions │ ├── sv-deps.sh │ ├── sv-init.sh │ ├── sv-run.sh │ └── tmpfiles ├── runit ├── 1 ├── 2 ├── 3 ├── ctrlaltdel └── reboot ├── s6 ├── crash ├── finish └── init ├── src ├── Makefile ├── checkpath.c ├── error.c ├── error.h ├── fstabinfo.c ├── helper.c ├── helper.h ├── initctl.c ├── mountinfo.c ├── queue.h ├── supervision.1 ├── supervision.5 ├── supervision.c ├── supervision.h ├── sv-conf.c ├── sv-conf.h ├── sv-config.c ├── sv-copyright.h ├── sv-deps.c ├── sv-deps.h ├── sv-init.8 ├── sv-init.c ├── sv-list.c ├── sv-list.h ├── sv-rc.8 ├── sv-rc.c ├── sv-rcorder.8 ├── sv-run.8 ├── sv-run.c ├── sv-shutdown.8 ├── sv-shutdown.c ├── sv.h ├── svd.1 ├── svd.c ├── svd.h ├── svp.1 ├── svp.c ├── svr.1 ├── svr.c ├── timespec.c ├── timespec.h └── waitfile.c ├── sv.conf ├── sv.conf.d ├── alsasound ├── checkfs ├── console ├── device-mapper ├── dmcrypt ├── dmesg ├── hostname ├── hwclock ├── ip6tables ├── ipset ├── iptables ├── kmod ├── libvirt-guests ├── lvm ├── miscfs ├── qemu-vlan.vnet0 ├── raid ├── tmpdirs ├── unionfs ├── zfs ├── zfs-share ├── zpool └── zramfs ├── sv.conf.local.d └── qemu-vlan.vnet4 ├── sv.init ├── sv.shutdown ├── sv.vim ├── sv ├── DEFAULT ├── SYSBOOT ├── acpid │ ├── OPTIONS │ ├── finish │ └── run ├── alsasound ├── apache2 │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── atd │ ├── OPTIONS │ ├── finish │ └── run ├── cgred │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── checkfs ├── console ├── cron │ ├── OPTIONS │ ├── OPTIONS.cronie │ ├── OPTIONS.dcron │ ├── OPTIONS.fcron │ ├── OPTIONS.vixie-cron │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── cups-browsed │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── cupsd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── dbus │ ├── OPTIONS │ ├── finish │ └── run ├── devfs ├── device-mapper ├── dhcp │ ├── OPTIONS │ ├── OPTIONS.dhclient │ ├── OPTIONS.dhcpcd │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── dhcpd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── dhcrelay │ ├── OPTIONS │ ├── finish │ └── run ├── dmcrypt ├── dmesg ├── dmeventd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── dmraid ├── dns │ ├── OPTIONS │ ├── OPTIONS.dnsmasq │ ├── finish │ └── run ├── docker │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── getty.tty1 │ ├── OPTIONS │ ├── finish │ └── run ├── git-daemon │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── gpm │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── hostapd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── hostname ├── httpd │ ├── OPTIONS │ ├── OPTIONS.busybox-httpd │ ├── OPTIONS.lighttpd │ ├── finish │ └── run ├── hwclock ├── inetd │ ├── OPTIONS │ ├── OPTIONS.ipsvd │ ├── OPTIONS.xinetd │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── initctl │ ├── OPTIONS │ ├── finish │ └── run ├── ipset ├── iptables ├── kmod ├── kmod-static-nodes ├── libvirt-guests ├── libvirtd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── local ├── localfs ├── loop-back-device ├── lvm ├── lvm-monitor ├── lvmetad │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── mdadm ├── mdev ├── miscfs ├── mtab ├── mysql │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── nagios │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── networkfs ├── nginx ├── npcd │ ├── OPTIONS │ ├── finish │ └── run ├── nrpe ├── ntp │ ├── OPTIONS │ ├── OPTIONS.busybox-ntpd │ ├── OPTIONS.ntpd │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── pcscd │ ├── OPTIONS │ ├── finish │ └── run ├── php-fpm │ ├── OPTIONS │ ├── OPTIONS.php-fpm5.6 │ ├── finish │ └── run ├── postgresql │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── procfs ├── qemu-binfmt ├── qemu-vlan.vnet0 ├── qemu-vlan.vnet4 ├── rdonlyfs ├── rootfs ├── rrdcached.nagios ├── rrdcached │ ├── OPTIONS │ ├── OPTIONS.nagios │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── rsync-daemon │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── saned │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── snmpd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── snmptrapd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── socklog-inet ├── socklog-ucspi ├── socklog-unix ├── spawn-fcgi.lighttpd ├── spawn-fcgi.nginx │ ├── OPTIONS │ ├── OPTIONS.lighttpd │ ├── OPTIONS.nginx │ ├── finish │ └── run ├── sshd │ ├── OPTIONS │ ├── finish │ └── run ├── sulogin │ ├── OPTIONS │ ├── finish │ └── run ├── swaps ├── sysctl ├── sysfs ├── syslog │ ├── OPTIONS │ ├── OPTIONS.rsyslog │ ├── OPTIONS.socklog │ ├── OPTIONS.syslog-ng │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── tmpdirs ├── tmpfiles.dev ├── tmpfiles.setup ├── udev-monitor │ ├── OPTIONS │ ├── finish │ └── run ├── udev │ ├── OPTIONS │ ├── finish │ └── run ├── unionfs ├── urandom ├── virtlockd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── virtlogd │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── vmware ├── wpa_supplicant │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── xdm │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── zed │ ├── OPTIONS │ ├── finish │ ├── log │ │ ├── finish │ │ └── run │ └── run ├── zfs ├── zfs-share ├── zpool └── zramfs └── t ├── README.md ├── t0000-functions.sh ├── t0000-service.sh ├── t0000-shutdown.sh └── t0000-utils.sh /.gitignore: -------------------------------------------------------------------------------- 1 | config.log 2 | src/config.h 3 | src/file-test.c 4 | src/*.o 5 | src/sv-run 6 | src/checkpath 7 | src/fstabinfo 8 | src/mountinfo 9 | src/initctl 10 | src/sv-shutdown 11 | src/sv-stage 12 | sv/net/* 13 | sv/socklog*/* 14 | sv/*/supervise 15 | sv/*/log/supervise 16 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2017 Toufeyl "tokiclover" Ali 2 | 3 | Many runscript services (sv/SERVICES) for sys{init,boot} are adapted from 4 | OpenRC-0.13.11; and are thus copyrighted as the following: 5 | Copyright (c) 2007-2008 Roy Marples 6 | 7 | -------------------------------------------------------------------------------- /BUGS.md: -------------------------------------------------------------------------------- 1 | udev: 2 | ---- 3 | 4 | udev seems to require a resynchronization before starting an X session; 5 | otherwise, no input would be available! Well, it could happen... 6 | 7 | [ -d ${SV_RUNDIR}/udev ] || dmsetup_opts="${dmsetup_opts} --noudevsync" 8 | [ -d ${SV_RUNDIR}/udev ] || lvm_opts="--noudevsync" 9 | 10 | There is a workaround for this... just wait *udev* to be ready. 11 | 12 | **IMPORTANT NOTE:** udev need a system logger to be able to start processing 13 | device events. Otherwise, it will simply refuse to do anything. 14 | Secondly, kernel modules should loaded after udev initialisation; or else, udev 15 | would silently ignore old devices events. 16 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | @COPYLEFT 2 | ALL WRONGS RESERVED 3 | 4 | --- 5 | 6 | Copyright 2014-2019 Toufeyl "tokiclover" Ali 7 | 8 | Redistribution and use in source and binary forms, with or without modification, are 9 | permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this list of 12 | conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | of conditions and the following disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY TOKICLOVER ''AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOKICLOVER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | The views and conclusions contained in the software and documentation are those of the 29 | authors and should not be interpreted as representing official policies, either expressed 30 | or implied, of tokiclover. 31 | 32 | --- 33 | -------------------------------------------------------------------------------- /README.local: -------------------------------------------------------------------------------- 1 | The following key points apply to old-style or simplified scripts in 2 | /usr/local/etc/sv.local.d/: 3 | 4 | ++ Scripts are only executed if they are executable. Any other files or 5 | directories present within the directory are silently ignored. 6 | 7 | ++ When a script is executed at boot time, it is passed the string 8 | `start' as its first and only argument. At shutdown time, it is 9 | passed the string `stop' as its first and only argument. All `sv/' 10 | scripts are expected to handle these arguments appropriately. If no 11 | action needs to be taken at a given time (either boot time or shut- 12 | down time), the script should exit successfully and without producing 13 | an error message. 14 | 15 | ++ The scripts within each directory are executed in lexicographical 16 | order. If a specific order is required, numbers may be used as a 17 | prefix to the existing filenames, so for example 100.foo would be 18 | executed before 200.bar; without the numeric prefixes the opposite 19 | would be true. 20 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * [x] improve performance by removing redundancy (service dependencies); 2 | * [x] improve logging and debugging; 3 | * [ ] more testing and compatiblity code for FreeBSD, OpenBSD, NetBSB; 4 | * [+] improve RC compatibility: installability runscript services to /etc/init.d 5 | (easy to do), and adapt rs semantics to rc (LEVEL/ACTION... quite easy); 6 | [x] (partly) done with runlevels command support (`sv-stage RUNLEVEL'); 7 | * [x] optimize parallel start/stop by using threads/pthread.h (*not easy*); 8 | * [x] improve sv-shutdown compatibilty to SystemV or BSD shutdown/halt utilities; 9 | * [x] set up niceness to daemons; 10 | * [x] add debugging code to runscript (added `SVC_DEBUG' shell function); 11 | * [x] add support to `/etc/sv.conf.local.d' configuration for any service type; 12 | * [x] migrate ./{run,finish} to new `/lib/sv/sh/run' location; 13 | * [x] migrate old (v2) init stage directory from `/etc/sv/.RUNLEVEL' 14 | to `/etc/sv.init.d/RUNLEVEL'; 15 | * [x] log message to syslog(3) (add a new `SV_SYSLOG' and `SV_SYSLOG_INFO' for 16 | info level message); 17 | * [x] add PID to lock file along with the service command; 18 | * [x] check service lock file before waiting for the lock file; 19 | * [x] check service pidfile for validity before marking a service as started; 20 | * [ ] add the full environment of service to be able to process commands once 21 | the service is started and removed from service directory; 22 | -------------------------------------------------------------------------------- /dmtab: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/dmtab,v 2016/06/06 Exp $ 3 | # 4 | # Configuration file for device-mapper volumes 5 | # 6 | # Format: : 7 | # Example (fake ATA RAID): isw0: 0 312602976 striped 2 128 /dev/sda 0 /dev/sdb 0 8 | # Example (LVM2): home: 0 134217728 linear 254:0 134219776 9 | # 10 | # Alternatively create all your volumes first, and then generate the file: 11 | # 12 | # dmsetup table >> /etc/dmtab 13 | # 14 | # and verify afterwards. 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/bin/envdir: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/envuidgid: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/fghack: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/pgrphack: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/setlock: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/setuidgid: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/bin/softlimit: -------------------------------------------------------------------------------- 1 | /bin/chpst -------------------------------------------------------------------------------- /lib/sh/SV-CONFIG: -------------------------------------------------------------------------------- 1 | __SV_NAM__='runit' 2 | __SVCENV__='SVDIR=\${SV_RUNDIR}' 3 | __SV_CMD__='/bin/runsvdir' 4 | __SVCCMD__='/bin/sv' 5 | __CHKCMD__='/bin/sv check' 6 | __STACMD__='/bin/sv' 7 | __LOGCMD__='/bin/svlogd' 8 | __PRECMD__='/bin/chpst' 9 | __SCANCMD__='pkill -CONT -F ${SV_TMPDIR}/runsvdir.pid' 10 | __SIGSTRT__='up' 11 | __SIGSTOP__='down' 12 | __SIGSONCE__='once' 13 | __SIGPAUSE__='pause' 14 | __SIGCONT__='cont' 15 | __SIGHUP__='hup' 16 | __SIGALRM__='alarm' 17 | __SIGINT__='interrupt' 18 | __SIGTERM__='term' 19 | __SIGKILL__='kill' 20 | __SIGEXIT__='exit' 21 | __SIGQUIT__='quit' 22 | __SIGUSR1__='1' 23 | __SIGUSR2__='2' 24 | __SIGWTUP__='-w ${SVC_TIMEOUT_UP:-${SV_TIMEOUT_UP:-10}} up' 25 | __SIGWDWN__='-w ${SVC_TIMEOUT_DOWN:-${SV_TIMMEOUT_DOWN:-30}} down' 26 | __SIGRELD__='reload' 27 | -------------------------------------------------------------------------------- /lib/sh/SV-OPTIONS.in: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/@svc@/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | #SVC_CONFIGFILE=/etc/@svc@.conf 7 | #SVC_REQIRED_FILES="/etc/FILE1.conf /etc/FILE2.conf" 8 | #SVC_COMMANDS=configtest 9 | #SVC_STARTED_COMMAND=reload 10 | #SVC_CMD=/path/to/binary 11 | #SVC_OPTS="-f -c ${SVC_CONFIGFILE}" 12 | #SVC_AFTER=logger 13 | #SVC_USE=logger 14 | #SVC_NEED=net 15 | #SVC_BEFORE=httpd 16 | #SVC_KEYWORD="timeout" 17 | #SVC_NOHANG="NO" 18 | #SVC_TIMEOUT="60" 19 | 20 | #ENV_DIR=Enable 21 | #PRE_CMD= 22 | #PRE_OPTS= 23 | #FIN_CMD= 24 | #FIN_OPTS= 25 | 26 | # 27 | # Run set up 28 | # 29 | #start_pre() 30 | #{ 31 | # checkpath -qd -o nobody:nobody -m 775 /var/run/fcgi 32 | #} 33 | 34 | # 35 | # Run clean up 36 | # 37 | #start_post() 38 | #{ 39 | # svc_wait "${SVC_TIMEOUT:60}" /run/daemon.pid 40 | #} 41 | 42 | # 43 | # Finish set up 44 | # 45 | #stop_pre() 46 | #{ 47 | #} 48 | 49 | # 50 | # Finish clean up 51 | # 52 | #stop_post() 53 | #{ 54 | #} 55 | 56 | #configtest() 57 | #{ 58 | # 59 | # Check SVC_CONFIG and SVC_REQUIRED_FILES 60 | # svc_config 61 | # 62 | # eval ${SVC_CMD} -t -f "${SVC_CONFIGFILE}" 63 | #} 64 | 65 | # 66 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 67 | # 68 | -------------------------------------------------------------------------------- /lib/sh/cgroup-release-agent: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) cgroup-agent 0.0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 8 | group="/sys/fs/cgroup/supervision/${1}" 9 | if [ -d "${group}" ]; then 10 | rmdir "${group}" >/dev/null 2>&1 11 | fi 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /lib/sh/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) run 0.4 2018/08/18 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD Exp $ 5 | # 6 | 7 | # 8 | # ZSH compatibility 9 | # 10 | if [ -n "${ZSH_VERSION}" ]; then 11 | emulate sh 12 | NULLCMD=: 13 | setopt SH_WORD_SPLIT 14 | disable -r end 15 | fi 16 | 17 | exec 2>&1 18 | 19 | case "${0}" in 20 | (/*) __av0__="${0%/*}" ;; 21 | (*) __av0__="${PWD}/${0#./}" 22 | __av0__="${__av0__%/*}";; 23 | esac 24 | readonly SVC_DIR="${__av0__%/log}" 25 | readonly SVC_NAME="${SVC_DIR##*/}" 26 | case "${SVC_DIR}" in 27 | (*/etc/*) 28 | : ${SV_SVCDIR=${SVC_DIR%/*}} 29 | ;; 30 | (*/run/*|*/tmp/*) 31 | : ${SV_RUNDIR=${SVC_DIR%/*}} 32 | ;; 33 | esac 34 | 35 | case "${__av0__}" in 36 | (*/log) __cmd_dir__=log;; 37 | (*) __cmd_dir__="" ;; 38 | esac 39 | readonly __cmd__="${0##*/}" 40 | readonly __svc__="${__av0__%/$__cmd_dir__}" 41 | readonly SV_TYPE=sv 42 | SV_LIBDIR=${SVC_DIR}/../../lib 43 | 44 | if ! . ${SV_LIBDIR}/sh/runscript-functions; then 45 | echo "${__cmd__}: error: Required file not found \`${SV_LIBDIR}/sh/runscript-functions'" >&2 46 | exit 1 47 | fi 48 | : ${SVC_CMD:=${SVC_NAME}} 49 | 50 | if [ "${__cmd__}" = "run" -o "${__cmd__}" = "finish" ]; then 51 | yesno "${__environ__}" || DOT ${SV_TMPDIR}/envs/${SVC_NAME} 52 | # 53 | # Use ENV dir(s) if requested 54 | # 55 | yesno "${ENV_DIR}" && svc_environ 56 | 57 | # 58 | # Set default getty options 59 | # 60 | case "${SVC_NAME}" in # SVC_NAME=$GETTY_TTY 61 | (*getty-tty*) 62 | : ${PRE_CMD:=${__PRECMD__}} 63 | if [ "${__SV_NAM__}" = "runit" ]; then 64 | : ${PRE_OPTS:=-P} 65 | : ${FIN_CMD:=utmpset} 66 | : ${FIN_OPTS:=-w ${SVC_NAME#*-}} 67 | fi 68 | ;; 69 | esac # SVC_NAME=$GETTY_TTY 70 | fi # __cmd__=run 71 | 72 | # 73 | # Set a few specific log env variables 74 | # 75 | if [ "${__cmd_dir__}" = "log" ]; then 76 | : ${SVC_LOGDIR:=${LOGDIR}/${SVC_NAME}} 77 | : ${SVC_USER:=root} 78 | : ${SVC_GROUP:=root} 79 | : ${LOG_MODE:=0755} 80 | : ${LOG_PROC:=gzip -nq} 81 | : ${LOG_SIZE:=2048000} 82 | : ${LOG_STAT:=} 83 | : ${LOG_PREFIX:=${SVC_NAME}} 84 | : ${LOG_CMD:=${__LOGCMD__}} 85 | # 86 | # Set default log options 87 | # 88 | if [ "${__SV_NAM__}" = "runit" ]; then 89 | : ${LOG_ARGS:="p${LOG_PREFIX}\ns${LOG_SIZE}\n!'${LOG_PROC}'"} 90 | : ${LOG_OPTS:=-tt ${SVC_LOGDIR}} 91 | else 92 | : ${LOG_ARGS:="s${LOG_SIZE} !'${LOG_PROC}'"} 93 | : ${LOG_OPTS:="T ${LOG_STAT:++^${LOG_STAT} =${SVC_LOGDIR}/status} ${LOG_ARGS}"} 94 | fi # __SV_NAM__ 95 | unset LOG_PROC LOG_PREFIX LOG_STAT LOG_SIZE 96 | fi # __cmd_dir__=log 97 | 98 | 99 | # 100 | # Handle [log/]{finish,run} & exec to the command 101 | # 102 | eval svc${__cmd_dir__:+_${__cmd_dir__}}_${__cmd__} "${@}" 103 | 104 | # 105 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 106 | # 107 | -------------------------------------------------------------------------------- /lib/sh/sv-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) sv-deps.sh 2.0 2018/08/07 21:09:26 Exp $ 4 | # $C$: Copyright (c) 2015-2017 tokiclover Exp $ 5 | # $L$: 2-clause/new/simplified BSD License Exp $ 6 | # 7 | 8 | # 9 | # ZSH compatibility 10 | # 11 | if [ -n "${ZSH_VERSION}" ]; then 12 | emulate sh 13 | NULLCMD=: 14 | setopt NULLGLOB SH_WORD_SPLIT 15 | disable -r end 16 | elif [ -n "${BASH_VERSION}" ]; then 17 | shopt -qs nullglob 18 | fi 19 | 20 | SV_CGROUP=0 21 | name="${0##*/}" 22 | SV_LIBDIR="${0%/sh/*}" 23 | export LC_ALL=C LANG=C 24 | if ! . ${SV_LIBDIR}/sh/runscript-functions; then 25 | echo "${name}: error: Required file not found \`${SV_LIBDIR}/sh/runscript-functions'" >&2 26 | exit 1 27 | fi 28 | SV_DEPDIR="${SV_TMPDIR}/deps" 29 | 30 | __svc_deps__() 31 | { 32 | local RC_OPTS SVC_DEBUG SVC_NAME SVC_NEED SVC_USE SVC_BEFORE SVC_AFTER name 33 | local SVC_KEYWORD SVC_PROVIDE SVC_TIMEOUT __SVC_PIDFILE__ SV_SERVICE RC_SERVICE 34 | local dep SVC_INSTANCE SVC_PROVIDER 35 | 36 | if [ -d "${__svc__}" ]; then 37 | SV_TYPE=sv 38 | elif [ -f "${__svc__}" ]; then 39 | SV_TYPE=rs 40 | else 41 | return 42 | fi 43 | SVC_NAME="${__svc__##*/}" 44 | if isin ${SVC_NAME} ${SVCLIST}; then 45 | ${append} || return 0 46 | else 47 | SVCLIST="${SVCLIST} ${SVC_NAME}" 48 | fi 49 | . ${SV_LIBDIR}/sh/runscript-functions || 50 | { echo "Required file not found." >&2; exit 1; } 51 | 52 | [ -n "${SVC_KEYWORD}" ] && echo "${SVC_NAME}:keyword=\"${SVC_KEYWORD}\"" >&4 53 | [ -n "${SVC_PROVIDE}" ] && echo "${SVC_NAME}:provide=\"${SVC_PROVIDE}\"" >&4 54 | [ -n "${SVC_TIMEOUT}" ] && echo "${SVC_NAME}:timeout=\"${SVC_TIMEOUT}\"" >&4 55 | for dep in ${__SV_DEPS_ORDER__}; do 56 | eval echo "\"${SVC_NAME}:${dep%:*}=\\\"\$SVC_${dep#*:}\\\"\"" >&4 57 | done 58 | } 59 | 60 | SVCDEPS_UPDATE=${SVCDEPS_UPDATE:+true} 61 | : ${SVCDEPS_UPDATE:=false} 62 | SVCLIST= 63 | svcdeps=${SV_DEPDIR}/svcdeps 64 | svclist=${SV_DEPDIR}/svclist 65 | 66 | append=false 67 | if [ "${#}" = 0 ]; then 68 | exec 4>${svcdeps} 69 | for dir in ${SV_SVCDIR} ${SV_SVCDIR_LOCAL}; do 70 | for __svc__ in ${dir}/*; do 71 | __svc_deps__ 72 | done 73 | done 74 | printf "${SVCLIST## }" >${svclist} 75 | else 76 | exec 4>${SV_DEPDIR}/tmp 77 | printf "" >>${svclist} 78 | read SVCLIST <${svclist} 79 | TMPLIST= one=true 80 | for SVC_NAME; do 81 | if ${SVCDEPS_UPDATE} && isin "${SVC_NAME}" ${SVCLIST}; then 82 | sed "/^${SVC_NAME}:/d" -i ${svcdeps} 83 | append=true 84 | else 85 | append=false 86 | fi 87 | for dir in ${SV_SVCDIR} ${SV_SVCDIR_LOCAL}; do 88 | __svc__=${dir}/${SVC_NAME} 89 | if __svc_deps__; then 90 | ${append} || TMPLIST="${TMPLIST} ${SVC_NAME}" 91 | break 92 | fi 93 | done 94 | done 95 | cat ${SV_DEPDIR}/tmp >>${svcdeps} 96 | rm -f ${SV_DEPDIR}/tmp 97 | printf "${TMPLIST}" >>${svclist} 98 | fi 99 | exec 4>&- 100 | 101 | # 102 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 103 | # 104 | -------------------------------------------------------------------------------- /lib/sh/sv-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) sv-run.sh 0.8 2018/07/22 21:09:26 Exp $ 4 | # $C$: Copyright (c) 2015-2018 tokiclover Exp $ 5 | # $L$: 2-clause/new/simplified BSD License Exp $ 6 | # 7 | 8 | readonly __arg__="$*" 9 | # 10 | # ZSH compatibility 11 | # 12 | if [ -n "${ZSH_VERSION}" ]; then 13 | emulate sh 14 | NULLCMD=: 15 | setopt NO_GLOB_SUBST SH_WORD_SPLIT 16 | disable -r end 17 | fi 18 | 19 | help_message() { 20 | cat <<-EOH 21 | usage: ${0##*/} [OPTIONS] SERVICE COMMAND [ARGUMENTS] 22 | COMMAND: add|del|desc|remove|reload|restart|start|stop|status|zap|cgroup_remove_service 23 | OPTIONS: [OPTIONS] SERVICE COMMAND [ARGUMENTS] 24 | -D, --nodeps Disable dependencies1 25 | -d, --debug Enable debug mode 26 | -x, --trace Enable shell trace 27 | -r, --rs Select runscript service type 28 | -s, --sv Select supervision service type 29 | -h, --help Print help and exit 30 | EOH 31 | ${1+exit ${1}} 32 | } 33 | 34 | while true; do 35 | case "${1}" in 36 | (-D|--node*) SVC_DEPS=0 ;; 37 | (-p|--deps*) SVC_DEPS=1 ;; 38 | (-r|--rs) SV_TYPE="rs" ;; 39 | (-s|--sv) SV_TYPE="sv" ;; 40 | (-x|--trace) set -x ;; 41 | (-d|--debug) SVC_DEBUG=true;; 42 | (-h|--help) help_message 0 ;; 43 | (*) break ;; 44 | esac 45 | shift 46 | done 47 | if ! [ ${#} -ge 2 ]; then 48 | echo "${0##*/}: error: Insufficient number of arguments" >&2 49 | exit 1 50 | fi 51 | 52 | : ${SV_LIBDIR:=${0%/sh/*}} 53 | : ${SVC_NAME:=${1##*/}} 54 | name="${SVC_NAME}" 55 | readonly __cmd__="${2}" 56 | readonly __cmd_args__="${@#*$2}" 57 | readonly __svc__="${1}" 58 | readonly __av0__="${0}" 59 | if [ -d "${__svc__}" ]; then 60 | : ${SV_TYPE:=sv} 61 | else 62 | : ${SV_TYPE:=rs} 63 | fi 64 | case "${1}" in 65 | (/etc/sv/*) 66 | : ${SV_SVCDIR:=${1%/*}} 67 | ;; 68 | esac 69 | shift 70 | readonly SVC_NAME SV_TYPE 71 | 72 | if ! . ${SV_LIBDIR}/sh/runscript-functions; then 73 | echo "${0##*/}: error: Required file not found \`${SV_LIBDIR}/sh/runscript-functions'" >&2 74 | rm -f ${SV_TMPDIR}/wait/${SVC_NAME} 75 | exit 1 76 | fi 77 | 78 | svc_cleanup() 79 | { 80 | local ret="$?" last="$_" 81 | rm -f ${SV_TMPDIR}/wait/${SVC_NAME} ${SV_TMPDIR}/envs/${SVC_NAME} 82 | _="${last}" 83 | return ${ret} 84 | } 85 | trap svc_cleanup INT TERM QUIT 86 | SVC_DEBUG "${__svc__}:pid=$$=( ${@} )" 87 | 88 | # 89 | # Handle service command 90 | # 91 | if [ "${SV_TYPE}" = "rs" ]; then 92 | rs_cmd "${@}" 93 | elif [ "${SV_TYPE}" = "sv" ]; then 94 | # 95 | # Save environment file to handle false start failures 96 | # 97 | if [ "${__cmd__}" = "start" -o "${__cmd__}" = "stop" ] || \ 98 | [ "${__cmd__}" = "up" -o "${__cmd__}" = "down" ]; then 99 | for env in SVC_DEBUG SVC_TRACE __SVC_WAIT__ SV_RUNDIR SV_SVCDIR \ 100 | SV_LIBDIR SV_SYSBOOT_LEVEL SV_SHUTDOWN_LEVEL SV_VERSION \ 101 | SV_SYSTEM SV_PREFIX SV_RUNLEVEL SV_INITLEVEL __SV_DEBUG_FD__; do 102 | eval echo "${env}=\$${env}" 103 | done >${SV_TMPDIR}/envs/${SVC_NAME} 104 | ENV_SET SVC_DEPS 105 | else 106 | rm -f ${SV_TMPDIR}/envs/${SVC_NAME} 107 | fi 108 | 109 | svc_cmd "${@}" 110 | else 111 | error "nothing to do -- invalid usage" 112 | exit 1 113 | fi 114 | -------------------------------------------------------------------------------- /runit/1: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/runit/1 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 8 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 9 | 10 | touch /etc/runit/stopit 11 | chmod 0 /etc/runit/stopit 12 | if [ -x ${SV_INIT_SH} ]; then 13 | ${SV_INIT_SH} sysinit 14 | else 15 | 16 | # 17 | # XXX: only sysinit because boot could hang and 18 | # runit does not accept any signal in init stage-1 19 | # 20 | RUNLEVEL=S rc sysinit 21 | 22 | fi 23 | 24 | # 25 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 26 | # 27 | -------------------------------------------------------------------------------- /runit/2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/runit/2 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 8 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 9 | SV_OPTS='log:..................................................................' 10 | 11 | [ -x ${SV_INIT_SH} ] && SV_OPTS="${SV_OPTS}" exec ${SV_INIT_SH} default 12 | 13 | RUNLEVEL=S rc boot 14 | # 15 | # XXX: is this really necessary? 16 | # 17 | RUNLEVEL=3 rc default 18 | 19 | SV_RUNDIR=/var/run/service 20 | SV_SERVICE=/etc/service 21 | case "${SV_RUNDIR}" in 22 | ("${SV_SERVICE}") 23 | ;; 24 | (*/run/*|*/tmp/*) 25 | rm -f -r "${SV_RUNDIR}" 26 | mkdir -p "${SV_RUNDIR}" 27 | cp -LRTp "${SV_SERVICE}" "${SV_RUNDIR}" 28 | ;; 29 | esac 30 | 31 | exec runsvdir ${SV_RUNDIR} ${SV_OPTS} 32 | exec 2>&1 33 | exec ${SHELL:-sh} -aim 34 | 35 | # 36 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 37 | # 38 | -------------------------------------------------------------------------------- /runit/3: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/runit/3 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | exec >/dev/console 2>&1 8 | 9 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 10 | _PATH_WALL= 11 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 12 | SV_SHUTDOWN=/lib/sv/sbin/shutdown 13 | SV_RUNDIR=/run/service 14 | 15 | if [ -x /etc/runit/reboot ]; then 16 | RUNLEVEL=0 ACTION=reboot 17 | else 18 | RUNLEVEL=6 ACTION=shutdown 19 | fi 20 | if [ -x ${SV_SHUTDOWN} ]; then 21 | ${SV_SHUTDOWN} --${ACTION} -m now 22 | fi 23 | if [ -x ${SV_INIT_SH} ]; then 24 | ${SV_INIT_SH} ${ACTION} 25 | # 26 | # XXX: safety net 27 | # 28 | ${SV_SHUTDOWN} --${ACTION} --force now 29 | else 30 | 31 | echo "System ${ACTION}" | ${_PATH_WALL:-busybox wall} 32 | 33 | sv -w 10 force-shutdown ${SV_RUNDIR}/* 34 | RUNLEVEL="${LEVEL}" rc "${ACTION}" 35 | # 36 | # XXX: safety net in case rc return 37 | # assume sysvinit utlities are used (-f)/(-q) for FreeBSD, OpenBSD ... 38 | # 39 | ${ACTION} -f 40 | 41 | fi 42 | 43 | # 44 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 45 | # 46 | -------------------------------------------------------------------------------- /runit/ctrlaltdel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/runit/ctrlaltdel 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 8 | _PATH_WALL= 9 | SV_SHUTDOWN=/lib/sv/sbin/shutdown 10 | 11 | touch /etc/runit/stopit 12 | chmod 100 /etc/runit/stopit 13 | if [ -x ${SV_SHUTDOWN} ]; then 14 | [ -x /etc/runit/reboot ] && ARG=-r || ARG=-p 15 | ${SV_SHUTDOWN} ${ARG} -l now 16 | else 17 | 18 | echo "System is going down in 3 seconds..." | ${_PATH_WALL:-busybox wall} 19 | sleep 3 20 | 21 | fi 22 | 23 | # 24 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /runit/reboot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tokiclover/supervision/e25d6c7f0f4132ba197f34c8f3480409f5dc921b/runit/reboot -------------------------------------------------------------------------------- /s6/crash: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/s6/crash 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | : ${SV_RUNDIR:=/run/service} 8 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 9 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 10 | 11 | if [ -x ${SV_INIT_SH} ]; then 12 | exec ${SV_INIT_SH} default 13 | fi 14 | 15 | exec /usr/bin/env - PATH=${PATH} s6-svscan ${SV_OPTS} ${SV_RUNDIR} 16 | exec 2>&1 17 | exec ${SHELL:-sh} -aim 18 | 19 | # 20 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 21 | # 22 | -------------------------------------------------------------------------------- /s6/finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/s6/finish 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | exec >/dev/console 2>&1 8 | 9 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 10 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 11 | SV_SHUTDOWN=/lib/sv/sbin/shutdown 12 | [ -d /lib/sv ] && PATH="/lib/sv/bin:/lib/sv/sbin:${PATH}" 13 | 14 | case "${1}" in 15 | (-[6ir]|reboot) RUNLEVEL=6 ACTION=reboot ;; 16 | (-[07hpqst]|halt|poweroff) RUNLEVEL=0 ACTION=shutdown;; 17 | esac 18 | : ${RUNLEVEL:=0} 19 | : ${ACTION:=shutdown} 20 | 21 | if [ -x ${SV_INIT_SH} ]; then 22 | ${SV_INIT_SH} "${ACTION}" || sv-rc ${ACTION} 23 | if [ -x ${SV_SHUTDOWN} ]; then 24 | ${SV_SHUTDOWN} --${ACTION} now 25 | fi 26 | case "${ACTION}" in 27 | (reboot) reboot -f ;; 28 | (shutdown) halt -f ;; 29 | esac 30 | fi 31 | 32 | s6-svc -D -T 10000 ${SV_RUNDIR}/* 33 | RUNLEVEL="${RUNLEVEL}" rc "${ACTION}" 34 | 35 | case "${ACTION}" in 36 | (reboot) reboot ; reboot -f ;; 37 | (shutdown) halt -p ; halt -f ;; 38 | esac 39 | 40 | # 41 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 42 | # 43 | -------------------------------------------------------------------------------- /s6/init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/s6/init 0 2017/01/12 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | PATH=/bin:/sbin:/usr/bin:/usr/sbin 7 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 8 | SV_RUNDIR=/run/service 9 | SV_SERVICE=/etc/service 10 | 11 | 12 | mkdir -m 0755 -p "${SV_RUNDIR}"/.s6-svscan 13 | for link in crash finish; do 14 | ln -f -s /etc/s6/${link} "${SV_RUNDIR}"/.s6-svscan/${link} 15 | done 16 | 17 | if [ -x ${SV_INIT_SH} ]; then 18 | ${SV_INIT_SH} sysinit 19 | exec ${SV_INIT_SH} default 20 | fi 21 | RUNLEVEL=S rc sysinit 22 | RUNLEVEL=S rc boot 23 | # 24 | # XXX: is this really necessary? 25 | # 26 | RUNLEVEL=3 rc default 27 | 28 | case "${SV_RUNDIR}" in 29 | ("${SV_SERVICE}") 30 | ;; 31 | (*/run/*|*/tmp/*) 32 | rm -f -r "${SV_RUNDIR}" 33 | mkdir -p "${SV_RUNDIR}" 34 | cp -LRTp "${SV_SERVICE}" "${SV_RUNDIR}" 35 | ;; 36 | esac 37 | 38 | exec s6-svscan ${SV_OPTS} ${SV_RUNDIR} 39 | exec 2>&1 40 | exec ${SHELL:-sh} -aim 41 | 42 | # 43 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 44 | # 45 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | -include ../config.mak 2 | CC ?= cc 3 | 4 | dist_SRCS := error.c helper.c 5 | dist_HDRS := error.h helper.h 6 | timespec_SRCS := timespec.c 7 | timespec_HDRS := timespec.h 8 | 9 | .SECONDEXPANSION: 10 | checkpath_SRCS := checkpath.c error.c 11 | sv-config_SRCS := $(dist_SRCS) sv-config.c sv-conf.c 12 | sv-shutdown_SRCS := sv-shutdown.c $(dist_SRCS) 13 | sv-shutdown_LIBS = $(LIBRT_LIBS) 14 | fstabinfo_SRCS := fstabinfo.c error.c 15 | mountinfo_SRCS := mountinfo.c error.c sv-list.c 16 | waitfile_SRCS := error.c waitfile.c 17 | 18 | sv-init_SRCS := sv-init.c error.c 19 | sv-run_SRCS := sv-conf.c sv-deps.c sv-run.c sv-list.c sv-rc.c $(dist_SRCS) 20 | sv-run_HDRS := sv.h sv-conf.h sv-copyright.h 21 | sv-run_CFLAGS = $(PTHREAD_FLAGS) 22 | sv-run_LDFLAGS = $(PTHREAD_FLAGS) 23 | 24 | supervision_SRCS := supervision.c error.c $(timespec_SRCS) 25 | svd_SRCS := svd.c error.c $(timespec_SRCS) 26 | svr_SRCS := svr.c error.c $(timespec_SRCS) 27 | svp_SRCS := svp.c error.c 28 | 29 | HDRRS = $(dist_HDRS) $(sv-run_HDRS) 30 | .SECONDEXPANSION: 31 | dist_BINS := \ 32 | checkpath \ 33 | fstabinfo \ 34 | mountinfo \ 35 | supervision \ 36 | sv-config \ 37 | sv-init \ 38 | svd \ 39 | svp \ 40 | svr \ 41 | sv-shutdown \ 42 | waitfile 43 | 44 | ifeq (SYSVINIT,yes) 45 | dist_BINS += initctl 46 | initctl_SRCS := initctl.c $(dist_SRCS) 47 | endif 48 | 49 | all: $(dist_BINS) sv-run 50 | 51 | clean: 52 | rm -f $(dist_BINS) $(dist_SRCS:%.c=%.o) $(sv-run_SRCS:%.c=%.o) $(dist_BINS:%.c=%.o%=%.o) \ 53 | $(dist_BINS) 54 | 55 | sv-run: $(sv-run_SRCS:%.c=%.o) $(dist_HDRS) $(sv-run_HDRS) 56 | $(CC) $(CFLAGS) $($@_CFLAGS) -o $@ $(sv-run_SRCS:%.c=%.o) $(LDFLAGS) $($@_LDFLAGS) $($@_LIBS) 57 | 58 | supervision_HDRS := error.h sv-copyright.h $(timespec_GDRS) 59 | svd_HDRS := config.h error.h sv-copyright.h $(timespec_HDRS) svd.h 60 | svr_HDRS := config.h error.h sv-copyright.h $(timespec_HDRS) svd.h supervision.h 61 | svp_HDRS := config.h error.h sv-copyright.h 62 | 63 | mountinfo_HDRS := sv-list.h 64 | sv-config_HDRS := $(dist_HDRS) sv-conf.h 65 | sv-init_HDRS := config.h sv-copyright.h 66 | sv-shutdown_HDRS := error.h sv-copyright.h 67 | 68 | checkpath: $(ceckpath_SRCS:%.c=%.o) $(checkpath_HDRS) 69 | sv-config: $(sv-config_SRCS:%.c=%.o) $(sv-config_HDRS) 70 | sv-shutdown: $(sv-shutdown_SRCS:%.c=%.o) $(sv-shutdown_HDRS) 71 | supervision: $(supervision_SRCS:%.c=%.o) $(supervision_HDRS) 72 | fstabinfo: $(fstabinfo_SRCS:%.c=%.o) $(fstabinfo_HDRS) 73 | mountinfo: $(mountinfo_SRCS:%.c=%.o) $(mountinfo_HDRS) 74 | waitfile: $(waitfile_SRCS:%.c=%.o) $(waitfile_HDRS) 75 | sv-init: $(sv-init_SRCS:%.c=%.o) $(sv-init_HDRS) 76 | svd: $(svd_SRCS:%.c=%.o) $(svd_HDRS) 77 | svr: $(svr_SRCS:%.c=%.o) $(svr_HDRS) 78 | svp: $(svp_SRCS:%.c=%.o) $(svp_HDRS) 79 | initctl: $(initctl_SRCS:%.c=%.o) $(initctl_HDRS) 80 | 81 | $(dist_BINS): $$@.o $($$@_SRCS:%.c=%.o) $($$@_HDRS) 82 | $(CC) $(CFLAGS) $($@_CFLAGS) -o $@ $($@_SRCS:%.c=%.o) $(LDFLAGS) $($@_LDFLAGS) $($@_LIBS) 83 | 84 | %.o: %.c %.h 85 | $(CC) $(CFLAGS) $(@_CFLAGS) $(CPPFLAGS) $(@_CPPFLAGS) $< -c -o $@ 86 | 87 | -------------------------------------------------------------------------------- /src/helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016-2018 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * it and/or modify it under the terms of the 2-clause, simplified, 7 | * new BSD License included in the distriution of this package. 8 | * 9 | * @(#)heleper.h 0.13.0 2016/12/28 10 | */ 11 | 12 | #ifndef HELPER_H 13 | #define HELPER_H 14 | 15 | #include 16 | #include 17 | #include 18 | #ifdef __linux__ 19 | # include 20 | #endif 21 | #include "error.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #ifdef __linux__ 28 | /* look for @regex regular exppression in @file 29 | * @return: 0 when found; 1 when not; <= -1/-errno on failure; 30 | */ 31 | __attribute__((__unused__)) int file_regex(const char *file, const char *regex); 32 | #endif /* __linux__ */ 33 | 34 | /* 35 | * test(1) clone like file test helper 36 | * @mode char like test (whithout the dash) 'e', 'd', etc; 37 | * @return bool; 38 | */ 39 | __attribute__((__unused__)) int file_test(const char *pathname, int mode); 40 | 41 | #ifndef HAVE_GETLINE 42 | __attribute__((__unused__)) ssize_t getline(char **buf, size_t *len, FILE *stream); 43 | #endif 44 | 45 | /* 46 | * (WARN: only first to second character are used!) 47 | * simple yes/no helper 48 | * @return true/false; 49 | */ 50 | __attribute__((__unused__)) int sv_yesno(const char *str); 51 | 52 | /* 53 | * tiny helper to get terminal cols 54 | * @retrun terminal cols 55 | */ 56 | __attribute__((__unused__)) int get_term_cols(void); 57 | 58 | /* 59 | * get shell string value, removing trailing white spaces and quote 60 | * @str string; 61 | * @return string value 62 | */ 63 | __attribute__((__unused__)) char *shell_string_value(char *str); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* HELPER_H */ 70 | -------------------------------------------------------------------------------- /src/initctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Utility providing an interface to SysVinit's halt, reboot, shutdown, 3 | * poweroff utilities. 4 | * 5 | * Copyright (c) 2016-2018 tokiclover 6 | * This file is part of Supervision 7 | * 8 | * Supervision is free software; you can redistribute 9 | * it and/or modify it under the terms of the 2-clause, simplified, 10 | * new BSD License included in the distriution of this package. 11 | * 12 | * @(#)initctl.c 0.15.0 2019/03/14 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "error.h" 20 | #include "helper.h" 21 | #include "config.h" 22 | 23 | const char *progname; 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | struct init_request ireq; 28 | int fd; 29 | int len; 30 | char arg[] = EXEC_PREFIX "/sbin/sv-shutdown -0"; 31 | mode_t m; 32 | 33 | progname = strrchr(argv[0], '/'); 34 | if (!progname) 35 | progname = argv[0]; 36 | else 37 | progname++; 38 | 39 | if (!file_test(INIT_FIFO, 'p')) { 40 | m = umask(0); 41 | if (mkfifo(INIT_FIFO, 0600) < 0) 42 | ERROR("Failed to create %s FIFO", INIT_FIFO); 43 | umask(m); 44 | } 45 | if ((fd = open(INIT_FIFO, O_RDONLY | O_NDELAY | O_NONBLOCK)) < 0) 46 | ERROR("Failed to open %s", INIT_FIFO); 47 | if (open(INIT_FIFO, O_WRONLY | O_NDELAY | O_NONBLOCK) < 0) 48 | ERROR("Failed to open %s", INIT_FIFO); 49 | 50 | for (;;) { 51 | len = read(fd, (char *)&ireq, sizeof(ireq)); 52 | if (len < 0) 53 | ERROR("Failed to read %s", INIT_FIFO); 54 | else if (len == 0) 55 | continue; 56 | else if (len != sizeof(ireq)) { 57 | ERR("Invalid %d bytes length.\n", len); 58 | continue; 59 | } 60 | if (ireq.magic != INIT_MAGIC) { 61 | ERR("Invalid magic header %x.\n", ireq.magic); 62 | continue; 63 | } 64 | if (ireq.cmd == INIT_CMD_RUNLVL) { 65 | sprintf(arg+strlen(arg)-1, "%c", ireq.runlevel); 66 | if (system(arg)) 67 | ERR("Failed to execute `%s'", arg); 68 | } 69 | } 70 | return(EXIT_SUCCESS); 71 | } 72 | -------------------------------------------------------------------------------- /src/supervision.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" CopyLeft (c) 2016-2018 tokiclover 3 | .\" 4 | .\" Distributed under the terms of the 2-clause BSD License as 5 | .\" stated in the COPYING file that comes with the source files 6 | .\" 7 | .pc 8 | .TH SUPERVISION 1 "2015-03-14" "0.15.0" "User Commands Manual" 9 | .SH NAME 10 | supervision \- supervise a directory 11 | .SH DESCRIPTION 12 | .B supervision 13 | is a utility to supervise collection of daemon maintedned in directory. 14 | See 15 | .BR supervision (5) 16 | for more information about the architecture and the layout of the 17 | supervised directory and the service layout defined as directory. 18 | .B SYNOPSIS 19 | for more information. 20 | 21 | .SH SYNOPSIS 22 | .B supervision 23 | .RB [\| \-d | \-\-debug \|] 24 | .RB [\| \-l | \-\-syslog \|] 25 | .RB [\| \-s | \-\-sid \|] 26 | .BR \| DIR \| 27 | 28 | .B supervision 29 | .RB [\| \-h | \-\-help \|] 30 | .RB [\| \-v | \-\-version \|] 31 | 32 | .SH OPTIONS 33 | .TP 34 | .RB [\| \-d | \-\-debug \|] 35 | Enable debugging 36 | .TP 37 | .RB [\| \-l | \-\-syslog \|] 38 | Log message to 39 | .RB syslog (1) 40 | .TP 41 | .RB [\| \-s | \-\-sid \|] 42 | Use a new session 43 | .TP 44 | .RB \| \-v | \-\-version \| 45 | Print the version message 46 | .TP 47 | .RB \| \-h | \-\-help \| 48 | Print the help message 49 | 50 | .SH "RETURN VALUE" 51 | .TP 52 | .B 0 53 | success 54 | .TP 55 | .B 1 56 | miscellaneous operational failures 57 | 58 | .SH "APPLICATION USAGE" 59 | None. 60 | .SH "FUTURE DIRECTIONS" 61 | None. 62 | .SH "SEE ALSO" 63 | .BR svd (1), 64 | .BR svl (1), 65 | .BR svp (1), 66 | .BR svr (1), 67 | .BR supervision (5), 68 | .SH AUTHORS 69 | tokiclover 70 | .\" 71 | .\" vim:fenc=utf-8:ft=groff:ci:pi:sts=2:sw=2:ts=2:expandtab: 72 | .\" 73 | -------------------------------------------------------------------------------- /src/supervision.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * new BSD License included in the distriution of this package. 7 | * 8 | * @(#)supervision.h 0.15.0 2019/03/14 9 | */ 10 | 11 | #ifndef SUPERVISION_H 12 | #define SUPERVISION_H 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef SYSCONFDIR 19 | # define SYSCONFDIR "/etc" 20 | #endif 21 | #ifndef RUNDIR 22 | # if defined(__linux__) || (defined(__FreeBSD_kernel__) && \ 23 | defined(__GLIBC__)) || defined(__GNU__) 24 | # define RUNDIR "/run" 25 | # else 26 | # define RUNDIR "/var/run" 27 | # endif 28 | #endif 29 | #ifndef SV_CONFDIR 30 | # define SV_SVCDIR SYSCONFDIR "/sv" 31 | #endif 32 | #ifndef SV_RUNDIR 33 | # define SV_RUNDIR RUNDIR "/supervision" 34 | #endif 35 | 36 | #ifndef SV_PIDFILE 37 | # define SV_PIDFILE ".tmp/supervision.pid" 38 | #endif 39 | #ifndef SV_FIFO 40 | # define SV_FIFO ".tmp/supervision.ctl" 41 | #endif 42 | #ifndef SVD 43 | # define SVD EXEC_PREFIX "/bin/svd" 44 | #endif 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | #endif /*SUPERVISION_H*/ 50 | -------------------------------------------------------------------------------- /src/sv-conf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * it and/or modify it under the terms of the 2-clause, simplified, 7 | * new BSD License included in the distriution of this package. 8 | * 9 | * @(#)sv-conf.c 0.14.0 2018/07/20 10 | */ 11 | 12 | #include "helper.h" 13 | #include "sv.h" 14 | 15 | #define SV_CONFIG_FILE SYSCONFDIR "/sv.conf" 16 | 17 | /* global configuration array */ 18 | static const char **SV_CONFIG_ARRAY; 19 | 20 | /* load configuration file as an environment list */ 21 | static int sv_conf_load(void); 22 | /* free an allocated configuration list */ 23 | static void sv_conf_free(void); 24 | 25 | inline int sv_conf_yesno(const char *env) { 26 | #ifdef DEBUG 27 | if (sv_debug) DBG("%s(%s)\n", __func__, env); 28 | #endif 29 | return sv_yesno(sv_getconf(env)); 30 | } 31 | 32 | const char *sv_getconf(const char *env) 33 | { 34 | #ifdef DEBUG 35 | if (sv_debug) DBG("%s(%s)\n", __func__, env); 36 | #endif 37 | if (!SV_CONFIG_ARRAY) 38 | if (sv_conf_load()) 39 | return NULL; 40 | if (!env) 41 | return NULL; 42 | 43 | const char *ptr; 44 | int i = 0; 45 | 46 | while ((ptr = SV_CONFIG_ARRAY[i])) 47 | if (!strcmp(SV_CONFIG_ARRAY[i++], env)) 48 | break; 49 | 50 | if (!ptr) 51 | return NULL; 52 | 53 | ptr = strchr(ptr, '='); 54 | if (ptr) 55 | return ptr+1; 56 | 57 | return NULL; 58 | } 59 | 60 | static int sv_conf_load(void) 61 | { 62 | FILE *fp; 63 | char *line = NULL, *ptr; 64 | size_t count = 0, len = 0, l, num = 8, pos; 65 | 66 | #ifdef DEBUG 67 | if (sv_debug) DBG("%s(void)\n", __func__); 68 | #endif 69 | 70 | if ((fp = fopen(SV_CONFIG_FILE, "r")) == NULL) { 71 | WARN("Failed to open %s\n", SV_CONFIG_FILE); 72 | return -1; 73 | } 74 | SV_CONFIG_ARRAY = err_calloc(num, sizeof(void *)); 75 | 76 | while (getline(&line, &len, fp) > 0) { 77 | if (line[0] == '#') 78 | continue; 79 | /* get conf name */ 80 | ptr = strchr(line, '=')+1; 81 | pos = ptr-line; 82 | 83 | /* get conf value */ 84 | ptr = shell_string_value(ptr); 85 | if (ptr == NULL) 86 | continue; 87 | 88 | /* append conf value if any */ 89 | l = strlen(ptr); 90 | if (++l) { 91 | memmove(line+pos, ptr, l); 92 | SV_CONFIG_ARRAY[count++] = err_strdup(line); 93 | } 94 | else 95 | continue; 96 | 97 | /* expand list if necessary */ 98 | if (count == num) { 99 | num += 8; 100 | SV_CONFIG_ARRAY = err_realloc(SV_CONFIG_ARRAY, sizeof(void *)*num); 101 | } 102 | } 103 | fclose(fp); 104 | 105 | SV_CONFIG_ARRAY[count++] = NULL; 106 | SV_CONFIG_ARRAY = err_realloc(SV_CONFIG_ARRAY, sizeof(void *)*count); 107 | 108 | #ifdef DEBUG 109 | atexit(sv_conf_free); 110 | #endif 111 | return 0; 112 | } 113 | 114 | static void sv_conf_free(void) 115 | { 116 | int i = 0; 117 | #ifdef DEBUG 118 | if (sv_debug) DBG("%s(void)\n", __func__); 119 | #endif 120 | while (SV_CONFIG_ARRAY[i]) 121 | free((void *)SV_CONFIG_ARRAY[i++]); 122 | free(SV_CONFIG_ARRAY); 123 | } 124 | 125 | -------------------------------------------------------------------------------- /src/sv-conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * it and/or modify it under the terms of the 2-clause, simplified, 7 | * new BSD License included in the distriution of this package. 8 | * 9 | * @(#)sv-conf.h 0.14.0 2018/08/18 10 | */ 11 | 12 | #ifndef SV_CONF_H 13 | #define SV_CONF_H 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | extern int sv_debug; 20 | 21 | /* 22 | * retrieve a configuration value like getenv(3) 23 | * @envp: configuration list; 24 | * @env: configuration name; 25 | */ 26 | extern const char *sv_getconf(const char *env); 27 | /* 28 | * simple helper to ease yes/no querries of config settings 29 | * @return: true/false; 30 | */ 31 | extern int sv_conf_yesno(const char *env); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* SV_CONF_H */ 38 | -------------------------------------------------------------------------------- /src/sv-copyright.h: -------------------------------------------------------------------------------- 1 | #ifndef SV_COPYRIGHT_H 2 | #define SV_COPYRIGHT "@(#) Copyright (c) 2015-2019 tokiclover \n" \ 3 | "License 2-clause, new, simplified BSD or MIT (at your name choice)\n" \ 4 | "This is free software: you are free to change and distribute it.\n" \ 5 | "There is NO WARANTY, to the extend permitted by law.\n" 6 | #endif /* SV_COPYRIGHT_H */ 7 | -------------------------------------------------------------------------------- /src/sv-list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * it and/or modify it under the terms of the 2-clause, simplified, 7 | * new BSD License included in the distriution of this package. 8 | * 9 | * @(#)sv-list.h 0.13.0 2016/12/30 10 | */ 11 | 12 | #ifndef SV_LIST_H 13 | #define SV_LIST_H 14 | 15 | #include "queue.h" 16 | #include "error.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* singly-linked list using queue(3) */ 23 | typedef struct SV_String { 24 | char *str; 25 | void *data; 26 | TAILQ_ENTRY(SV_String) entries; 27 | } SV_String_T; 28 | typedef TAILQ_HEAD(SV_StringList, SV_String) SV_StringList_T; 29 | 30 | /* string list helpers to manage string list using queue(3) */ 31 | extern SV_StringList_T *sv_stringlist_new(void); 32 | extern SV_StringList_T *sv_stringlist_sort(SV_StringList_T **list); 33 | extern SV_StringList_T *sv_stringlist_cat(SV_StringList_T **dst, SV_StringList_T **src); 34 | extern SV_String_T *sv_stringlist_append (SV_StringList_T *list, SV_String_T *svc); 35 | extern SV_String_T *sv_stringlist_add (SV_StringList_T *list, const char *str); 36 | extern SV_String_T *sv_stringlist_adu (SV_StringList_T *list, const char *str); 37 | extern SV_String_T *sv_stringlist_find(SV_StringList_T *list, const char *str); 38 | extern int sv_stringlist_del (SV_StringList_T *list, const char *str); 39 | extern int sv_stringlist_rem (SV_StringList_T *list, SV_String_T *elm); 40 | extern size_t sv_stringlist_len (SV_StringList_T *list); 41 | extern int sv_stringlist_mov (SV_StringList_T *src, SV_StringList_T *dst, SV_String_T *ent); 42 | extern void sv_stringlist_free(SV_StringList_T **list); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* SV_LIST_H */ 49 | -------------------------------------------------------------------------------- /src/svd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * new BSD License included in the distriution of this package. 7 | * 8 | * @(#)svd.h 0.15.0 2019/03/14 9 | */ 10 | 11 | #ifndef SVD_H 12 | #define SVD_H 13 | 14 | #include "config.h" 15 | 16 | #ifndef SYSCONFDIR 17 | # define SYSCONFDIR "/etc" 18 | #endif 19 | #ifndef RUNDIR 20 | # if defined(__linux__) || (defined(__FreeBSD_kernel__) && \ 21 | defined(__GLIBC__)) || defined(__GNU__) 22 | # define RUNDIR "/run" 23 | # else 24 | # define RUNDIR "/var/run" 25 | # endif 26 | #endif 27 | #ifndef SV_CONFDIR 28 | # define SV_SVCDIR SYSCONFDIR "/sv" 29 | #endif 30 | #ifndef SV_RUNDIR 31 | # define SV_RUNDIR RUNDIR "/sv" 32 | #endif 33 | 34 | #ifndef SV_TIMEOUT 35 | # define SV_TIMEOUT 1U 36 | #endif 37 | #ifndef SV_RUN_NUM 38 | # define SV_RUN_NUM 100 39 | #endif 40 | #ifndef SVD 41 | # define SVD EXEC_PREFIX "/bin/svd" 42 | #endif 43 | #ifndef SVL 44 | # define SVL EXEC_PREFIX "/bin/svl" 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #define ST_WANT_UP 'u' 52 | #define ST_WANT_DOWN 'd' 53 | enum { 54 | ST_DOWN, 55 | #define ST_DOWN ST_DOWN 56 | ST_RUN, 57 | #define ST_RUN ST_RUN 58 | ST_FINISH 59 | #define ST_FINISH ST_FINISH 60 | }; 61 | 62 | #define ST_BUF_SIZ 24LU 63 | static char st_buf[ST_BUF_SIZ]; 64 | 65 | enum { 66 | ST_OFF_PSEC = 0LU, 67 | ST_OFF_NSEC = 8LU, 68 | ST_OFF_PID = 16LU, 69 | ST_OFF_PAUSE = 20LU, 70 | #define ST_OFF_PAUSE ST_OFF_PAUSE 71 | ST_OFF_UP = 21LU, 72 | #define ST_OFF_UP ST_OFF_UP 73 | ST_OFF_TERM = 22LU, 74 | #define ST_OFF_TERM ST_OFF_TERM 75 | ST_OFF_RUN = 23LU, 76 | #define ST_OFF_RUN ST_OFF_RUN 77 | }; 78 | 79 | enum { 80 | SW_DOWN = 0x00, 81 | #define SW_DOWN SW_DOWN 82 | SW_PAUSE = 0x01, 83 | #define SW_PAUSE SW_PAUSE 84 | SW_TERM = 0x02, 85 | #define SW_TERM SW_TERM 86 | SW_EXIT = 0x04, 87 | #define SW_EXIT SW_EXIT 88 | SW_RUN = 0x08, 89 | #define SW_RUN SW_RUN 90 | SW_FINISH = 0x10, 91 | #define SW_FINISH SW_FINISH 92 | }; 93 | enum { 94 | SV_EXEC_RUN, 95 | #define SV_EXEC_RUN SV_EXEC_RUN 96 | SV_EXEC_FINISH 97 | #define SV_EXEC_FINISH SV_EXEC_FINISH 98 | }; 99 | 100 | static struct sdent { 101 | int sd_pid, sd_stat, sd_ctrl, sd_want, sd_ret; 102 | int fd_lock, fd_ctrl, fd_status, sv_run, sv_log; 103 | void *fp_lock, *fp_ctrl, *fp_status; 104 | char *sv_pid, *sv_stat, *sv_status, *sv_control, *sv_lock, *sv_ok; 105 | struct timespec sv_time; 106 | } sde[2] = { 107 | [0] = { 108 | .sd_want = SW_RUN, 109 | .sd_ctrl = SW_RUN, 110 | .sv_control = "supervise/control", 111 | .sv_pid = "supervise/pid", 112 | .sv_status = "supervise/status", 113 | .sv_stat = "supervise/stat", 114 | .sv_lock = "supervise/lock", 115 | .sv_ok = "supervise/ok", 116 | }, 117 | [1] = { 118 | .sd_ctrl = SW_RUN, 119 | .sv_control = "log/supervise/control", 120 | .sv_pid = "log/supervise/pid", 121 | .sv_stat = "log/supervise/stat", 122 | .sv_status = "log/supervise/status", 123 | .sv_lock = "log/supervise/lock", 124 | .sv_ok = "log/supervise/ok", 125 | } 126 | }, *sd_svc = &sde[0], *sd_log = &sde[1]; 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | #endif /*SVD_H*/ 132 | -------------------------------------------------------------------------------- /src/timespec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * new BSD License included in the distriution of this package. 7 | * 8 | * @(#)timespec.c 0.15.0 2019/03/18 9 | */ 10 | 11 | 12 | #include "timespec.h" 13 | 14 | uint64_t timespec_pack_sec(char *restrict s, register uint64_t u) 15 | { 16 | register int o = TIMESPEC_NSEC; 17 | while (o--) s[o] = (unsigned char)(u & 255), u >>= CHAR_BIT; 18 | s[0] = (unsigned char)u; 19 | return u; 20 | } 21 | 22 | __attribute__((__unused__)) uint64_t timespec_unpack_sec(char *restrict s) 23 | { 24 | register uint64_t u; 25 | register int o = 0; 26 | u = (unsigned char)s[o]; 27 | while (o++ < TIMESPEC_NSEC) u <<= CHAR_BIT, u += (unsigned char)s[o]; 28 | return u; 29 | } 30 | 31 | __attribute__((__unused__)) int timespec_cmp(struct timespec *restrict u, struct timespec *restrict v) 32 | { 33 | if (u->tv_sec < v->tv_sec ) return -1; 34 | if (u->tv_sec > v->tv_sec ) return 1; 35 | if (u->tv_nsec < v->tv_nsec) return -1; 36 | if (u->tv_nsec > v->tv_nsec) return 1; 37 | return 0; 38 | } 39 | 40 | void timespec_pack(char *restrict s, struct timespec *restrict ts) 41 | { 42 | register char *p = s; 43 | timespec_pack_sec(p, (uint64_t)ts->tv_sec & UINT64_MAX); 44 | p += TIMESPEC_NSEC; 45 | timespec_pack_sec(p, (uint64_t)ts->tv_nsec & UINT64_MAX); 46 | p += TIMESPEC_NSEC; 47 | } 48 | 49 | void timespec_unpack(char *restrict s, struct timespec *restrict ts) 50 | { 51 | register char *p = s; 52 | ts->tv_nsec = timespec_unpack_sec(p); 53 | p += TIMESPEC_NSEC; 54 | ts->tv_sec = timespec_unpack_sec(p); 55 | } 56 | 57 | void timespec_add(struct timespec *restrict ts, struct timespec *restrict u, struct timespec *restrict v) 58 | { 59 | ts->tv_sec = u->tv_sec + v->tv_sec; 60 | 61 | if (TIMESPEC_NSEC_MAX <= u->tv_nsec) { 62 | ts->tv_sec++; 63 | ts->tv_nsec = v->tv_nsec; 64 | } 65 | else if (TIMESPEC_NSEC_MAX <= v->tv_nsec) { 66 | ts->tv_sec++; 67 | ts->tv_nsec = u->tv_nsec; 68 | } 69 | else { 70 | if ((u->tv_nsec + v->tv_nsec) > TIMESPEC_NSEC_MAX) { 71 | ts->tv_sec++; 72 | ts->tv_nsec = u->tv_nsec > v->tv_nsec ? 73 | u->tv_nsec - TIMESPEC_NSEC_MAX - 1LU + v->tv_nsec : 74 | v->tv_nsec - TIMESPEC_NSEC_MAX - 1LU + u->tv_nsec; 75 | } 76 | else 77 | ts->tv_nsec = u->tv_nsec + v->tv_nsec; 78 | } 79 | } 80 | 81 | void timespec_sub(struct timespec *restrict ts, struct timespec *restrict u, struct timespec *restrict v) 82 | { 83 | ts->tv_sec = u->tv_sec - v->tv_sec; 84 | 85 | if (TIMESPEC_NSEC_MAX <= u->tv_nsec) { 86 | ts->tv_nsec = u->tv_nsec - v->tv_nsec; 87 | } 88 | else if (TIMESPEC_NSEC_MAX <= v->tv_nsec) { 89 | if (ts->tv_sec) ts->tv_sec--; 90 | ts->tv_nsec = u->tv_nsec; 91 | } 92 | else { 93 | if (u->tv_nsec > v->tv_nsec) 94 | ts->tv_nsec = u->tv_nsec - v->tv_nsec; 95 | else { 96 | if (ts->tv_sec) ts->tv_sec--; 97 | ts->tv_nsec = TIMESPEC_NSEC_MAX + 1LU + (u->tv_nsec - v->tv_nsec); 98 | } 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/timespec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 tokiclover 3 | * This file is part of Supervision 4 | * 5 | * Supervision is free software; you can redistribute 6 | * new BSD License included in the distriution of this package. 7 | * 8 | * @(#)timespec.h 0.15.0 2019/03/14 9 | */ 10 | 11 | #ifndef TIMESPEC_H 12 | #define TIMESPEC_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define TIMESPEC_NSEC 8LU 24 | #define TIMESPEC_SIZE 16LU 25 | #define TIMESPEC_NSEC_MAX 999999999LU 26 | #define TIMESPEC_APPROX(ta) ((ta)->ta_sec+(ta)->ta_nsec > 50000000LU ? 1LU : OLU) 27 | 28 | #define TIMESPEC(ta) clock_gettime(CLOCK_REALTIME, ta) 29 | 30 | extern uint64_t timespec_pack_sec (char *restrict s, register uint64_t u); 31 | extern uint64_t timespec_unpack_sec(char *restrict s) __attribute__((__unused__)); 32 | 33 | extern void timespec_add(struct timespec *restrict ts, struct timespec *restrict u, struct timespec *restrict v); 34 | extern void timespec_sub(struct timespec *restrict ts, struct timespec *restrict u, struct timespec *restrict v); 35 | extern int timespec_cmp(struct timespec *restrict ts, struct timespec *restrict u) __attribute__((__unused__)); 36 | 37 | extern void timespec_pack (char *restrict s, struct timespec *restrict ts); 38 | extern void timespec_unpack(char *restrict s, struct timespec *restrict ts); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | #endif /*TIMESPEC_H*/ 44 | -------------------------------------------------------------------------------- /sv.conf.d/alsasound: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/alsasound, 2016/06/06 Exp $ 3 | # 4 | # Enable this to save mixer settings on service stop 5 | # 6 | SAVE_ON_STOP=Yes 7 | 8 | # 9 | # Enable this to restore mixer settings on service start 10 | # 11 | RESTORE_ON_START=Yes 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /sv.conf.d/checkfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: /etc/sv.conf.d/checkfs, 2016/06/06 Exp $ 3 | # 4 | 5 | # 6 | # Setup extra fsck(8) options 7 | # 8 | FSCK_OPTS= 9 | 10 | # 11 | # Enable fsck(8) in stage-3 or system shutdown/halt 12 | # 13 | CHECKFS_SHUTDOWN=No 14 | 15 | # 16 | # Force fsck by appending `forcefsck' in kernel command line after 17 | # using `-E|--force' command line option to sv-shutdown(8) 18 | # 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /sv.conf.d/console: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/console, 2016/06/06 Exp $ 3 | # 4 | 5 | # 6 | # Console font to use (see /usr/share/consolefont) without the extension 7 | # (e.g. '.psf.gz') 8 | #CONSOLEFONT="ter-g14n" 9 | # 10 | # Character set map to use (see /usr/share/consoletrans) 11 | #CONSOLE_TRANSALTAION="8859-16_to_uni" 12 | # 13 | # Unicode map to use (see /usr/share/unimaps) 14 | #CONSOLE_UNICODEMAP="iso01" 15 | 16 | # 17 | # Console keymap to use (see /usr/share/keymaps) 18 | #CONSOLE_KEYMAP="de" 19 | # 20 | # Load extended keyboard mappings 21 | #CONSOLE_KEYMAP_EXTENDED="backspace keypad" 22 | # 23 | # Some fonts map ALTGr-E to currency symbol instead of euro; 24 | # set this to yes to fix it. 25 | #CONSOLE_KEYMAP_EURO="Yes" 26 | 27 | # 28 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 29 | # 30 | -------------------------------------------------------------------------------- /sv.conf.d/device-mapper: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/device-mapper, 2016/06/06 Exp $ 3 | # 4 | # See dmsetup(8) and DOCDIR/supervision/dmtab for more information. 5 | # Everything is configured in dmtab(8); so copy DOCDIR/supervision/dmtab 6 | # to /etc/dmtab and setup everything in that configuration file. 7 | # 8 | # Enable this for software or fake ATA RAID support for physical volumes 9 | # 10 | #SVC_NEED="raid" 11 | 12 | # 13 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 14 | # 15 | -------------------------------------------------------------------------------- /sv.conf.d/dmcrypt: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/dmcrypt, 2016/06/06 Exp $ 3 | # 4 | # See cryptsetup(8) and /usr/share/doc/supervision/crypttab for more information. 5 | # Everything is configured in crypttab(8); so copy DOCDIR/crypttab 6 | # to /etc/crypttab and setup everything in that configuration file. 7 | # 8 | # If software raid is need or used for this service, add `raid' to 9 | # SVC_NEED or SVC_USE in this configuration file . Likewise, if LVM 10 | # is needed or used, just add `lvm' to any of those variables. 11 | #SVC_USE=lvm 12 | #SVC_NEED=raid 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv.conf.d/dmesg: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/dmesg, 2016/06/06 Exp $ 3 | # 4 | # see dmesg(1) for more info 5 | # 6 | DMESG_LEVEL=1 7 | 8 | # 9 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 10 | # 11 | -------------------------------------------------------------------------------- /sv.conf.d/hostname: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/hostname, 2016/06/06 Exp $ 3 | # 4 | # Set the machine hostname 5 | # 6 | HOSTNAME="" 7 | 8 | # 9 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 10 | # 11 | -------------------------------------------------------------------------------- /sv.conf.d/hwclock: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/hwclock, 2018/08/20 Exp $ 3 | # 4 | # 5 | # *** IMPORTANT NOTE: *** 6 | # 7 | # When using hardware time to synchronize system time, with a modern kernel 8 | # (v3.9 or latter), the Linux kernel handle the synchronization internally. 9 | # So, checkout if CONFIG_RTC_HCTOSYS is enabled; if so, remove the service 10 | # from sysboot runlevel by issuing `sv-run --sysboot clock del'. 11 | # 12 | # If a ntp daemon is used to keep the system clock in synchronisation with 13 | # a server, CONFIG_RTC_SYSTOHC should be enabled. 14 | # 15 | # See https://wiki.gentoo.org/wiki/System_time for more information. 16 | # 17 | # *** END OF THE NOTE *** 18 | # 19 | # 20 | # Set clock to 'UTC' (also known as Greenwich Mean Time or GMT for short) 21 | # if the hardware is set up to UTC. Else, set clock to 'local' if the hardware 22 | # clock is set to 'local'; e.g. Windows dual boot users shall set the clock to 23 | # 'local'. 24 | # 25 | HWCLOCK="UTC" 26 | 27 | # 28 | # Enable this to set the system time from the current hardware time. 29 | # Modern kernel with CONFIG_RTC_HCTOSYS=y does not need this if the hardware 30 | # clock is set to 'UTC'. 31 | # 32 | #CLOCK_HCTOSYS="Yes" 33 | 34 | # 35 | # Enable this to set the hardware time from system current time when shutting 36 | # down the system 37 | # 38 | #CLOCK_SYSTOHC="Yes" 39 | # 40 | # Append extra argument to pass to hwclock. Alpha users may append --arc or 41 | # --srm. 42 | # 43 | HWCLOCK_ARGS="" 44 | 45 | # 46 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 47 | # 48 | -------------------------------------------------------------------------------- /sv.conf.d/ip6tables: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/ip6tables, 2016/06/06 Exp $ 3 | # 4 | # See iptables(8) and or ip6tables(8) for more information. 5 | # 6 | # Path of the rules file for saving 7 | IP6TABLES_RULES_FILE="/var/lib/ip6tables/rules-save" 8 | 9 | # 10 | # Extra save and restore options to pass to ip[6]tables 11 | SAVE_RESTORE_OPTIONS="-c" 12 | 13 | # 14 | # Enable rules saving when shutting down the service 15 | #SAVE_ON_STOP="Yes" 16 | 17 | # 18 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 19 | # 20 | -------------------------------------------------------------------------------- /sv.conf.d/ipset: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/ipset, 2016/06/06 Exp $ 3 | # 4 | # See ipset(8) for more information. 5 | # 6 | # Path of the rules file for saving 7 | #IPSET_RULES_FILE="/var/lib/ipset/rules-save" 8 | 9 | # 10 | # Enable rules saving when shutting down the service 11 | SAVE_ON_STOP="Yes" 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /sv.conf.d/iptables: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/iptables, 2016/06/06 Exp $ 3 | # 4 | # See iptables(8) and or ip6tables(8) for more information. 5 | # 6 | # Path of the rules file for saving 7 | IPTABLES_RULES_FILE="/var/lib/iptables/rules-save" 8 | 9 | # 10 | # Extra save and restore options to pass to ip[6]tables 11 | SAVE_RESTORE_OPTIONS="-c" 12 | 13 | # 14 | # Enable rules saving when shutting down the service 15 | #SAVE_ON_STOP="Yes" 16 | 17 | # 18 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 19 | # 20 | -------------------------------------------------------------------------------- /sv.conf.d/kmod: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/kmod, 2019/01/06 Exp $ 3 | # 4 | 5 | # 6 | # Setup this variable for kernel modules for any kernel version 7 | #modules="iwlwifi ucvideo" 8 | 9 | # 10 | # Set module options 11 | # XXX: hypen `-' in module name should be replaced by underscore `_'! 12 | # 13 | #module_ucvideo_options="quircks=0x100" 14 | 15 | # 16 | # Setup any or all following variants to load kernel modules for 17 | # pariticular kernel (major, minor, patch level) versions 18 | #modules_4="snd-hda-intel" 19 | #modules_4_18="sha256-ssse3 twofish-x86_64-3way" 20 | #modules_4_18_100="sha512-ssse3 serpent-avx2 blowfish-x86_64" 21 | 22 | # 23 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 24 | # 25 | 26 | -------------------------------------------------------------------------------- /sv.conf.d/libvirt-guests: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/libvirtd Exp $ 3 | # 4 | # LIBVIRT_URIS 5 | # space separated list of libvirt URIs to communicate with to start/stop guests 6 | # Valid values are anything that can be passed to 'virsh connect' 7 | 8 | LIBVIRT_URIS="qemu:///system qemu:///session" 9 | 10 | 11 | # LIBVIRT_SHUTDOWN 12 | # Valid options: 13 | # * managedsave - Performs a state save external to the VM (for hypervisors 14 | # supporting this operation). qemu-kvm will stop the CPU 15 | # and save off all state to a separate file. When the 16 | # machine is started again, it will resume like nothing 17 | # ever happened. This is guarenteed to always successfully 18 | # stop your machine and restart it. 19 | # 20 | # * shutdown - Sends an ACPI shutdown (think of this as a request to 21 | # your guest to shutdown). There is no way to distinguish 22 | # between guests that are ignoring the shutdown request or 23 | # are stuck or are taking a long time to shutdown. We will 24 | # wait LIBVIRT_MAXWAIT seconds before yanking the power 25 | # out. 26 | # 27 | # * destroy - Immediately stop all running guests. Use with caution as 28 | # this can leave the guest in a corrupted state and might 29 | # lead to data loss. 30 | # 31 | 32 | LIBVIRT_SHUTDOWN="managedsave" 33 | 34 | 35 | # LIBVIRT_MAXWAIT 36 | # Timeout in seconds until stopping a guest and "pulling the plug" on the 37 | # guest 38 | # Valid values are any integer over 0 39 | 40 | LIBVIRT_MAXWAIT="10" 41 | 42 | 43 | # LIBVIRT_START 44 | # If this value is set to 'no', then guests and networks that were shutdown 45 | # by this script when it was stopped will not be started when it is started 46 | # back up. 47 | # Valid values are yes or no 48 | 49 | LIBVIRT_START="yes" 50 | 51 | 52 | # LIBVIRT_IGNORE_AUTOSTART 53 | # If the VM is marked for autostart in its XML configuration then we won't 54 | # save its start when the init script is stopped. The result is that when 55 | # the init script starts back up, no attempt will be made to start the VM or 56 | # confirm it is started. 57 | # Valid values are yes or no 58 | 59 | #LIBVIRT_IGNORE_AUTOSTART="no" 60 | 61 | 62 | # LIBVIRT_NET_SHUTDOWN 63 | # If libvirtd created networks for you (e.g. NATed networks) then this init 64 | # script will shut them down for you if this is set to 'yes'. Otherwise, 65 | # the networks will be left running. For this option to be useful you must 66 | # have enabled the 'virt-network' USE flag and have had libvirt create a 67 | # NATed network for you. Valid values: 'yes' or 'no' 68 | 69 | LIBVIRT_NET_SHUTDOWN="yes" 70 | 71 | # 72 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 73 | # 74 | -------------------------------------------------------------------------------- /sv.conf.d/lvm: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/lvm, 2016/06/06 Exp $ 3 | # 4 | # See lvm(8), lvchange(8), vgchange(8) etc for more information. 5 | # 6 | # Enable this for crypted physical volumes 7 | # 8 | #SVC_NEED="dmcrypt" 9 | 10 | # 11 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 12 | # 13 | -------------------------------------------------------------------------------- /sv.conf.d/miscfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/miscfs, 2016/06/06 Exp $ 3 | # 4 | # Enable /var/log/dmesg boot log 5 | # 6 | DMESG_LOG=Yes 7 | # 8 | # Enable wipping of /tmp (temporary files) 9 | # 10 | WIPE_TMPDIR=Yes 11 | 12 | # 13 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 14 | # 15 | -------------------------------------------------------------------------------- /sv.conf.d/raid: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/raid, 2016/06/06 Exp $ 3 | # 4 | # See dmraid(1) for more information about supported format; 5 | # or else, `dmraid -l'. 6 | # 7 | DMRAID_FORMATS= 8 | 9 | # 10 | # this service need or use dmcrypt? 11 | # 12 | #SVC_USE="dmcrypt" 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv.conf.d/tmpdirs: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/tmpdirs, 2016/06/06 Exp $ 3 | # 4 | # tmpdir maintain a temporary directory hierarchy on a tmpfs or zram 5 | # backed device. Keeping the state of a diretory across machine reboot 6 | # is available & optional, comes with a tarball. 7 | # 8 | 9 | # Enable zram backed device (instead of regular tmpfs) 10 | use_zram=yes 11 | # Root directory of the file system hierachy 12 | tmpdir_root=/var/tmp 13 | 14 | # Set the size to use (tmpfs case) 15 | tmpdir_size=20% 16 | # Colon separated list of directory to archive 17 | tmpdir_saved= 18 | # Colon separated list of direcory (without saved state, backup) 19 | tmpdir_unsaved= 20 | # Set the compressor to use (for state saved directory) 21 | compressor="lz4 -1" 22 | 23 | # 24 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /sv.conf.d/unionfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/unionfs, 2016/06/06 Exp $ 3 | # 4 | 5 | # Squash directory root, where to put the merged hierchy filesystem 6 | unionfs_rootdir=/unionfs 7 | # Filesystem to use for the merged hierachy 8 | # Supported value: aufs, overlay; or else, auto-detected 9 | unionfs_filesystem=overlay 10 | 11 | # System wide squash-ed directory-ies 12 | #unionfs_sysdir="/usr /opt" 13 | 14 | # Local squash-ed directory-ies 15 | unionfs_localdir="/var/db /var/cache/edb" 16 | 17 | # Squashed directory-ies to rebuild before shutting down the service 18 | # WARN: This list should be in either unionfs_sysdir|localdir group 19 | unionfs_rebuilddir= 20 | # 21 | # Full path to sdr script, else default to $(which sdr) 22 | sdr=/usr/sbin/sdr 23 | # Offset to use when rebuilding (in percent) 24 | offset=20 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv.conf.d/zfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/zfs, 2016/06/06 Exp $ 3 | # 4 | # See zfs(8) and zpool(8) for more information. 5 | # 6 | # WARN: when using zfs service, add also zpool service to stage-1! 7 | # 8 | # Extra options to pass to `zfs mount' besides `-a' like `-O' for overlay 9 | #ZFS_MOUNT_ARGS=-O 10 | # 11 | # Extra options to pass to `zfs umount' besides `-a' 12 | #ZFS_UMOUNT_ARGS= 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv.conf.d/zfs-share: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/zfs-share, 2016/06/06 Exp $ 3 | # 4 | # See zfs(8) and zpool(8) for more information. 5 | # 6 | # WARN: when using zfs service, add also zpool service to stage-1! 7 | # 8 | # Extra options to pass to `zfs share' besides `-a' like 9 | #ZFS_SHARE_ARGS= 10 | # 11 | # Extra options to pass to `zfs unshare' besides `-a' like 12 | #ZFS_UMSHARE_ARGS= 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv.conf.d/zpool: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/zpool, 2016/06/06 Exp $ 3 | # 4 | # See zfs(8) and zpool(8) for more information 5 | # 6 | # 7 | # Extra options to pass to `zpool import' besides `-N -a' 8 | #ZPOOL_IMPORT_ARGS= 9 | # 10 | # Extra options to pass to `zpool export' besides `-a' 11 | #ZPOOL_EXPORT_ARGS= 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /sv.conf.d/zramfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.d/zramfs, 2016/06/06 Exp $ 3 | # 4 | 5 | # Set the number of zram devices to use 6 | ZRAM_DEVICE_NUMBER=4 7 | # Set compressor algorithm to use 8 | ZRAM_COMPRESSOR=lz4 9 | # Set the maximum number of streams for (de)compression per device 10 | ZRAM_STREAM_NUMBER=2 11 | 12 | # ZRAM device definition is defined like: 13 | # 14 | # device size should not excede 2xRAM-SIZE to avoid memory waste 15 | # 16 | #ZRAM_DEVICE_0='512M swap' 17 | ZRAM_DEVICE_0='8G btrfs /var/tmp relatime,nodatacow,nospace_cache,nossd 1777' 18 | ZRAM_DEVICE_1='512M btrfs /tmp relatime,nodatacow,nospace_cache,nossd 1777' 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /sv.conf.local.d/qemu-vlan.vnet4: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: /etc/sv.conf.local.d/qemu-vlan.vnet4 Exp $ 3 | # 4 | 5 | QEMU_VLAN_DHCP="dnsmasq" 6 | QEMU_VLAN_VDE="true" 7 | QEMU_VLAN_NUM="4" 8 | 9 | # 10 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 11 | # 12 | -------------------------------------------------------------------------------- /sv.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/sv.init 0 2019/01/31 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | exec >/dev/console 2>&1 8 | 9 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 10 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 11 | SV_SHUTDOWN=/lib/sv/sbin/shutdown 12 | 13 | exec ${SV_INIT_SH} "${@}" 14 | 15 | # 16 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 17 | # 18 | -------------------------------------------------------------------------------- /sv.shutdown: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Id: @(#) /etc/sv.shutdown 0 2019/01/31 21:09:26 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | exec >/dev/console 2>&1 8 | 9 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 10 | SV_INIT_SH=/lib/sv/sh/sv-init.sh 11 | SV_SHUTDOWN=/lib/sv/sbin/shutdown 12 | 13 | exec ${SV_INIT_SH} "${@}" 14 | 15 | # 16 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 17 | # 18 | -------------------------------------------------------------------------------- /sv.vim: -------------------------------------------------------------------------------- 1 | " 2 | " Language: Supervision 3 | " Licence: Distributed under the same terms as Vim itself and/or 2-clause BSD 4 | " 5 | " Syntax highlighting for Supervision Scripts Framework by inheriting sh.vim. 6 | " Requires vim 6.3 or later. 7 | " 8 | 9 | if &compatible || v:version < 603 10 | finish 11 | endif 12 | 13 | if exists("b:current_syntax") 14 | finish 15 | endif 16 | 17 | let is_bash=1 18 | runtime! syntax/sh.vim 19 | unlet b:current_syntax 20 | 21 | syn keyword svKwd begin end error eval_colors info yesno warn SOURCE 22 | syn keyword svKwd env_del env_set env_sv svc_cmd svc_down svc_status 23 | syn keyword svKwd env_rs rs_cmd svc_sig svc_wait svc_zap mountinfo fstabinfo 24 | syn keyword svKwd start start_pre start_post stop stop_pre stop_post restart 25 | syn keyword svKwd log_start_pre log_stop_post ENV_DEL ENV_SET ENV_SVC 26 | syn keyword svKwd checkpath fstabinfo mountinfo waitfile 27 | syn keyword svKwd svc_status_start svc_status_stop svc_status_active svc_status_up 28 | syn keyword svKwd svc_status_down svc_status_exist svc_status_pid 29 | syn keyword svVars LOG_MODE LOG_PROC LOG_SIZE LOG_STAT LOG_PREFIX LOG_PRE_CMD 30 | syn keyword svVars LOG_CMD LOG_OPTS LOG_FIN_CMD LOG_FIN_OPTS LOG_PRE_OPTS 31 | syn keyword svVars LOGDIR LOG_ARGS LOG_STAT LOG_COMP LOG_PREFIX LOG_SIZE 32 | syn keyword svVars SVC_REQUIRED_FILES SVC_TIMEOUT_DOWN SVC_TIMEOUT_UP 33 | syn keyword svVars SVC_DEBUG SVC_CONFIGFILE SVC_CMD SVC_OPTS SVC_GROUP SVC_USER 34 | syn keyword svVars SVC_NEED SVC_USE SVC_BEFORE SVC_AFTER SV_TRY SVC_PROVIDE 35 | syn keyword svVars ENV_DIR ENV_CMD ENV_OPTS PRE_CMD PRE_OPTS FIN_CMD FIN_OPTS 36 | syn keyword svVars CGROUP_CLEANUP CGROUP_INHERIT SV_CGROUP SVC_DEPS SVC_PIDFILE 37 | syn keyword svVars NULL SV_SVCDIR SV_TMPDIR SV_RUNDIR SV_SERVICE SV_OPTS SV_CMD 38 | syn keyword svVars SVC_COMMANDS SVC_STARTED_COMMANDS SVC_STOPPED_COMMANDS 39 | syn keyword svVars RC_OPTS COLOR description __cmd__ __cmd_dir__ __cmd_args__ name 40 | syn keyword svVars SVC_KEYWORD SVC_TIMEOUT SVC_TRY SVC_SYSLOG SVC_SYSLOG_INFO 41 | syn keyword svVars SVC_NICE SVC_CONFIGDIRS SVC_TRACE SVC_INSTANCE SVC_PROVIDER 42 | 43 | syn cluster shCommandSubList add=svKwd 44 | 45 | hi def link svKwd Keyword 46 | hi def link svFunc Special 47 | hi def link svVars PreProc 48 | 49 | let b:current_syntax = "sv" 50 | -------------------------------------------------------------------------------- /sv/DEFAULT: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/DEFAULT Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description='DEFAULT check-point (DUMMY SERVICE)' 8 | SVC_NEED='cron getty.tty1 sshd' 9 | SVC_PROVIDE='DEFAULT' 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/SYSBOOT: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/SYSBOOT Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description='SYSBOOT check-point (DUMMY SERVICE)' 8 | SVC_NEED='dev clock hostname localfs loop-back-device miscfs console net networkfs logger' 9 | SVC_PROVIDE='SYSBBOT' 10 | 11 | start() 12 | { 13 | # 14 | # nth hack to get udev(8) working 15 | # 16 | if [ -e ${SV_RUNDIR}/udev ]; then 17 | sv-run -q udev restart >${NULL} 2>&1 18 | fi 19 | } 20 | 21 | # 22 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 23 | # 24 | -------------------------------------------------------------------------------- /sv/acpid/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/acpid/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CMD=/usr/sbin/acpid 7 | SVC_PIDFILE=/var/run/acpid.pid 8 | SVC_OPTS="--foreground --pidfile ${SVC_PIDFILE}" 9 | SVC_USE=logger 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/acpid/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/acpid/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/alsasound: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/alsasound Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up ALSA sound cards" 8 | description_restore="Restore ALSA mixer settings" 9 | SVC_AFTER="kmod miscfs" 10 | SVC_NEED="localfs" 11 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 12 | SVC_COMMANDS="restore" 13 | SVC_STARTED_COMMANDS="save" 14 | 15 | ALSA_STATEDIR="/var/lib/alsa" 16 | ALSA_SCRDIR="/etc/alsa.d" 17 | ALSA_HOMEDIR="/var/run/alsasound" 18 | alsactl="$(command -v alsactl 2>${NULL})" 19 | 20 | restore() 21 | { 22 | checkpath -q -d -m 0700 ${ALSA_HOMEDIR} || return 23 | if [ ! -r ${ALSA_STATEDIR}/asound.state ]; then 24 | error "No mixer settings found; sound cards should be unmutted" 25 | return 1 26 | fi 27 | 28 | local card cards extra temp 29 | while read card extra; do 30 | case "${card}" in 31 | ([0-9]*) cards="${cards} ${card}";; 32 | esac 33 | done ${temp} 45 | done 46 | return 0 47 | } 48 | 49 | save() 50 | { 51 | mkdir -p ${ALSA_HOMEDIR}/oss 52 | checkpath -q -d -m 0700 ${ALSA_HOMEDIR} || return 53 | if ! ${alsactl} -E HOME="${ALSA_HOMEDIR}" -I -f ${ALSA_STATEDIR}/asound.state \ 54 | store ${card}; then 55 | warn "Failed to store card settings" 56 | return 1 57 | fi 58 | 59 | local card temp 60 | for card in /proc/asound/card*/pcm*/oss; do 61 | [ -e "${card}" ] || continue 62 | temp="${card##/proc/asound/}" 63 | temp="${ALSA_HOMEDIR}/oss/${temp//\//_}" 64 | cat <${card} >${temp} 65 | done 66 | return 0 67 | } 68 | 69 | start() 70 | { 71 | if yesno "${RESTORE_ON_START}"; then 72 | restore 73 | else 74 | return 0 75 | fi 76 | } 77 | 78 | stop() 79 | { 80 | if yesno "${SAVE_ON_STOP}"; then 81 | save 82 | else 83 | return 0 84 | fi 85 | } 86 | 87 | # 88 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 89 | # 90 | -------------------------------------------------------------------------------- /sv/apache2/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/apache2/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/apache2/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/apache2/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/atd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/atd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CMD=/usr/sbin/atd 7 | SVC_OPTS='-f -d' 8 | SVC_USER=at 9 | SVC_GROUP=at 10 | SVC_SPOOLDIR=/var/spool/at 11 | SVC_USE=logger 12 | 13 | start_pre() 14 | { 15 | checkpath -q -d -m 1770 -o ${SVC_USER}:${SVC_GROUP} ${SVC_SPOOLDIR}/atjobs \ 16 | ${SVC_SPOOLDIR}/atspool 17 | } 18 | 19 | # 20 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 21 | # 22 | -------------------------------------------------------------------------------- /sv/atd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/atd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cgred/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cgre/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="CGroup Rules Engine Daemon" 7 | SVC_CMD=/usr/sbin/cgrulesengd 8 | SVC_OPTS='--nodaemon --logfile=-' 9 | SVC_CONFIGFILE=/etc/cgroup/cgconfig.conf 10 | 11 | CGCONFIGPARSER=/usr/sbin/cgconfigparser 12 | CGCLASSIFY=/usr/sbin/cgclassify 13 | CG_CLASSIFY=No 14 | 15 | start_pre() 16 | { 17 | begin "Setting up Control Groups" 18 | ${CGCONFIGPARSER} --load=${SVC_CONFIGFILE} >/dev/null 2>&1 19 | end "${?}" 20 | if ! [ ${?} -eq 0 ]; then 21 | error "Failed to Setup CGroups" 22 | return 1 23 | fi 24 | 25 | # Classify PID according to the rules if requested 26 | yesno "${CG_CLASSIFY}" || return 0 27 | begin "Classifying PID to CGroups" 28 | local pid 29 | for pid in $(ps --no-headers -eL o tid); do 30 | ${CGCLASSIFY} ${pid} 31 | done 32 | end "${?}" 33 | return 0 34 | } 35 | 36 | stop_post() 37 | { 38 | local ctrl eq mnt_pnt mnt_pts=false 39 | while read ctrl eq mnt_pnt; do 40 | case "${ctrl}" in 41 | ('#'*) continue ;; 42 | (mount*) mnt_pts=true ;; 43 | ('}'*) mnt_pts=false;; 44 | (*) 45 | ${mnt_pts} || continue 46 | mnt_pnt="${mnt_pnt%;}" 47 | begin "Unmounting ${mnt_pnt}" 48 | umount "${mnt_pnt}" 49 | end "${?}" 50 | ;; 51 | esac 52 | done <"${SVC_CONFIGFILE}" 53 | } 54 | 55 | # 56 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 57 | # 58 | -------------------------------------------------------------------------------- /sv/cgred/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cgred/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cgred/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cgred/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/checkfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/checkfs 2017/01/12 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: Copyright (c) 2015-2017 tokiclover Exp $ 6 | # $C$: Copyright (c) 2007-2008 Roy Marples Exp $ 7 | # 8 | 9 | description='Check filesystems' 10 | SVC_USE='dev kmod clock device-mapper dmcrypt lvm dmraid mdadm' 11 | SVC_KEYWORD='docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc' 12 | 13 | _abort() 14 | { 15 | local pid pidfile=${SV_TMPDIR}/sv.pid 16 | if [ -e ${pidfile} ]; then 17 | read pid <${pidfile} 18 | kill -USR1 ${pid} || pkill -USR1 -x sv-rc 19 | fi 20 | return 1 21 | } 22 | _forcefsck() 23 | { 24 | [ -e /forcefsck ] || boot_option forcefsck 25 | } 26 | _reboot() 27 | { 28 | [ "${SV_INITLEVEL}" = "${SV_SYSBOOT_LEVEL}" ] && ${SV_LIBDIR}/sbin/reboot "${@}" 29 | } 30 | _shutdown() 31 | { 32 | [ "${SV_INITLEVEL}" = "${SV_SYSBOOT_LEVEL}" ] && ${SV_LIBDIR}/sbin/shutdown "${@}" 33 | } 34 | 35 | start() 36 | { 37 | local exclude_fs fsck_opts fs 38 | 39 | for fs in ${NETWORKFS} ${EXTRA_NETWORKFS}; do 40 | exclude_fs="${exclude_fs},no${fs}" 41 | done 42 | 43 | if [ -e /fastboot ]; then 44 | warn "Skipping filesystems check (enabled by /fastboot)" 45 | rm -f /fastboot 46 | return 0 47 | fi 48 | 49 | if _forcefsck; then 50 | fsck_opts="-f ${fsck_opts}" 51 | rm -f /forcefsck 52 | fi 53 | 54 | if [ "${SV_UNAME}" = Linux ]; then 55 | fsck_opts="${fsck_opts} -C -T -t opts=no_netdev${exclude_fs}" 56 | if echo > /${SVC_NAME}.$$ 2>&1; then 57 | rm /${SVC_NAME}.$$ 58 | fsck_opts="${fsck_opts} -R" 59 | fi 60 | fi 61 | 62 | trap : SIGINT SIGQUIT 63 | fsck ${FSCK_OPTS:--p} ${fsck_opts} 64 | case "${?}" in 65 | (0) return 0;; 66 | (1) warn "Filesystems repaired"; return 0;; 67 | (2|3) 68 | if [ "${SV_UNAME}" = Linux ]; then 69 | error "Filesystems repaired" 70 | warn "System reboot" 71 | _reboot -f 72 | else 73 | error "Filesystems have errors" 74 | error "Mmanual filesystem check required" 75 | _abort 76 | fi 77 | ;; 78 | (4) 79 | if [ "${SV_UNAME}" = Linux ]; then 80 | error "Filesystem errors left uncorrected" 81 | warn "Aborting!!!" 82 | _abort 83 | else 84 | error "Filesystems repaired" 85 | warn "System reboot" 86 | _reboot 87 | fi 88 | ;; 89 | (8) error "Operational error";; 90 | (*) error "Filesystems could not be repaired";; 91 | esac 92 | warn "Aborting!!!" 93 | _abort 94 | } 95 | 96 | stop() 97 | { 98 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 99 | yesno "${CHECKFS_SHUTDOWN}" || return 0 100 | start 101 | } 102 | 103 | # 104 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 105 | # 106 | -------------------------------------------------------------------------------- /sv/console: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/console Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up console (font, keymap, encoding)" 8 | SVC_NEED='localfs' 9 | SVC_AFTER='miscfs' 10 | SVC_KEYWORD='docker lxc openvz prefix supervision systemd-nspawn uml vserver xenu' 11 | 12 | : ${SV_TTY_NUMBER:=12} 13 | : ${SV_TTY_UNICODE:=YES} 14 | : ${consolefont:=${CONSOLEFONT}} 15 | : ${translation:=${TRANSLATION:-${CONSOLE_TRANSLATION}}} 16 | : ${unicodemap:=${UNICODEMAP:-${CONSOLE_UNICODEMAP}}} 17 | : ${keymap:=${KEYMAP:-${CONSOLE_KEYMAP}}} 18 | : ${keymap_extended:=${KEYMAP_EXTENDED:-${CONSOLE_KEYMAP_EXTENDED}}} 19 | : ${keymap_euro:=${KEYMAP_EURO:-${CONSOLE_KEYMAP_EURO}}} 20 | # 21 | # Set up console encoding (ASCII/unicode) 22 | # 23 | console_encoding() 24 | { 25 | local encoding='%@' message=ASCII 26 | 27 | if yesno "${SV_TTY_UNICODE}"; then 28 | encoding='%G' message=unicode 29 | fi 30 | 31 | local i=0 32 | begin "Setting up console encoding (${message})" 33 | while [ "${i}" -lt "${SV_TTY_NUMBER}" ]; do 34 | printf "\033${encoding}" >${TTY}${i} 35 | i=$((${i}+1)) 36 | done 37 | end "${?}" 38 | } 39 | 40 | # 41 | # Set up console font 42 | # 43 | console_font() 44 | { 45 | [ -n "${consolefont}" ] || return 46 | 47 | local i=0 ret=0 48 | begin "Setting up console font (${consolefont})" 49 | while [ "${i}" -lt "${SV_TTY_NUMBER}" ]; do 50 | setfont ${consolefont} -C ${TTY}${i} \ 51 | ${translation:+-m} ${translation} \ 52 | ${unicodemap:+-u} ${unicodemap} \ 53 | >${NULL} 2>&1 || { ret=1; break; } 54 | i=$((${i}+1)) 55 | done 56 | end "${ret}" 57 | } 58 | 59 | # 60 | # Set up console keymap 61 | # 62 | console_keymap() 63 | { 64 | [ -n "${keymap}" ] || return 65 | 66 | # Force linux keycodes for PPC 67 | [ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ] && 68 | echo 1 >/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes 69 | 70 | local encoding='-a' message=ASCII 71 | if yesno "${SV_TTY_UNICODE}"; then 72 | encoding='-u' message=unicode 73 | fi 74 | 75 | local i=0 76 | begin "Setting up keyboard encoding (${message})" 77 | while [ "${i}" -lt "${SV_TTY_NUMBER}" ]; do 78 | kbd_mode ${encoding} -C ${TTY}${i} 79 | i=$((${i}+1)) 80 | done 81 | end "${?}" 82 | 83 | begin "Setting up keymap (${keymap})" 84 | loadkeys -q ${keymap} ${keymap_extended} 85 | end "${?}" || return 86 | 87 | if yesno "${keymap_euro}"; then 88 | echo "altgr keycode 18 = U+20AC" | loadkeys -q - 89 | fi 90 | } 91 | 92 | start() 93 | { 94 | if [ "${SV_TTY_NUMBER}" = 0 ]; then 95 | warn "Skipping console settings (SV_TTY_NUMBER=0)" 96 | return 97 | fi 98 | 99 | local TTY=/dev/tty 100 | [ -d /dev/vc ] && TTY=/dev/vc/ 101 | 102 | console_encoding 103 | console_font 104 | console_keymap 105 | 106 | # 107 | # XXX: save {font+umap,keymap} for early loading 108 | # 109 | if [ -w ${SV_LIBDIR}/cache ]; then 110 | yesno "${SV_TTY_UNICODE}" && echo '' >${SV_LIBDIR}/cache/unicode 111 | setfont -O ${SV_LIBDIR}/cache/font+umap 112 | dumpkeys >${SV_LIBDIR}/cache/keymap 113 | fi 114 | } 115 | 116 | # 117 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 118 | # 119 | -------------------------------------------------------------------------------- /sv/cron/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cron/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | # 6 | # Possible choice: {b,d,f}cron,cronie,vixie-cron 7 | # 8 | name=fcron 9 | SVC_USE=logger 10 | SVC_PROVIDE=cron 11 | 12 | # 13 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 14 | # 15 | -------------------------------------------------------------------------------- /sv/cron/OPTIONS.cronie: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cron/OPTIONS.cronie Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=cronie 7 | SVC_CRONTABS_DIR=/var/spool/anacron 8 | SVC_CMD=/usr/sbin/anacron 9 | SVC_OPTS='-d -s -S ${SVC_CRONTABS_DIR}' 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/cron/OPTIONS.dcron: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cron/OPTIONS.dcron Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=dcron 7 | SVC_CMD=/usr/sbin/crond 8 | SVC_OPTS=-n 9 | 10 | case "${SVC_OPTS}" in 11 | (*-s*) SVC_USE=logger;; 12 | esac 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv/cron/OPTIONS.fcron: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cron/OPTIONS.fcron Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=fcron 7 | SVC_CONFIGFILE=/etc/${name}/${name}.conf 8 | SVC_CRONTABS_DIR=/var/spool/${name} 9 | SVC_CMD=/usr/libexec/${name} 10 | SVC_OPTS="--configfile ${SVC_CONFIGFILE} --foreground" 11 | 12 | case "${SVC_OPTS}" in 13 | (*--nosyslog*) ;; 14 | (*) SVC_USE=logger;; 15 | esac 16 | 17 | start_pre() 18 | { 19 | [ -z "${SVC_LOGFILE}" ] || SVC_OPTS="${SVC_OPTS} --logfilepath ${SVC_LOGFILE}" 20 | } 21 | check_config() 22 | { 23 | [ -d ${SVC_CRONTABS_DIR} ] || ${SVC_CMD} --newspooldir ${SVC_CRONTABS_DIR} 24 | } 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv/cron/OPTIONS.vixie-cron: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cron/OPTIONS.vixie-cron Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Vixie Cron Daemon' 7 | name=vixie-cron 8 | SVC_CMD=/usr/sbin/vixie-cron 9 | SVC_OPTS=-n 10 | case "${SVC_OPTS}" in 11 | (*-s*) SVC_USE=logger;; 12 | esac 13 | 14 | # 15 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 16 | # 17 | -------------------------------------------------------------------------------- /sv/cron/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cron/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cron/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cron/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cups-browsed/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cups-browsed/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Bonjour broadcasts of shared, remote CUPS printers' 7 | SVC_NEED='cupsd' 8 | SVC_CMD='/usr/sbin/cups-browsed' 9 | 10 | # 11 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 12 | # 13 | -------------------------------------------------------------------------------- /sv/cups-browsed/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cups-browsed/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cups-browsed/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cups-browsed/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cupsd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/cupsd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CMD='/usr/sbin/cupsd' 7 | SVC_OPTS='-f' 8 | SVC_NEED='dbus' 9 | SVC_AFTER='logger' 10 | 11 | start_pre() 12 | { 13 | checkpath -q -d -m 0775 -o root:lp /var/cache/cups /var/cache/cups/rss \ 14 | /var/run/cups 15 | checkpath -q -d -m 0511 -o lp:lpadmin /var/run/cups/certs 16 | } 17 | 18 | # 19 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 20 | # 21 | -------------------------------------------------------------------------------- /sv/cupsd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/cupsd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cupsd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/cupsd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dbus/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dbus-daemon/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CMD=/usr/bin/dbus-daemon 7 | SVC_OPTS='--system --nofork' 8 | 9 | SVC_SOCKET=/var/run/dbus/system_bus_socket 10 | 11 | start_pre() 12 | { 13 | [ -d ${SVC_SOCKET%/*} ] || mkdir ${SVC_SOCKET%/*} 14 | dbus-uuidgen --ensure=/etc/machine-id 15 | } 16 | 17 | stop_post() 18 | { 19 | [ -S ${SVC_SOCKET} ] && rm -f ${SVC_SOCKET} 20 | [ -f /var/run/dbus.pid ] && rm -f /var/run/dbus.pid 21 | } 22 | 23 | # 24 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /sv/dbus/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dbus/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/devfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/devfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description='Set up /dev/MISCELLANEOUS filesystems' 8 | SVC_KEYWORD='docker lxc prefix shutdown supervision systemd-nspawn uml vserver xenu' 9 | : ${SYSFS_OPTS:=nodev,nosuid,noexec} 10 | 11 | mount_dev() 12 | { 13 | if grep -q devtmpfs /proc/filesystems; then 14 | fs=devtmpfs 15 | elif grep -q tmpfs /proc/filesystems; then 16 | fs=tmpfs 17 | else 18 | warn "{dev,}tmpfs filesystems are not supported;" 19 | warn "/dev will not be mounted." 20 | return 0 21 | fi 22 | 23 | local sysfs_opts="nosuid,exec,mode=755" 24 | begin "Mounting /dev" 25 | if mountinfo -q /dev; then 26 | mount ${OPT} -o remount,${sysfs_opts} /dev >${NULL} 2>&1 27 | else 28 | fstabinfo --quiet --mount /dev >${NULL} 2>&1 || 29 | mount ${OPT} -t ${fs} -o ${sysfs_opts},size=${DEV_FS_SIZE:-10M} dev /dev >${NULL} 2>&1 30 | fi 31 | end ${?} 32 | } 33 | 34 | seed_dev() 35 | { 36 | # 37 | # Check out/Create some required nodes 38 | # 39 | [ -c /dev/console ] || mknod -m 600 /dev/console c 5 1 40 | [ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0 41 | [ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1 42 | [ -c /dev/null ] || mknod -m 666 /dev/null c 1 3 43 | [ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11 44 | # 45 | # Handle std{out,in,err} (not provided by sysfs) 46 | # 47 | ln -fns /proc/kcore /dev/core 48 | ln -fns /proc/self/fd /dev/fd 49 | ln -fns fd/0 /dev/stdin 50 | ln -fns fd/1 /dev/stdout 51 | ln -fns fd/2 /dev/stderr 52 | } 53 | mount_devfs() 54 | { 55 | for fs in \ 56 | 'mqueue /dev/mqueue 1777 nodev' \ 57 | 'devpts /dev/pts 0755 gid=5,mode=0620' \ 58 | 'tmpfs /dev/shm 1777 nodev,mode=1777' 59 | do 60 | set -- ${fs} 61 | grep -Eq "[[:space:]]${1}$" /proc/filesystems || continue 62 | mountinfo -q ${2} && continue 63 | mkdir -m ${3} -p ${2} >${NULL} 2>&1 || continue 64 | begin "Mounting ${2}" 65 | mount ${OPT} -t ${1} -o noexec,nosuid,${4} ${2##*/} ${2} >${NULL} 2>&1 66 | end ${?} 67 | done 68 | } 69 | 70 | start() 71 | { 72 | local OPT fs 73 | 74 | [ -w /etc/mtab ] || OPT=-n 75 | 76 | mount_dev 77 | mount_devfs 78 | seed_dev 79 | } 80 | 81 | # 82 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 83 | # 84 | -------------------------------------------------------------------------------- /sv/device-mapper: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/device-mapper Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up device-mapper" 8 | SVC_AFTER="dev mdev udev kmod" 9 | SVC_BEFORE="checkfs" 10 | SVC_USE="dmcrypt" 11 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 12 | 13 | dmtab="/etc/dmtab" 14 | dmsetup="$(command -v dmsetup 2>${NULL})" 15 | 16 | volume_entries() 17 | { 18 | [ -f "${dmtab}" ] || return 19 | 20 | local volume options 21 | while read volume options; do 22 | case "${volume}" in 23 | ([a-zA-Z]*) 24 | DM_VOLUME_LIST="${DM_VOLUME_LIST} ${volume%:}" 25 | DM_DEVICE_LIST="${DM_DEVICE_LIST},${volume} ${options}" 26 | ;; 27 | esac 28 | done <${dmtab} 29 | [ -n "${DM_VOLUME_LIST}" ] 30 | } 31 | volume_exists() 32 | { 33 | [ -e /dev/mapper/${1} ] 34 | } 35 | 36 | start_pre() 37 | { 38 | if [ -e /proc/modules ]; then 39 | device_info --all device-mapper || modporbe dm-mod >${NULL} 2>&1 40 | fi 41 | checkpath -q -d -m 0700 -o root:root /run/lvm /run/lock/lvm 42 | 43 | [ -n "${dmsetup}" -a -x "${dmsetup}" ] && 44 | [ -c /dev/mapper/control -a -f ${dmtab} ] && 45 | volume_entries 46 | } 47 | stop_pre() 48 | { 49 | volume_entries 50 | } 51 | 52 | start() 53 | { 54 | [ -d /proc/lvm ] || device_info --all device-mapper || return 55 | 56 | local volume options retval=0 ifs="${IFS}" 57 | local dmsetup_opts=--addnodeoncreate 58 | if [ -e ${SV_RUNDIR}/udev ]; then 59 | udevadm trigger|| UDEV_ARGS=--noudevsync 60 | ENV_SET UDEV_ARGS 61 | dmsetup_opts="${dmsetup_opts} ${UDEV_ARGS}" 62 | fi 63 | 64 | IFS=',' 65 | set -- ${DM_DEVICE_LIST#,} 66 | IFS="${ifs}" 67 | 68 | for volume in "${@}"; do 69 | options="${volume#* }" 70 | volume="${volume%%:*}" 71 | [ -n "${volume}" -a -n "${options}" ] || continue 72 | volume_exists "${volume}" && continue 73 | 74 | begin "Creating ${volume} volume" 75 | ${dmsetup} create "${volume}" ${dmsetup_opts} --table "${options}" 76 | end "${?}" || retval=$((${retval}+1)) 77 | done 78 | return ${retval} 79 | } 80 | 81 | stop() 82 | { 83 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 84 | [ -d /proc/lvm ] || device_info --all device-mapper || return 85 | 86 | local volume retval=0 87 | for volume in ${DM_VOLUME_LIST}; do 88 | volume_exists "${volume}" || continue 89 | begin "Removing ${volume} volume" 90 | ${dmsetup} remove ${UDEV_ARGS} "${volume}" 91 | end "${?}" || retval=$((${retval}+1)) 92 | done 93 | return ${retval} 94 | } 95 | 96 | # 97 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 98 | # 99 | -------------------------------------------------------------------------------- /sv/dhcp/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dhcp/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=dhcpcd 7 | SVC_AFTER='iptables ipt6tables wpa_supplicant wpa_supplicant.wlan0' 8 | SVC_PROVIDE='net' 9 | # 10 | # support instance for interface 11 | # 12 | case "${SVC_NAME}" in 13 | (*.*) DHCP_IFACES="${SVC_NAME#*.}";; 14 | esac 15 | 16 | # 17 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 18 | # 19 | -------------------------------------------------------------------------------- /sv/dhcp/OPTIONS.dhclient: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dhclient/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Dynamic Host Configuration Protocol (DHCP) client' 7 | 8 | name=dhclient 9 | SVC_CONFIGFILE=/etc/dhcp/${name}.conf 10 | SVC_COMMANDS=check_config 11 | SVC_LIBDIR=/var/lib/dhcp 12 | SVC_LOGFILE=${LOGDIR}/${name}.log 13 | SVC_PIDFILE=/var/run/${name}.pid 14 | SVC_CMD=/sbin/dhclient 15 | SVC_OPTS="${DHCP_OPTS} -cf ${SVC_CONFIGFILE} -d -nw -q -lf ${SVC_LIBDIR}/${name}.leases -pf /var/run/${name}.pid ${DHCP_IFACES}" 16 | SVC_USE='logger' 17 | 18 | start_pre() 19 | { 20 | checkpath -q -d -o dhcp:dhcp /var/run/dhcp ${SVC_LIBDIR} \ 21 | ${SVC_LIBDIR}/dhcpd.leases 22 | } 23 | 24 | check_config() 25 | { 26 | if [ ! -f ${SVC_CONFIGFILE} ]; then 27 | error "No config file found." 28 | return 1 29 | fi 30 | if ! eval ${SVC_CMD} ${SVC_OPTS} -t > ${NULL} 2>&1; then 31 | error "Config syntax error." 32 | return 2 33 | fi 34 | } 35 | 36 | # 37 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 38 | # 39 | -------------------------------------------------------------------------------- /sv/dhcp/OPTIONS.dhcpcd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dhcpcd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Full-featured/lightweight Dynamic Host Configuration Protocol (DHCP) client' 7 | name=dhcpcd 8 | SVC_CONFIGFILE=/etc/${name}.conf 9 | SVC_COMMANDS=check_config 10 | SVC_LOGFILE=${LOGDIR}/${name}.log 11 | SVC_CMD=/sbin/dhcpcd 12 | SVC_OPTS="${DHCP_OPTS} --config ${SVC_CONFIGFILE} --quiet --nobackground --denyinterfaces vnet[0-9]_[0-9] ${DHCP_IFACES}" 13 | SVC_USE=logger 14 | 15 | start_pre() 16 | { 17 | [ -z "${SVC_LOGFILE}" ] || DHCP_OPTS="${DHCP_OPTS} --logfile ${SVC_LOGFILE}" 18 | } 19 | 20 | check_config() 21 | { 22 | if [ ! -f ${SVC_CONFIGFILE} ]; then 23 | error "No config file found." 24 | return 1 25 | fi 26 | if ! eval ${SVC_CMD} ${SVC_OPTS} -t >${NULL} 2>&1; then 27 | error "Config syntax error." 28 | return 2 29 | fi 30 | if [ ! -f /etc/${name}.duid ]; then 31 | eval ${SVC_CMD} --duid || { error "ClientID error."; return 3; } 32 | fi 33 | } 34 | 35 | # 36 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 37 | # 38 | -------------------------------------------------------------------------------- /sv/dhcp/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcp/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcp/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcp/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcpd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dhcpcd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Dynamic Host Configuration Protocol (DHCP) server' 7 | 8 | SVC_CONFIGFILE=/etc/dhcp/${name}.conf 9 | SVC_COMMANDS=check_config 10 | SVC_LIBDIR=/var/lib/dhcp 11 | SVC_LOGFILE=${LOGDIR}/${name}.log 12 | SVC_PIDFILE=/var/run/${name}.pid 13 | SVC_CMD=/usr/sbin/dhcpd 14 | SVC_OPTS="${DHCP_OPTS} -cf ${SVC_CONFIGFILE} -d -f -lf ${SVC_LIBDIR}/${name}.leases -pf /var/run/${name}.pid -q -user dhcp -group dhcp ${DHCP_INTERFACES}" 15 | SVC_USE='logger dns' 16 | 17 | start_pre() 18 | { 19 | [ -n "${SVC_LOGFILE}" ] && DHCP_OPTS="${DHCP_OPTS} -tf ${SVC_LOGFILE}" 20 | checkpath -q -d -o dhcp:dhcp /var/run/dhcp ${SVC_LIBDIR} \ 21 | ${SVC_LIBDIR}/dhcpd.leases 22 | } 23 | 24 | check_config() 25 | { 26 | if [ ! -f ${SVC_CONFIGFILE} ]; then 27 | error "No config file found." 28 | return 1 29 | fi 30 | if ! eval ${SVC_CMD} ${SVC_OPTS} -t > ${NULL} 2>&1; then 31 | error "Config syntax error." 32 | return 2 33 | fi 34 | } 35 | 36 | # 37 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 38 | # 39 | -------------------------------------------------------------------------------- /sv/dhcpd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcpd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcpd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcpd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcrelay/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dhcrelay/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Dynamic Host Configuration Protocol (DHCP) relay' 7 | 8 | SVC_CMD='/usr/sbin/dhcrelay' 9 | SVC_PIDFILE=/var/run/${name}.pid 10 | SVC_OPTS="-pf ${SVC_PIDFILE} -d 192.168.0.255" 11 | SVC_USE='logger' 12 | SVC_NEED='net' 13 | 14 | start_pre() 15 | { 16 | # 17 | # XXX: a server IP address shall be appended here to get a functional relay 18 | # 19 | if [ "${SVC_NAME%6}" != "${SVC_NAME}" ]; then 20 | SVC_OPTS="-6 ${SVC_OPTS}" 21 | else 22 | SVC_OPTS="-4 ${SVC_OPTS}" 23 | fi 24 | 25 | local iface 26 | for iface in ${DHCRELAY_INTERFACES}; do 27 | SVC_OPTS="${SVC_OPTS} -i ${iface}" 28 | done 29 | } 30 | 31 | # 32 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 33 | # 34 | -------------------------------------------------------------------------------- /sv/dhcrelay/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dhcrelay/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dmesg: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/dmesg Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: Copyright (c) 2007-2008 Roy Marples Exp $ 6 | # 7 | 8 | description="Set up kernel messages level for printing" 9 | SVC_BEFORE="dev kmod" 10 | SVC_KEYWORD="docker lxc prefix shutdown supervision systemd-nspawn vserver" 11 | 12 | start() 13 | { 14 | [ -n "${DMESG_LEVEL}" ] && dmesg -n${DMESG_LEVEL} 15 | } 16 | 17 | # 18 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 19 | # 20 | -------------------------------------------------------------------------------- /sv/dmeventd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dmeventd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="device-mapper event daemon" 7 | SVC_CMD=/sbin/dmeventd 8 | SVC_OPTS="-f -l" 9 | SVC_AFTER="device-mapper lvm" 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/dmeventd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dmeventd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dmeventd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/dmeventd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dmraid: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/dmraid Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up fake ATA-RAID (dmraid)" 8 | SVC_AFTER="dev mdev udev" 9 | SVC_BEFORE="kmod" 10 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 11 | 12 | dmraid="$(command -v dmraid 2>${NULL})" 13 | 14 | start_pre() 15 | { 16 | [ -n "${dmraid}" -a -x "${dmraid}" -a -n "${DMRAID_FORMATS}" ] 17 | } 18 | 19 | start() 20 | { 21 | # 22 | # Handle Linux fake ATA-RAID 23 | # 24 | local format retval 25 | [ -n "${DMRAID_FORMATS}" ] && 26 | for format in ${DMRAID_FORMATS}; do 27 | begin "Bringing up ${format} ATA-RAID" 28 | ${dmraid} --activate y --ignorelocking --ignoremonitoring ${format} 29 | end "${?}" 30 | retval=$((${retval}+${?})) 31 | done 32 | 33 | return ${retval} 34 | } 35 | 36 | # 37 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 38 | # 39 | -------------------------------------------------------------------------------- /sv/dns/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dns/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=dnsmasq 7 | SVC_NEED=net 8 | 9 | # 10 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 11 | # 12 | -------------------------------------------------------------------------------- /sv/dns/OPTIONS.dnsmasq: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/dnsmasq/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=dnsmasq 7 | SVC_CONFIGFILE=/etc/${name}.conf 8 | SVC_CMD=/usr/sbin/dnsmasq 9 | SVC_PIDFILE=/var/run/${name}.pid 10 | SVC_USER=nobody 11 | SVC_GROUP=nobody 12 | SVC_OPTS="-k ${SVC_USER:+-u} ${SVC_USER} ${SVC_GROUP:+-g} ${SVC_GROUP} --pid-file=${SVC_PIDFILE}" 13 | SVC_USE=logger 14 | 15 | start_pre() 16 | { 17 | checkpath -q -f -m 0644 -o ${name}:${name} /var/lib/misc/${name}.leases 18 | } 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /sv/dns/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/dns/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/docker/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/docker/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_PIDFILE=/run/${SVC_NAME}.pid 7 | SVC_CMD=/usr/bin/dockerd 8 | SVC_OPTS="-p ${SVC_PIDFILE} ${SVC_OPTS}" 9 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 10 | SVC_USER=root 11 | SVC_GROUP=docker 12 | LOG_MODE=0775 13 | 14 | kernel_modules="bridge br_netfilter ip_vs_rr veth vxlan xfrm_algo xfrm_user \ 15 | ipvlan macvlan aufs btrfs dm-thin-pool overlay zfs" 16 | 17 | start_pre() 18 | { 19 | # 20 | # XXX: only load for service ./run (not log/run) 21 | # 22 | if [ -z "${__cmd_dir__}" ]; then 23 | modprobe -aq ${kernel_modules} 24 | fi 25 | # 26 | # XXX: memory protection should be disabled for PaX kernel 27 | # 28 | if yesno "${PAX}" && [ -x /sbin/paxctl ]; then 29 | /sbin/paxctl -m /usr/bin/containerd 30 | /sbin/paxctl -m /usr/bin/containerd-shim 31 | /sbin/paxctl -m /usr/bin/runc 32 | fi 33 | 34 | checkpath -qf -m 0644 -o ${SVC_USER}:${SVC_GROUP} ${SVC_PIDFILE} 35 | ulimit -n 1048576 36 | ulimit -u 1048576 37 | return 0 38 | } 39 | stop_post() 40 | { 41 | # 42 | # XXX: only load for service ./run (not log/run) 43 | # 44 | if [ -z "${__cmd_dir__}" ]; then 45 | modprobe -arq ${kernel_modules} 46 | fi 47 | 48 | rm -f ${SVC_PIDFILE} 49 | } 50 | log_start_pre() 51 | { 52 | start_pre 53 | } 54 | 55 | # 56 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 57 | # 58 | -------------------------------------------------------------------------------- /sv/docker/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/docker/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/docker/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/docker/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/getty.tty1/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/getty.tty1/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/git-daemon/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/git-daemon/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Simple server for Git repositories' 7 | 8 | SVC_CMD=/usr/bin/git 9 | SVC_PIDFILE=/var/run/git-daemon.pid 10 | SVC_USER=nobody 11 | SVC_GROUP=nobody 12 | SVC_OPTS="daemon -e HOME= -e XDG_CONFIG_HOME= -b -m -u ${SVC_USER}:${SVC_GROUP} --pid-file=${SVC_PIDFILE} --verbose" 13 | SVC_USE=logger 14 | 15 | start_pre() 16 | { 17 | sv-run -q syslog status >${NULL} 2>&1 && SVC_OPTS="${SVC_OPTS} --syslog" 18 | } 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /sv/git-daemon/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/git-daemon/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/git-daemon/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/git-daemon/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/gpm/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/gpm/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 7 | SVC_CMD=/usr/sbin/gpm 8 | RC_OPTS=Yes 9 | SVC_OPTS='-D -m ${MOUSEDEV} -t ${MOUSE} 10 | ${RESPONSIVENESS:+-r} ${RESPONSIVENESS} 11 | ${REPEAT_TYPE:+-R} ${REPEAT_TYPE} ${APPEND}' 12 | # 13 | # See gpm(8) man page for more info. 14 | # 15 | : ${MOUSE:=ps2} 16 | : ${MOUSEDEV:=/dev/input/mice} 17 | #: ${REPEAT_TYPE:=raw} 18 | #: ${RESPONSIVENESS:=} 19 | #: ${APPEND:=-g 1 -A60} 20 | # 21 | 22 | start_pre() 23 | { 24 | if [ -z "${MOUSEDEV}" -o -z "${MOUSE}" ]; then 25 | error "MOUSEDEV and MOUSE should be set first" 26 | return 1 27 | fi 28 | } 29 | 30 | # 31 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 32 | # 33 | -------------------------------------------------------------------------------- /sv/gpm/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/gpm/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/gpm/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/gpm/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/hostapd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/hostapd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CONFIGFILE=/etc/hostapd/hostapd.conf 7 | SVC_CMD=/usr/sbin/hostapd 8 | SVC_PIDFILE=/var/run/hostapd.pid 9 | SVC_OPTS="-P ${SVC_PIDFILE} ${SVC_CONFIGFILE}" 10 | SVC_USE=logger 11 | SVC_NEED=net 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /sv/hostapd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/hostapd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/hostapd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/hostapd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/hostname: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/hostname Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up machine hostname" 8 | SVC_KEYWORD="docker lxc prefix shutdown supervision systemd-nspawn" 9 | 10 | start() 11 | { 12 | hostname "${hostname:-${HOSTNAME}}" 13 | } 14 | 15 | # 16 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 17 | # 18 | -------------------------------------------------------------------------------- /sv/httpd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/httpd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Web Server Daemon' 7 | 8 | name=lighttpd 9 | SVC_GROUP=${name} 10 | SVC_USER=${name} 11 | SVC_USE="logger spawn-fcgi.${name} fastcgi.${name} php-fpm" 12 | SVC_NEED=net 13 | SVC_PROVIDE=httpd 14 | 15 | # 16 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 17 | # 18 | -------------------------------------------------------------------------------- /sv/httpd/OPTIONS.busybox-httpd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/httpd/OPTIONS.busybox-httpd Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=httpd 7 | 8 | SVC_CONFIGFILE=/etc/httpd.conf 9 | SVC_CMD=/bin/busybox 10 | SVC_OPTS="${name} -v -f -u ${SVC_USER}:${SVC_GROUP} -c ${SVC_CONFIGFILE} ${HTTP_OPTS}" 11 | 12 | # 13 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 14 | # 15 | -------------------------------------------------------------------------------- /sv/httpd/OPTIONS.lighttpd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/lighttpd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=lighttpd 7 | SVC_USER=lighttpd 8 | SVC_GROUP=lighttpd 9 | SVC_COMMANDS=check_config 10 | SVC_STARTED_COMMANDS=reload 11 | SVC_CONFIGFILE="/etc/${name}/${name}.conf" 12 | SVC_STATEDIR="/var/run/${name}" 13 | SVC_CMD="/usr/sbin/${name}" 14 | SVC_OPTS="-D -f ${SVC_CONFIGFILE}" 15 | SVC_USE="${SVC_USE} slapd" 16 | 17 | start_pre() 18 | { 19 | checkpath -q -d -m 0750 -o "${SVC_USER}:${SVC_GROUP}" "${SVC_STATEDIR}" 20 | } 21 | stop_pre() 22 | { 23 | # 24 | # XXX: send a signal to gracefully stop lighttpd 25 | # 26 | local args 27 | [ -n "${__SIGWDWN__}" ] && args="${__SIGWDWN__/$__SIGSTRT__/$__SIGINT__}" || 28 | args="${__SIGINT__}" 29 | ${__SVCCMD__} ${args} ${SV_RUNDIR}/${SVC_NAME} 30 | } 31 | 32 | check_config() 33 | { 34 | eval ${SVC_CMD} -t -f "${SVC_CONFIGFILE}" 35 | } 36 | reload() 37 | { 38 | svc_sig HUP 39 | } 40 | 41 | # 42 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 43 | # 44 | -------------------------------------------------------------------------------- /sv/httpd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/httpd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/hwclock: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/hwclock 2018/08/20 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: Copyright (c) 2015-2018 tokiclover Exp $ 6 | # $C$: Copyright (c) 2007-2008 Roy Marples Exp $ 7 | # 8 | 9 | description="Set up hardware/system clock" 10 | description_save="Save the current system clock to hardware clock" 11 | description_show="Display the current hardware time" 12 | SVC_BEFORE="*" 13 | SVC_PROVIDE="clock" 14 | SVC_COMMANDS="show" 15 | SVC_STARTED_COMMANDS="save" 16 | SVC_KEYWORD="docker lxc openvz prefix supervision systemd-nspawn uml vserver xenu" 17 | 18 | : $HWCLOCK:=UTC} 19 | if [ "$HWCLOCK}" = "UTC" ]; then 20 | HWCLOCK_MESSAGE="UTC" 21 | HWCLOCK_OPTS="--utc" 22 | else 23 | HWCLOCK_MESSAGE="Local Time" 24 | HWCLOCK_OPTS="--local" 25 | fi 26 | 27 | # 28 | # hwclock doesn't always return non zero on error 29 | # 30 | HWCLOCK() 31 | { 32 | local errors="$(hwclock "${@}" 2>&1 >${NULL})" 33 | 34 | [ -z "${errors}" ] && return 0 35 | echo "${errors}" >&2 36 | return 1 37 | } 38 | 39 | start_pre() 40 | { 41 | case "${SV_UNAME}" in 42 | (s930) HWCLOCK_MESSAGE="s390";; 43 | (*) device_info "cobd" && HWCLOCK_MESSAGE="coLinux";; 44 | esac 45 | case "${HWCLOCK_MESSAGE}" in 46 | (UTC|'Local Time') ;; 47 | (*) HWCLOCK_OPTS=;; 48 | esac 49 | } 50 | 51 | start() 52 | { 53 | if [ -z "${HWCLOCK_OPTS}" ]; then 54 | warn "Not setting up clock for ${HWCLOCK_MESSAGE}" 55 | return 0 56 | fi 57 | 58 | if [ -e /proc/modules ] && ! device_info rtc; then 59 | local rtc mod 60 | for rtc in /dev/rtc /dev/rtc[0-9]*; do 61 | [ -e "${rtc}" ] && break 62 | done 63 | [ -e "${rtc}" ] || 64 | for mod in rtc-cmos rtc genrtc; do 65 | modprobe -q "${mod}" && break 66 | done 67 | fi 68 | 69 | begin "Setting up system clock (${HWCLOCK_MESSAGE})" 70 | HWCLOCK --systz ${HWCLOCK_OPTS} ${HWCLOCK_ARGS} 71 | end "${?}" "Hardware Clock" 72 | 73 | if [ -e /etc/adjtime ] && yesno "$HWCLOCK_ADJTIME}"; then 74 | HWCLOCK --adjust ${HWCLOCK_OPTS} 75 | end "${?}" "Adjust Clock" 76 | fi 77 | if yesno "$HWCLOCK_HCTOSYS}"; then 78 | HWCLOCK --hctosys ${HWCLOCK_OPTS} $HWCLOCK_ARGS} 79 | end "${?}" "System Clock" 80 | fi 81 | return 0 82 | } 83 | 84 | stop() 85 | { 86 | yesno "$HWCLOCK_SYSTOHC}" || return 0 87 | start_pre 88 | [ -n "${HWCLOCK_OPTS}" ] || return 0 89 | 90 | yesno "$HWCLOCK_ADJTIME}" || 91 | if LC_ALL=C hwclock --help 2>&1 | grep -qsw "\-\-noadjfile"; then 92 | HWCLOCK_OPTS="${HWCLOCK_OPTS} --noadjfile" 93 | fi 94 | begin "Setting up hardware clock from system clock (${HWCLOCK_MESSAGE})" 95 | printf "\n\t" 96 | HWCLOCK ${HWCLOCK_OPTS} $HWCLOCK_ARGS} 97 | end "${?}" 98 | return 0 99 | } 100 | 101 | save() 102 | { 103 | CLOCK_SYSTOHC=1 104 | stop 105 | } 106 | 107 | show() 108 | { 109 | start_pre 110 | printf "\n\t" 111 | hwclock --show ${HWCLOCK_OPTS} $HWCLOCK_ARGS} 112 | } 113 | 114 | # 115 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 116 | # 117 | -------------------------------------------------------------------------------- /sv/inetd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/inetd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Internet protocol service daemon - Super-Server' 7 | name=ipsvd 8 | 9 | # 10 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 11 | # 12 | -------------------------------------------------------------------------------- /sv/inetd/OPTIONS.ipsvd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/ipsvd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | case "${SVC_NAME}" in 7 | (*.udpsvd) name=udpsvd SVC_CMD=/usr/bin/udpsvd SVC_OPTS="-i /etc/udpsvd.d";; 8 | (*.tcpsvd) name=tcpsvd SVC_CMD=/usr/bin/tcpsvd SVC_OPTS="-i /etc/tcpsvd.d";; 9 | (*) 10 | error "invalid service name -- ${SVC_NAME}" 11 | error "\`ipsvd.{tc,ud}psvd' instances shall be used instead" 12 | ;; 13 | esac 14 | SVC_USE=net 15 | 16 | # 17 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 18 | # 19 | -------------------------------------------------------------------------------- /sv/inetd/OPTIONS.xinetd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/xinetd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=xinetd 7 | 8 | SVC_STARTED_COMMANDS="check dump reload" 9 | SVC_CONFIGFILE=/etc/xinetd.conf 10 | SVC_CMD=/usr/sbin/xinetd 11 | SVC_PIDFILE=/var/run/${name}.pid 12 | SVC_OPTS="-f ${SVC_CONFIGFILE} -pidfile ${SVC_PIDFILE} -dontfork -stayalive" 13 | SVC_USE=net 14 | 15 | reload() 16 | { 17 | svc_sig HUP 18 | } 19 | dump() 20 | { 21 | svc_sig USR1 22 | } 23 | check() 24 | { 25 | svc_sig IOT 26 | } 27 | 28 | # 29 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 30 | # 31 | -------------------------------------------------------------------------------- /sv/inetd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/inetd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/inetd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/inetd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/initctl/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/initctl/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="SysVinit shutdown/reboot compatibility service" 7 | 8 | # 9 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 10 | # 11 | -------------------------------------------------------------------------------- /sv/initctl/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/initctl/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/ipset: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/ipset Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up IPSet rules" 8 | description_check="Check IP sets rules file" 9 | description_reload="Reload IP sets rules file" 10 | description_save="Save IP sets rules to file" 11 | 12 | SVC_AFTER="kmod" 13 | SVC_BEFORE="iptables ip6tables" 14 | SVC_NEED="localfs" 15 | SVC_COMMANDS="check" 16 | SVC_STARTED_COMMANDS="reload save" 17 | : ${IPSET_RULES_FILE:=/var/lib/ipset/rules-save} 18 | ipset="$(command -v ipset 2>${NULL})" 19 | 20 | check() 21 | { 22 | if [ -f "${IPSET_RULES_FILE}" ]; then 23 | checkpath -qf -m 0600 "${IPSET_RULES_FILE}" 24 | else 25 | error "Create some rules before starting this service" 26 | error "And then run \`sv-run ${SVC_NAME} save' to save the rules" 27 | return 1 28 | fi 29 | } 30 | 31 | start_pre() 32 | { 33 | [ -n "${ipset}" -a -x "${ipset}" ] || 34 | { error "No IPTables binary found"; return 1; } 35 | 36 | local action set type extra modules 37 | [ -f "${IPSET_RULES_FILE}" ] && [ -d /proc/modules ] && 38 | while read action set type extra; do 39 | case "${action}" in 40 | (create) modules="${modules} ip_set_${type/:/_}";; 41 | esac 42 | done <${IPSET_RULES_FILE} 43 | [ -n "${modules}" ] && modprobe -a ${modules} >${NULL} 2>&1 44 | 45 | checkpath -qd "${IPSET_RULES_FILE%/*}" 46 | } 47 | 48 | start() 49 | { 50 | check && ${ipset} restore <"${IPSET_RULES_FILE}" 51 | } 52 | 53 | stop() 54 | { 55 | # 56 | # XXX: Check for IPTables references before anything else; 57 | # if some sets are referenced in IPTables, do nothing. 58 | # 59 | if ! ${ipset} list | gawk ' 60 | ($1 == "References:") { refcount += $2 } 61 | ($1 == "Type:" && $2 == "list:set") { listset = 1 } 62 | (scanlist) { if ($0 != "") setcount++; 63 | else { scanlist = 0; listset = 0 } } 64 | (listset && $1 == "Members:") { scanlist = 1 } 65 | END { exit (refcount - setcount) } 66 | '; then 67 | error "IPSet rules are being used" 68 | return 1 69 | fi 70 | if yesno "${SAVE_ON_STOP}"; then 71 | save || return 1 72 | fi 73 | ${ipset} flush 74 | ${ipset} destroy 75 | } 76 | 77 | reload() 78 | { 79 | svc_status_start || return 80 | # 81 | # XXX: There is no way to reload IP sets if used in IPTables; 82 | # so, remain only trying to swap existant rules if possible 83 | # from temporary sets. 84 | # 85 | local running_sets="$(ipset save | awk '/^create/{ printf "%s|", $2}')" 86 | begin "Reloading IPSets rules" 87 | sed -r "s/^(create|add) (${running_sets%|}) /\1 \2_temp /g" ${IPSET_RULES_FILE} \ 88 | | ${ipset} reload 89 | end "${?}" "IPSets rules" 90 | 91 | local set 92 | for set in ${running_sets//|/ }; do 93 | ${ipset} swap ${set} ${set}_temp || end "${?}" "swap ${set} IP set" 94 | ${ipset} destroy ${set}_temp || end "${?}" "destroy ${set}_temp IP set" 95 | done 96 | } 97 | 98 | save() 99 | { 100 | ${ipset} save >${IPSET_RULES_FILE} 101 | check 102 | } 103 | 104 | # 105 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 106 | # 107 | -------------------------------------------------------------------------------- /sv/iptables: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/iptables Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up IPTables rules" 8 | description_check="Check IPTables rules file" 9 | description_reload="Reload IPTables rules file" 10 | description_save="Save IPTables rules to file" 11 | 12 | SVC_AFTER="kmod ipset" 13 | SVC_BEFORE="net" 14 | SVC_USE="logger" 15 | SVC_NEED="localfs" 16 | SVC_PROVIDE="firewall" 17 | SVC_COMMANDS="check" 18 | SVC_STARTED_COMMANDS="reload save" 19 | 20 | case "${SVC_NAME}" in 21 | (iptables|ip6tables) iptables_name="${SVC_NAME}";; 22 | (*) iptables_name="iptables";; 23 | esac 24 | iptables_bin="$(command -v ${iptables_name} 2>${NULL})" 25 | iptables_file="${IPTABLES_RULES_FILE:=/var/lib/${iptables_name}/rules-save}" 26 | 27 | case "${iptables_name}" in 28 | (iptables) 29 | iptables_mods="iptable_filter iptable_mangle iptable_raw iptable_nat \ 30 | ipt_MASQUERADE ipt_REDIRECT ipt_REJECT" 31 | ;; 32 | (ip6tables) 33 | iptables_mods="ip6table_filter ip6table_mangle ip6table_raw ip6table_nat \ 34 | ip6t_MASQUERADE ip6t_REDIRECT ip6t_REJECT" 35 | ;; 36 | esac 37 | 38 | check() 39 | { 40 | if [ -f "${iptables_file}" ]; then 41 | checkpath -qf -m 0600 "${iptables_file}" 42 | else 43 | error "Create some rules before starting this service" 44 | error "And then run \`sv-run ${SVC_NAME} save' to save the rules" 45 | return 1 46 | fi 47 | ${iptables_bin}-restore --test ${SAVE_RESTORE_OPTIONS} <"${iptables_file}" 48 | } 49 | 50 | start_pre() 51 | { 52 | [ -n "${iptables_bin}" -a -x "${iptables_bin}" ] || 53 | { error "No IPTables binary found"; return 1; } 54 | 55 | if [ -e /proc/modules ]; then 56 | modprobe -a ipt_LOG ${iptables_mods} >${NULL} 2>&1 57 | fi 58 | 59 | if [ ! -d /proc/net/netfilter ]; then 60 | error "Kernel lacks basic IPTables support" 61 | return 1 62 | fi 63 | 64 | checkpath -qd "${iptables_file%/*}" 65 | } 66 | 67 | start() 68 | { 69 | check && ${iptables_bin}-restore ${SAVE_RESTORE_OPTIONS} <"${iptables_file}" 70 | } 71 | 72 | stop() 73 | { 74 | if yesno "${SAVE_ON_STOP}"; then 75 | save || return 1 76 | fi 77 | set_policy ACCEPT 78 | } 79 | 80 | set_policy() 81 | { 82 | local chain policy="${1}" 83 | [ -n "${1}" ] || return 84 | 85 | ${iptables_bin} -w -F 86 | ${iptables_bin} -w -X 87 | 88 | for chain in PREROUTING INPUT FORWARD OUTPUT POSTROUTING; do 89 | ${iptables_bin} -w -P "${chain}" "${policy}" 90 | done 91 | } 92 | 93 | reload() 94 | { 95 | if svc_status_start && check; then 96 | begin "Reloading IP tables rules" 97 | set_policy DROP 98 | start 99 | end "${?}" 100 | fi 101 | } 102 | 103 | save() 104 | { 105 | ${iptables_bin}-save ${SAVE_RESTORE_OPTIONS} >${iptables_file} 106 | checkpath -qf -m 0600 "${iptables_file}" 107 | } 108 | 109 | # 110 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 111 | # 112 | -------------------------------------------------------------------------------- /sv/kmod: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/kmod Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="kernel modules loader" 8 | SVC_AFTER="devfs sysfs dev mdev udev" 9 | SVC_KEYWORD="docker lxc openvz prefix shutdown supervision systemd-nspawn uml vserver" 10 | 11 | start() 12 | { 13 | local mod grp kv_minor kv_major kv_patch kv_modules ifs="${IFS}" 14 | 15 | IFS=".-" 16 | set ${SV_UNAME_RELEASE} 17 | 18 | kv_major="${1}" kv_minor="${2}" kv_patch="${3}" 19 | IFS="${ifs}" 20 | 21 | for grp in "" "_${kv_major}" "_${kv_major}_${kv_minor}" "_${kv_major}_${kv_minor}_${kv_patch}"; do 22 | for mod in $(eval echo "\${modules$grp}"); do 23 | eval modprobe -aq "${mod}" "\${module_${mod//-/_}_options}" 24 | done 25 | done 26 | 27 | # 28 | # Build a space separated list to be able to load everything with a single 29 | # command 30 | # 31 | return 0 32 | } 33 | 34 | # 35 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 36 | # 37 | -------------------------------------------------------------------------------- /sv/kmod-static-nodes: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/kmod-static-nodes Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up static kernel nodes" 8 | SVC_AFTER='devfs' 9 | SVC_BEFORE='dev tmpfiles.dev' 10 | SVC_KEYWORD='docker lxc shutdown supervision systemd-nspawn' 11 | 12 | start() 13 | { 14 | checkpath -qd /run/tmpfiles.d 15 | kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf 16 | } 17 | 18 | # 19 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 20 | # 21 | -------------------------------------------------------------------------------- /sv/libvirtd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/libvirtd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="Virtual Machine Management daemon (libvirt)" 7 | 8 | SVC_PIDFILE="/var/run/libvirtd.pid" 9 | SVC_CMD="/usr/sbin/libvirtd" 10 | SVC_OPTS="${LIBVIRTD_OPTS} --pid-file ${SVC_PIDFILE}" 11 | PRE_CMD="/usr/bin/env" 12 | PRE_OPTS="- KRB5_KTNAME=/etc/libvirt/krb5.tab" 13 | 14 | SVC_NEED="net virtlogd" 15 | SVC_USE="dbus virtlockd" 16 | SVC_AFTER="ntp-client ntp nfs nfsmount portmap rpc.statd iptables ip6tables ebtables corosync sanlock cgred xenconsoled" 17 | 18 | start_pre() 19 | { 20 | checkpath -qd /etc/libvirt/lxc /etc/libvirt/nwfilter /etc/libvirt/qemu \ 21 | /etc/libvirt/storage /var/run/libvirt 22 | } 23 | # 24 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /sv/libvirtd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/libvirtd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/libvirtd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/libvirtd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/local: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/local Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description='Run old-style or simplified local scripts' 8 | SVC_AFTER='*' 9 | SV_LOCALDIR="/usr/local/etc/sv.local.d" 10 | SV_LOCALCONF="/usr/local/etc/sv.local.conf.d" 11 | 12 | exec__cmd__() 13 | { 14 | local x 15 | for x in ${SV_LOCALDIR}/*; do 16 | if [ -x "${x}" ]; then 17 | begin "\tStarting \`${x##*/}'" 18 | (. ${x} "${__cmd__}") 19 | end "${?}" 20 | fi 21 | done 22 | } 23 | start() 24 | { 25 | exec__cmd__ "${__cmd__}" 26 | } 27 | stop() 28 | { 29 | exec__cmd__ "${__cmd__}" 30 | } 31 | 32 | # 33 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 34 | # 35 | -------------------------------------------------------------------------------- /sv/loop-back-device: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/loopback Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up loopback interface" 8 | SVC_KEYWORD="docker jail prefix shutdown supervison systemd-nspawn uml vserver" 9 | 10 | start() 11 | { 12 | if [ "${SV_UNAME}" = "Linux" ]; then 13 | ifconfig lo up >${NULL} 2>&1 && return 14 | else 15 | ifconfig lo0 up >${NULL} 2>&1 && return 16 | fi 17 | if [ "${SV_UNAME}" = "Linux" ]; then 18 | ifconfig lo 127.0.0.1 netmask 255.0.0.0 19 | route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 20 | ifconfig lo up 21 | else 22 | ifconfig lo0 127.0.0.1 netmask 255.0.0.0 23 | route -q add -inet 127.0.0.0 -netmask 255.0.0.0 127.0.0.1 24 | ifconfig lo0 up 25 | fi 26 | } 27 | 28 | # 29 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 30 | # 31 | -------------------------------------------------------------------------------- /sv/lvm: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/lvm Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up LVM2 devices" 8 | SVC_AFTER="dev mdev udev kmod device-mapper lvmetad" 9 | SVC_BEFORE="checkfs" 10 | SVC_USE="lvmetad" 11 | SVC_CONFIGFILE="/etc/lvm/lvm.conf" 12 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 13 | 14 | lvm="$(command -v lvm 2>${NULL})" 15 | 16 | start_pre() 17 | { 18 | if [ -e /proc/modules ]; then 19 | device_info --all device-mapper || modporbe dm-mod >${NULL} 2>&1 20 | fi 21 | checkpath -q -d -m 0700 -o root:root /run/lvm /run/lock/lvm 22 | 23 | if [ -e ${SV_RUNDIR}/udev ]; then 24 | udevadm trigger || UDEV_ARGS=--noudevsync 25 | ENV_SET UDEV_ARGS 26 | fi 27 | 28 | [ -n "${lvm}" -a -x "${lvm}" ] && [ -c /dev/mapper/control -a -f ${SVC_CONFIGFILE} ] 29 | } 30 | 31 | # 32 | # XXX: try to make LVM udev friendly or else LVM will stall waiting for devices 33 | # 34 | LVM_PVSCAN() 35 | { 36 | local num="${1}" pid="$$" 37 | 38 | if [ -z "${UDEV_ARGS}" ]; then 39 | sh -c " 40 | n="${num}"; 41 | while [ "\${n}" -gt 0 ]; do 42 | sleep 1; 43 | if kill -0 "${pid}" 2>${NULL}; then 44 | udevadm trigger; 45 | else 46 | exit 0; 47 | fi; 48 | n="\$\(\(\${n}-1\)\)"; 49 | done; 50 | if kill -0 "${pid}" 2>${NULL}; then 51 | kill -INT "${pid}" 2>${NULL}; 52 | exit 1; 53 | fi; 54 | exit 0; 55 | " & 56 | fi 57 | 58 | ${lvm} pvscan 59 | } 60 | start() 61 | { 62 | [ -d /proc/lvm ] || device_info --all device-mapper || return 63 | 64 | if ! LVM_PVSCAN "${PVSCAN_TIMEOUT:-60}"; then 65 | error "*** Failed to scan devices!!! ***" 66 | return 1 67 | fi 68 | ${lvm} vgscan --mknodes 69 | ${lvm} vgchange ${UDEV_ARGS} --sysinit --activate ly 70 | } 71 | 72 | stop() 73 | { 74 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 75 | [ -d /proc/lvm ] || device_info --all device-mapper || return 76 | ${lvm} lvchange ${UDEV_ARGS} --sysinit --activate ln 77 | ${lvm} vgchange ${UDEV_ARGS} --sysinit --activate ln 78 | } 79 | 80 | # 81 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 82 | # 83 | -------------------------------------------------------------------------------- /sv/lvm-monitor: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/lvm-monitor Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up LVM2 devices monitoring" 8 | SVC_NEED="dmeventd lvm" 9 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 10 | 11 | lvm="$(command -v lvm 2>${NULL})" 12 | 13 | start_pre() 14 | { 15 | vglist="$(${lvm} vgs --noheadings -o name --rows 2>${NULL})" 16 | } 17 | start() 18 | { 19 | if [ -e ${SV_RUNDIR}/udev ]; then 20 | udevadm trigger || UDEV_ARGS=--noudevsync 21 | ENV_SET UDEV_ARGS 22 | fi 23 | 24 | ${lvm} vgchange ${UDEV_ARGS} --monitor y --poll y ${vglist} 25 | } 26 | stop_pre() 27 | { 28 | start_pre 29 | } 30 | stop() 31 | { 32 | ${lvm} vgchange --monitor n ${vglist} 33 | } 34 | 35 | # 36 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 37 | # 38 | -------------------------------------------------------------------------------- /sv/lvmetad/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/lvmetad/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="LVM metadata cache daemon" 7 | SVC_PIDFILE="/run/lvmetad.pid" 8 | SVC_CMD=/sbin/lvmetad 9 | SVC_OPTS="-f -p ${SVC_PIDFILE}" 10 | SVC_AFTER="dev mdev udev" 11 | SVC_BEFORE="lvm" 12 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 13 | 14 | start_pre() 15 | { 16 | checkpath --dir /run/lvm 17 | } 18 | 19 | # 20 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 21 | # 22 | -------------------------------------------------------------------------------- /sv/lvmetad/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/lvmetad/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/lvmetad/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/lvmetad/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/mdadm: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/dmraid Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up software raid (mdadm)" 8 | SVC_AFTER="dev mdev udev" 9 | SVC_BEFORE="kmod" 10 | SVC_CONFIGFILE="/etc/mdadm.conf" 11 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 12 | 13 | mdadm="$(command -v mdadm 2>${NULL})" 14 | 15 | raid_device_entry() 16 | { 17 | [ -s "${SVC_CONFIGFILE}" ] || return 18 | 19 | local prefix volume device 20 | while read prefix volume device; do 21 | case "${prefix}" in 22 | ([Aa][Rr][Rr][Aa][Yy]) 23 | RAID_DEVICE_LIST="${RAID_DEVICE_LIST}\n${volume};${device}\n" 24 | ;; 25 | esac 26 | done <${SVC_CONFIGFILE} 27 | } 28 | 29 | start_pre() 30 | { 31 | [ -n "${mdadm}" -a -x "${mdadm}" -a -f "${SVC_CONFIGFILE}" ] 32 | } 33 | 34 | start() 35 | { 36 | local ifs="${IFS}" device options entry retval=0 37 | raid_device_entry 38 | IFS=' 39 | ' 40 | # 41 | # Handle Linux software RAID 42 | # 43 | #mdadm --assemble --scan 44 | [ -n "${RAID_DEVICE_LIST}" -a -x ${mdadm} ] && 45 | for entry in $(printf ${RAID_DEVICE_LIST}); do 46 | IFS=";${ifs}" 47 | eval set -- ${entry} 48 | device="${1}" options="${2}" 49 | [ -b /dev/${device} ] && continue 50 | case "${options}" in 51 | ([Uu][Uu][Ii][Dd]) ;; 52 | (*) options=;; 53 | esac 54 | 55 | begin "Bringing up ${device} device (software RAID)" 56 | ${mdadm} --assemble ${options:+--uuid} ${options#*=} --config /etc/mdadm.conf ${device} 57 | end "${?}" 58 | retval=$((${retval}+${?})) 59 | done 60 | return ${retval} 61 | } 62 | 63 | # 64 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 65 | # 66 | -------------------------------------------------------------------------------- /sv/mdev: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/mdev Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description='Set up (mdev) device manager' 8 | : ${MDEV_CMD:=/sbin/mdev} 9 | : ${MDEV_LOGFILE:=/run/mdev.log} 10 | SVC_BEFORE="checkfs device-mapper dmcrypt dmraid kmod mdadm lvm lvmetad zfs" 11 | SVC_NEED='devfs sysfs' 12 | SVC_PROVIDE='dev' 13 | SVC_KEYWORD='docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc' 14 | 15 | start() 16 | { 17 | begin "Setting up mdev\n" 18 | if ! [ -x ${MDEV_CMD} ]; then 19 | if type -p busybox >${NULL} 2>&1; then 20 | MDEV_CMD="$(type -p busybox) mdev" 21 | else 22 | end "1" "Failed to setup mdev." 23 | return 1 24 | fi 25 | fi 26 | if mountinfo --quiet /dev; then 27 | mount -o remount,exec,mode=755 /dev 28 | else 29 | mount -t tmpfs -o exec,nosuid,mode=755,size=${DEV_FS_SIZE:-10M} \ 30 | dev /dev >${NULL} 2>&1 || 31 | { end "2" "Failed to setup tmpfs."; return 2; } 32 | fi 33 | if yesno ${MDEV_DEBUG}; then 34 | touch ${MDEV_LOGFILE} 35 | ln -s ${MDEV_LOGFILE} /dev/mdev.log 36 | fi 37 | echo '' >/dev/mdev.seq 38 | echo "${MDEV_CMD}" >/proc/sys/kernel/hotplug 39 | [ -d /lib/mdev/devices ] && cp -RPp /lib/mdev/devices/* /dev 2>${NULL} 40 | # 41 | # Populate /dev 42 | # 43 | ${MDEV_CMD} -s 44 | end ${?} 45 | } 46 | 47 | # 48 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 49 | # 50 | -------------------------------------------------------------------------------- /sv/mtab: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/mtab Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up /etc/mtab" 8 | SVC_NEED='rootfs' 9 | SVC_KEYWORD="docker prefix supervision systemd-nspawn" 10 | 11 | start() 12 | { 13 | [ -e /proc/self/mounts ] || return 0 14 | 15 | if [ -L /etc/mtab ]; then 16 | return 0 17 | elif [ -e /etc/mtab ]; then 18 | warn "using a regular file for /etc/mtab is deprecated" 19 | warn "convert it to a symlink: 'ln -fns /proc/self/mounts /etc/mtab'" 20 | cat /proc/self/mounts >/etc/mtab 21 | else 22 | ln -fns /proc/self/mounts /etc/mtab 23 | fi 24 | } 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv/mysql/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/mysql/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/mysql/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/mysql/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/nagios/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/nagios/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/nagios/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/nagios/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/networkfs: -------------------------------------------------------------------------------- 1 | localfs -------------------------------------------------------------------------------- /sv/nginx: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/nginx Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Robust, small and high performance http and reverse proxy server" 8 | description_configtest="Run nginx' internal config check." 9 | description_upgrade="Upgrade the nginx binary without losing connections." 10 | description_reload="Reload the nginx configuration without losing connections." 11 | 12 | SVC_CONFIGFILE=/etc/nginx/nginx.conf 13 | SVC_COMMANDS=configtest 14 | SVC_STARTED_COMMANDS="reload upgrade" 15 | SVC_OPTS="${SVC_OPTS} -c ${SVC_CONFIGFILE}" 16 | SVC_CMD=/usr/sbin/nginx 17 | SVC_USER=nginx 18 | SVC_GROUP=nginx 19 | SVC_NEED=net 20 | SVC_USE="mysql dns logger networkfs postgresql fastcgi php-fpm" 21 | SVC_AFTER=sshd 22 | SVC_PROVIDE=httpd 23 | SVC_PIDFILE=/run/nginx.pid 24 | 25 | start_pre() 26 | { 27 | if [ "${__cmd__}" != "restart" ]; then 28 | configtest || return 1 29 | fi 30 | } 31 | start_post() 32 | { 33 | svc_wait "${TIMEOUT:-60}" "${SVC_PIDFILE}" 34 | } 35 | 36 | stop_pre() 37 | { 38 | if [ "${__cmd__}" = "restart" ]; then 39 | configtest || return 1 40 | fi 41 | 42 | [ -f ${SVC_PIDFILE} ] && ${SVC_CMD} ${SVC_OPTS} -s stop 43 | } 44 | stop_post() 45 | { 46 | [ -f ${SVC_PIDFILE} ] && pgrep -F ${SVC_PIDFILE} nginx >${NULL} && 47 | ${SVC_CMD} ${SVC_OPTS} -s stop 48 | [ -f ${SVC_PIDFILE} ] && rm ${SVC_PIDFILE} || return 0 49 | } 50 | 51 | reload() 52 | { 53 | configtest || return 1 54 | svc_sig HUP 55 | } 56 | upgrade() 57 | { 58 | configtest || return 1 59 | 60 | info "Sending USR2 to old binary" 61 | svc_sig USR2 62 | sleep 3 63 | 64 | if [ ! -f ${SVC_PIDFILE}.oldbin ]; then 65 | error "File with old pid not found" 66 | return 2 67 | fi 68 | 69 | if [ ! -f ${SVC_PIDFILE} ]; then 70 | error "New binary failed to start" 71 | return 3 72 | fi 73 | 74 | info "Sleeping 3 seconds before WINCH" 75 | sleep 3 ; pkill -WINCH -F ${SVC_PIDFILE}.oldbin 76 | 77 | info "Sending QUIT to old binary" 78 | pkill -QUIT -F ${SVC_PIDFILE}.oldbin 79 | } 80 | 81 | configtest() 82 | { 83 | ${SVC_CMD} -c ${SVC_CONFIGFILE} -t -q || 84 | ${SVC_CMD} -c ${SVC_CONFIGFILE} -t 85 | } 86 | # 87 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 88 | # 89 | -------------------------------------------------------------------------------- /sv/npcd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: /etc/sv/npcd/OPTIONS Exp $ 3 | # $License: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | SVC_CONFIGFILE=/etc/pnp/npcd.cfg 7 | SVC_CMD=/usr/bin/npcd 8 | SVC_OPTS="--config ${SVC_CONFIGFILE}" 9 | SVC_USE="net logger" 10 | SVC_STARTED_COMMANDS=reload 11 | 12 | start_pre() 13 | { 14 | # 15 | # support a faster cache by using a symlink 16 | # 17 | local spooldir=/var/spool/pnp 18 | if [ -L ${spooldir} ]; then 19 | spooldir=$(readlink ${spooldir}) 20 | fi 21 | checkpath -qd -m 775 -o nagios:nagios ${spooldir} /var/tmp/nagios \ 22 | /var/tmp/nagios/pnp 23 | } 24 | reload() 25 | { 26 | svc_sig HUP 27 | } 28 | 29 | # 30 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 31 | # 32 | -------------------------------------------------------------------------------- /sv/npcd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/npcd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/nrpe: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/nrpe Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | SVC_CONFIGFILE=/etc/nagios/nrpe.cfg 8 | SVC_CMD=/usr/libexec/${SVC_NAME} 9 | # 10 | # XXX: fghack does not work here (a dead nrpe instance will remain in the 11 | # foreground) 12 | # 13 | SVC_OPTS="-c ${SVC_CONFIGFILE} --daemon" 14 | 15 | get_config() 16 | { 17 | sed -n -e 's:^[ \t]*'$1'=\([^#]\+\).*:\1:p' ${SVC_CONFIGFILE} 18 | } 19 | 20 | start_pre() 21 | { 22 | SVC_PIDFILE="$(get_config pid_file)" 23 | ENV_SET SVC_PIDFILE 24 | } 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv/ntp/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/ntp/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Network Time Protocol Daemon' 7 | name=busybox-ntpd 8 | SVC_NEED=net 9 | SVC_USE=dns 10 | # 11 | # XXX: not using 'ntp' virtual service? uncomment this! 12 | # 13 | #SVC_PROVIDE=ntp 14 | 15 | # 16 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 17 | # 18 | -------------------------------------------------------------------------------- /sv/ntp/OPTIONS.busybox-ntpd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/busybox-ntpd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | name=busybox-ntpd 6 | SVC_CMD=/bin/busybox 7 | SVC_OPTS='ntpd -n' 8 | 9 | # 10 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 11 | # 12 | -------------------------------------------------------------------------------- /sv/ntp/OPTIONS.ntpd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/ntpd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | name=ntpd 7 | SVC_CONFIGFILE=/etc/${name}.conf 8 | SVC_COMMANDS=check_config 9 | 10 | SVC_CMD=/usr/sbin/ntpd 11 | SVC_PIDFILE=/var/run/${name}.pid 12 | SVC_OPTS="-d -f ${SVC_CONFIGFILE} -p ${SVC_PIDFILE}" 13 | 14 | check_config() 15 | { 16 | eval ${SVC_CMD} -f ${SVC_CONFIGFILE} -n 17 | } 18 | 19 | # 20 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 21 | # 22 | -------------------------------------------------------------------------------- /sv/ntp/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/ntp/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/ntp/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/ntp/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/pcscd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/pcscd Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='PC/SC Smart Card Daemon' 7 | 8 | SVC_CONFIGFILE=/etc/reader.conf.d/reader.conf 9 | SVC_CMD=/usr/sbin/pcscd 10 | SVC_OPTS="--config ${SVC_CONFIGFILE} --foreground" 11 | SVC_AFTER='udev dbus' 12 | SVC_USE=logger 13 | 14 | start_pre() 15 | { 16 | checkpath -q -d -m 0755 -o pcscd:pcscd /run/pcscd 17 | } 18 | 19 | # 20 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 21 | # 22 | -------------------------------------------------------------------------------- /sv/pcscd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/pcscd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/php-fpm/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/php-fpm/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | # 7 | # XXX: to use a differrent version just setup name variable and add a new 8 | # OPTIONS.$name file to reflect the new instance or php version. 9 | # The default is to use php-fpm5.6 10 | # 11 | if [ "${SVC_NAME%.*}" = "${SVC_NAME}" ]; then 12 | name=php-fpm5.6 13 | fi 14 | 15 | SVC_BEFORE="apache2 httpd lighttpd nginx" 16 | SVC_USE=logger 17 | SVC_NEED=net 18 | SVC_CONFIGFILE=/etc/php/fpm-php5.6/php-fpm.conf 19 | SVC_REQUIRED_FILES="/etc/php/fpm-php5.6/php.ini" 20 | SVC_CMD=/usr/bin/php-fpm5.6 21 | # 22 | # XXX: do not expand in case an instance or different php is used 23 | # 24 | SVC_OPTS="--nodaemonize --php-ini ${SVC_CONFIGFILE%/*}/php.ini --fpm-config ${SVC_CONFIGFILE}" 25 | SVC_PIDFILE=/var/run/php-fpm.pid 26 | 27 | start_pre() 28 | { 29 | # 30 | # XXX: check SVC_CONFIGFILE for user:group and socket path 31 | # 32 | checkpath -qd -m 770 -o nobody:nobody /var/run/php-fpm 33 | } 34 | reload() 35 | { 36 | svc_sig HUP || kill -HUP $(cat ${SVC_PIDFILE}) 37 | } 38 | 39 | # 40 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 41 | # 42 | -------------------------------------------------------------------------------- /sv/php-fpm/OPTIONS.php-fpm5.6: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/php-fpm/OPTION.php-fpm5.6 Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CONFIGFILE=/etc/php/fpm-php5.6/php-fpm.conf 7 | SVC_REQUIRED_FILES=/etc/php/fpm-php5.6/php.ini 8 | SVC_CMD=/usr/bin/php-fpm5.6 9 | 10 | # 11 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 12 | # 13 | -------------------------------------------------------------------------------- /sv/php-fpm/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/php-fpm/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/postgresql/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/postgresql/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | # 7 | # XXX: define this variable to select a version and/or instance. 8 | # Default behaviour is to use 9.6 unless an instance is used. 9 | case "${SVC_NAME}" in 10 | (*-[0-9].[0-9]) 11 | name="${SVC_NAME}" 12 | ;; 13 | (*) 14 | name=postgresql-9.6 15 | ;; 16 | esac 17 | 18 | # Which port and socket to bind PostgreSQL 19 | PGPORT="5432" 20 | 21 | # How long to wait for server to start in seconds 22 | START_TIMEOUT=10 23 | STOP_TIMEOUT=60 24 | 25 | # Extra options to run postmaster with, e.g.: 26 | # -N is the maximal number of client connections 27 | # -B is the number of shared buffers and has to be at least 2x the value for -N 28 | # Please read the man-page to postmaster for more options. Many of these 29 | # options can be set directly in the configuration file. 30 | #PGOPTS="-N 512 -B 1024" 31 | 32 | PGDATA="/etc/${name}" 33 | DATA_DIR="/var/lib/postgresql/${name#*-}/data" 34 | 35 | SVC_CONFIGFILE="/etc/${name}/postgresql.conf" 36 | get_config() 37 | { 38 | eval echo $(sed -e 's:#.*::g' ${SVC_CONFIGFILE} | \ 39 | awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }') 40 | } 41 | [ "$(get_config log_destination)" = "syslog" ] && SVC_USE="${SVC_USE} logger" 42 | port=$(get_config port) 43 | : ${port:=${PGPORT}} 44 | socket=$(get_config unix_socket_directories) 45 | : ${socket:=/run/postgresql} 46 | 47 | SVC_STARTED_COMMANDS=reload 48 | SVC_CMD=/usr/lib/${name}/bin/postgres 49 | SVC_USER=postgres 50 | SVC_GROUP=postgres 51 | SVC_REQUIRED_FILES="/etc/${name}/pg_hba.conf /etc/${name}/pg_ident.conf" 52 | SVC_OPTS="-l -D ${PGDATA} ${PGOPTS} -p ${port} -k ${socket} --data-directory=${DATA_DIR} <${NULL}" 53 | SVC_WAIT_DOWN="${STOP_TIMEOUT}" 54 | ENV_CMD="/usr/bin/env" 55 | ENV_OPTS="- PGPORT=${PGPORT} PGDATA=${PGDATA}" 56 | PRE_CMD="setuidgid" 57 | PRE_OPTS="${SVC_USER}" 58 | 59 | SVC_USE="loopback net" 60 | # localfs needed for $DATA_DIR 61 | SVC_NEED=localfs 62 | SVC_PROVIDE=postgresql 63 | 64 | check_config() 65 | { 66 | local f 67 | for f in ${SVC_CONFIGFILE} ${SVC_REQ_FILES}; do 68 | if [ -e ${f} ]; then 69 | checkpath -f -m 600 -o ${SVC_USER}:${SVC_GROUP} ${f} 70 | else 71 | error "${f} not found (HINT: cp ${DATA_DIR%/*}/${f##*/} ${PGDATA})" 72 | return 1 73 | fi 74 | done 75 | for f in ${socket//,/ }; do 76 | checkpath -d -m 1775 -o ${SVC_USER}:${SVC_GROUP} ${f} 77 | f=${f%/*}/.s.PGSQL.${port} 78 | if [ -e ${f} ]; then 79 | error "${f} is already used (HINT: change port number)" 80 | return 1 81 | fi 82 | done 83 | } 84 | 85 | start_pre() 86 | { 87 | check_config 88 | } 89 | 90 | reload() 91 | { 92 | svc_sig HUP || 93 | ${PRE_CMD} ${PRE_OPTS} ${SVC_CMD%/*}/pg_ctl reload -s -D ${PGDATA} 94 | } 95 | 96 | # 97 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 98 | # 99 | -------------------------------------------------------------------------------- /sv/postgresql/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/postgresql/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/postgresql/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/postgresql/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/procfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/procfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: (c) 2015-2016 Exp $ 6 | # $C$: Copyright (c) 2007-2008 Roy Marples Exp $ 7 | # 8 | 9 | description='Set up miscellaneous filesystems' 10 | : ${SYSFS_OPTS:=nodev,nosuid,noexec} 11 | 12 | SVC_NEED='devfs kmod' 13 | SVC_KEYWORD="docker lxc openvz prefix shutdown supervision systemd-nspawn uml vserver" 14 | 15 | mount_binfmt_misc() 16 | { 17 | [ -d /sys/module/binfmt_misc ] || modprobe -q binfmt-misc 18 | grep -Eq "[[:space:]]binfmt_misc$" /proc/filesystems || return 19 | 20 | begin "Mounting binfmt_misc (miscellaneous binary format) filesystem" 21 | mount -t binfmt_misc -o ${SYSFS_OPTS} binfmt_misc /proc/sys/fs/binfmt_misc 22 | end "${?}" 23 | } 24 | 25 | start() 26 | { 27 | if [ ! -e /proc/sys/fs/binfmt_misc/register -a -d /proc/sys/fs/binfmt_misc ]; then 28 | mount_binfmt_misc 29 | fi 30 | return 0 31 | } 32 | 33 | # 34 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 35 | # 36 | -------------------------------------------------------------------------------- /sv/qemu-vlan.vnet4: -------------------------------------------------------------------------------- 1 | qemu-vlan.vnet0 -------------------------------------------------------------------------------- /sv/rdonlyfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/rdonlyfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Mount filesystem read-only" 8 | SVC_AFTER="*" 9 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 10 | 11 | start() 12 | { 13 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 1 14 | sync 15 | 16 | local dir mnt_opts mnt_point 17 | 18 | mnt_point="/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*|/run|/lib.*|/tmp" 19 | umount=$(command -v umount 2>${NULL}) 20 | 21 | for dir in $(mountinfo -P "^(${mnt_point})$" -o rw -N); do 22 | begin "Unmounting ${dir} (read-only)" 23 | ${umount} -n -r ${dir} 2>${NULL} 24 | end "${?}" 25 | done 26 | 27 | sv-shutdown --force --${SV_RUNLEVEL} 28 | } 29 | 30 | # 31 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 32 | # 33 | -------------------------------------------------------------------------------- /sv/rootfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/rootfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Mount root filesystem" 8 | SVC_NEED='checkfs' 9 | SVC_KEYWORD="docker jail lxc openvz prefix supervision systemd-nspawn uml vserver" 10 | 11 | start() 12 | { 13 | local mnt_opts ret 14 | case ",$(fstabinfo -r -o /)," in 15 | (*,ro,*) ;; 16 | (*) 17 | if [ "${SV_UNAME}" = Linux ]; then 18 | mnt_opts='-n -w -o remount' 19 | else 20 | mnt_opts='-u -w' 21 | fi 22 | begin "Mounting root filesystem" 23 | mount ${mnt_opts} / 24 | ret="${?}" 25 | end "${ret}" 26 | ;; 27 | esac 28 | 29 | # 30 | # FIXME: add more insurance? 31 | # 32 | local mnt_dir 33 | for mnt_dir in /run /usr /tmp /var; do 34 | mountinfo --quiet ${mnt_dir} && mnt_opts='--remount' || 35 | mnt_opts='--mount' 36 | fstabinfo --quiet ${mnt_opt} ${mnt_dir} 37 | done 38 | 39 | return ${ret} 40 | } 41 | 42 | # 43 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 44 | # 45 | -------------------------------------------------------------------------------- /sv/rrdcached.nagios: -------------------------------------------------------------------------------- 1 | rrdcached -------------------------------------------------------------------------------- /sv/rrdcached/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/rrdcached/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | # 7 | # XXX: SUPPORT SERVICE INSTANCES (SEE OPTIONS.${SVC_GROUP}) 8 | # 9 | case "${SVC_NAME}" in 10 | (*.*) name="${SVC_NAME#*.}";; 11 | esac 12 | 13 | # 14 | # Setup sane default values 15 | # 16 | SVC_CMD=/usr/bin/rrdcached 17 | SVC_OPTS="" 18 | SVC_USER=nobody 19 | SVC_GROUP=nobody 20 | databasedir=/var/lib/rrdcached/db 21 | journaldir=/var/lib/rrdcached/journal 22 | 23 | # 24 | # Run th daemon as unprivileged user/group 25 | # XXX: base and journal directory should have the appropriate mode! 26 | SVC_OPTS="${SVC_OPTS} -G ${SVC_USER} -U ${SVC_GROUP}" 27 | # 28 | # Use 8 threads for writing files to improve IO performances 29 | SVC_OPTS="${SVC_OPTS} -t8" 30 | # 31 | # Use a unix socket with write access to ${SVC_USER} 32 | SVC_OPTS="${SVC_OPTS} -m 666 -s ${SVC_GROUP} -l unix:/run/${SVC_NAME}.sock" 33 | # 34 | # Use a local address with less privileged operations 35 | SVC_OPTS="${SVC_OPTS} -l -P FLUSH,PENDING,BATCH -l 192.168.0.27:42217" 36 | # 37 | # Use system wide base and journal directory 38 | # (journal directory will improve performance by writing to many files at once) 39 | SVC_OPTS="${SVC_OPTS} -b ${databasedir} -j ${journaldir}" 40 | 41 | description="RRDtool data caching daemon" 42 | SVC_CMD=/usr/bin/rrdcached 43 | SVC_OPTS="${SVC_OPTS} -Og" 44 | SVC_BEFORE="apache2 httpd lighttpd nginx" 45 | SVC_NEED="localfs networkfs net" 46 | SVC_USE="logger" 47 | 48 | start_pre() 49 | { 50 | checkpath -qd -o ${SVC_USER}:${SVC_GROUP} ${databasedir} ${journaldir} 51 | } 52 | 53 | # 54 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 55 | # 56 | 57 | -------------------------------------------------------------------------------- /sv/rrdcached/OPTIONS.nagios: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/rrdcached/OPTIONS.nagios Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | # 7 | # Setup sane default values 8 | # 9 | SVC_OPTS="" 10 | SVC_USER=nagios 11 | SVC_GROUP=nagios 12 | databasedir=/var/${SVC_USER}/perfdata 13 | journaldir=/var/${SVC_USER}/journal 14 | 15 | # 16 | # Run th daemon as unprivileged user/group 17 | # XXX: base and journal directory should have the appropriate mode! 18 | SVC_OPTS="${SVC_OPTS} -G ${SVC_USER} -U ${SVC_USER}" 19 | # 20 | # Use 8 threads for writing files to improve IO performances 21 | SVC_OPTS="${SVC_OPTS} -t8" 22 | # 23 | # Use a unix socket with write access to nobody 24 | SVC_OPTS="${SVC_OPTS} -m 660 -s ${SVC_GROUP} -l unix:/run/${SVC_NAME}.sock" 25 | # 26 | # Use a local address with less privileged operations 27 | SVC_OPTS="${SVC_OPTS} -l 127.0.0.1:42217" 28 | # 29 | # Use system wide base and journal directory 30 | # (journal directory will improve performance by writing to many files at once) 31 | SVC_OPTS="${SVC_OPTS} -b ${databasedir} -j ${journaldir}" 32 | 33 | SVC_OPTS="${SVC_OPTS} -Og" 34 | SVC_BEFORE="${SVC_BEFORE} nagios" 35 | 36 | start_pre() 37 | { 38 | checkpath -qd -o ${SVC_USER}:${SVC_GROUP} ${databasedir} ${journaldir} 39 | } 40 | 41 | # 42 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 43 | # 44 | 45 | -------------------------------------------------------------------------------- /sv/rrdcached/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/rrdcached/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/rrdcached/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/rrdcached/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/rsync-daemon/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/rsync-daemon/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Simple (anonymous) rsync daemon' 7 | SVC_CONFIGFILE=/etc/rsyncd.conf 8 | SVC_CMD=/usr/bin/rsync 9 | SVC_USER=nobody 10 | SVC_GROUP=nobody 11 | SVC_OPTS="${RSYNC_OPTS} --config=${SVC_CONFIGFILE} --daemon --no-detach" 12 | SVC_USE=net 13 | 14 | #RSYNC_OPTS='--log-file=${LOGDIR}/${SVC_NAME}.log --verbose' 15 | 16 | # 17 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 18 | # 19 | -------------------------------------------------------------------------------- /sv/rsync-daemon/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/rsync-daemon/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/rsync-daemon/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/rsync-daemon/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/saned/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/saned Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Scanner Access Now Easy daemon' 7 | 8 | ENV_DIR=Yes 9 | SVC_CMD=/usr/sbin/saned 10 | SVC_OPTS='-d 2' 11 | SVC_USER=saned 12 | SVC_GROUP=saned 13 | SVC_CONFIGFILE=/etc/sane.d/saned.conf 14 | SANE_CONFIG_DIR=/etc/sane.d 15 | 16 | start_pre() 17 | { 18 | checkpath -q -d -m 0775 -o ${SVC_USER}:${SVC_GROUP} /var/run/saned 19 | } 20 | 21 | # 22 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 23 | # 24 | -------------------------------------------------------------------------------- /sv/saned/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/saned/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/saned/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/saned/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmpd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/snmpd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | # Initial (empty) options. 7 | SVC_PIDFILE="/var/run/snmpd.pid" 8 | SVC_OPTS="-p ${SVC_PIDFILE}" 9 | 10 | # Disable smux by default 11 | SVC_OPTS="${SVC_OPTS} -I -smux" 12 | 13 | # Enable connection logging. 14 | #SVC_OPTS="${SVC_OPTS} -a" 15 | 16 | # Enable syslog and disable file log. 17 | # where facility is: 'd' = LOG_DAEMON, 'u' = LOG_USER, [0-7] = LOG_LOCAL[0-7] 18 | #SVC_OPTS="${SVC_OPTS} -Lsd -Lf /dev/null" 19 | #SVC_NEED=logger 20 | 21 | # log messages to specified file 22 | #SVC_OPTS="${SVC_OPTS} -A -Lf /var/log/snmptrapd.log" 23 | 24 | # or use supervision log facilty instead 25 | # where 'e' is stderr and 'o' stdout 26 | SVC_OPTS="${SVC_OPTS} -Le" 27 | # Enable agentx socket as /var/agentx/master 28 | # *NOTE* Before uncommenting this, make sure 29 | # the /var/agentx directory exists. 30 | #SVC_OPTS="${SVC_OPTS} -x /var/agentx/master" 31 | 32 | # run snmpd with lesser privilege 33 | SVC_OPTS="${SVC_OPTS} -u nobody -g nobody" 34 | 35 | description='Simple Network Management Protocol Daemon' 36 | 37 | SVC_CONFIGFILE=/etc/snmp/snmpd.conf 38 | SVC_CMD=/usr/sbin/snmpd 39 | SVC_OPTS="-f ${SVC_OPTS}" 40 | SVC_BEFORE="apache2 httpd lighttpd nginx" 41 | 42 | # 43 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 44 | # 45 | -------------------------------------------------------------------------------- /sv/snmpd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmpd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmpd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmpd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmptrapd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/snmptrapd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | # Initial (empty) options. 7 | SVC_PIDFILE="/var/run/snmptrapd.pid" 8 | SVC_OPTS="-p ${SVC_PIDFILE}" 9 | 10 | # ignore authentication failure traps 11 | SVC_OPTS="${SVC_OPTS} -a" 12 | 13 | # log messages to specified file 14 | #SVC_OPTS="${SVC_OPTS} -A -Lf /var/log/snmptrapd.log" 15 | 16 | # log messages to syslog with the specified facility 17 | # where facility is: 'd' = LOG_DAEMON, 'u' = LOG_USER, [0-7] = LOG_LOCAL[0-7] 18 | #SVC_OPTS="${SVC_OPTS} -Ls d" 19 | #SVC_NEED=logger 20 | 21 | # or use supervision log facilty instead 22 | # where 'e' is stderr and 'o' stdout 23 | SVC_OPTS="${SVC_OPTS} -Le" 24 | 25 | # connect to agentx address instead of /var/agentx/master 26 | SVC_OPTS="${SVC_OPTS} -x tcp:127.0.0.0:161" 27 | 28 | # setup address to listen to TRAP/INFORM messages (default to tcp:127.0.0.1:162) 29 | #SNMPTRAPD_ADDRESS=tcp:192.168.0.10 30 | 31 | description='Log Simple Network Management Protocol trap messages' 32 | 33 | SVC_CONFIGFILE=/etc/snmp/snmptrapd.conf 34 | #: ${SNMPTRAPD_ADDRESS:=tcp:127.0.0.1:162} 35 | 36 | SVC_CMD=/usr/sbin/snmptrapd 37 | SVC_OPTS="-f ${SVC_OPTS} ${SNMPTRAPD_ADDRESS}" 38 | SVC_BEFORE="apache2 httpd lighttpd nginx" 39 | 40 | # 41 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 42 | # 43 | -------------------------------------------------------------------------------- /sv/snmptrapd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmptrapd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmptrapd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/snmptrapd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/socklog-inet: -------------------------------------------------------------------------------- 1 | syslog -------------------------------------------------------------------------------- /sv/socklog-ucspi: -------------------------------------------------------------------------------- 1 | syslog -------------------------------------------------------------------------------- /sv/socklog-unix: -------------------------------------------------------------------------------- 1 | syslog -------------------------------------------------------------------------------- /sv/spawn-fcgi.lighttpd: -------------------------------------------------------------------------------- 1 | spawn-fcgi.nginx -------------------------------------------------------------------------------- /sv/spawn-fcgi.nginx/OPTIONS.lighttpd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/spawn-fcgi/OPTIONS.lighttpd Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | # 7 | # The FCGI process can be made available through a filesystem socket or 8 | # through a inet socket. One and only one of the two types must be choosen. 9 | # Default is the inet socket. 10 | # 11 | # Leave empty to use an IP socket (default). See below. Enabling this, 12 | # disables the IP socket. 13 | # 14 | FCGI_SOCKET= 15 | 16 | # When using FCGI_PORT, connections will only be accepted from the following 17 | # address. The default is 127.0.0.1. Use 0.0.0.0 to bind to all addresses. 18 | # 19 | FCGI_ADDRESS=127.0.0.1 20 | 21 | # The port specified by FCGI_PORT is the port used 22 | # by the first child process. If this is set to 1234 then subsequent child 23 | # processes will use 1235, 1236, etc. 24 | # 25 | FCGI_PORT=8004 26 | 27 | # The number of child processes to spawn. The default is 1. 28 | # XXX: This is only used when using multiwatch(1) to supervise children! 29 | # 30 | FCGI_CHILDREN=2 31 | # 32 | # XXX: Alternatively, if using fcgiwrap(1), uncommenting the newt line will 33 | # enable to start the children instead. 34 | #FCGI_OPTIONS="${FCGI_OPTIONS} -c ${FCGI_CHILDREN}" 35 | 36 | # The path to your FastCGI application. These sometimes carry the .fcgi 37 | # extension but not always. For PHP, you should usually point this to 38 | # /usr/bin/php-cgi. 39 | # 40 | #FCGI_PROGRAM=/usr/bin/php-cgi 41 | FCGI_PROGRAM=/usr/bin/fcgi-cgi 42 | #FCGI_PROGRAM=/usr/sbin/fcgiwrap 43 | # 44 | # If multiwatch is used to supervice CGI children uncomment the following: 45 | FCGI_PROGRAM="/usr/bin/multiwatch -f ${FCGI_CHILDREN} -- ${FCGI_PROGRAM}" 46 | 47 | # If you want to run your application inside a chroot then specify the 48 | # directory here. Leave this blank otherwise. 49 | # 50 | FCGI_CHROOT= 51 | 52 | # If you want to run your application from a specific directiory specify 53 | # it here. Leave this blank otherwise. 54 | # 55 | FCGI_CHDIR= 56 | 57 | # The user and group to run your application as. If you do not specify these, 58 | # the application will be run as root:root. 59 | # 60 | #FCGI_USER=lighttpd 61 | #FCGI_GROUP=lighttpd 62 | 63 | # If your application requires additional environment variables, you may 64 | # specify them here. See PHP example below. 65 | # 66 | ALLOWED_ENV="PATH" 67 | 68 | # PHP ONLY :: These two options are specific to PHP. The first is the number 69 | # of child processes to spawn. The second is the number of requests to be 70 | # served by a single PHP process before it is restarted. 71 | # 72 | #PHP_FCGI_CHILDREN=5 73 | #PHP_FCGI_MAX_REQUESTS=500 74 | # 75 | # For this to work you would set 76 | # ALLOWED_ENV="${ALLOWED_ENV} PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS" 77 | 78 | # 79 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 80 | # 81 | -------------------------------------------------------------------------------- /sv/spawn-fcgi.nginx/OPTIONS.nginx: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/spawn-fcgi/OPTIONS.nginx Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | # 7 | # The FCGI process can be made available through a filesystem socket or 8 | # through a inet socket. One and only one of the two types must be choosen. 9 | # Default is the inet socket. 10 | # 11 | # Leave empty to use an IP socket (default). See below. Enabling this, 12 | # disables the IP socket. 13 | # 14 | FCGI_SOCKET= 15 | 16 | # When using FCGI_PORT, connections will only be accepted from the following 17 | # address. The default is 127.0.0.1. Use 0.0.0.0 to bind to all addresses. 18 | # 19 | FCGI_ADDRESS=127.0.0.1 20 | 21 | # The port specified by FCGI_PORT is the port used 22 | # by the first child process. If this is set to 1234 then subsequent child 23 | # processes will use 1235, 1236, etc. 24 | # 25 | FCGI_PORT=8002 26 | 27 | # The number of child processes to spawn. The default is 1. 28 | # XXX: This is only used when using multiwatch(1) to supervise children! 29 | # 30 | FCGI_CHILDREN=2 31 | # 32 | # XXX: Alternatively, if using fcgiwrap(1), uncommenting the newt line will 33 | # enable to start the children instead. 34 | #FCGI_OPTIONS="${FCGI_OPTIONS} -c ${FCGI_CHILDREN}" 35 | 36 | # The path to your FastCGI application. These sometimes carry the .fcgi 37 | # extension but not always. For PHP, you should usually point this to 38 | # /usr/bin/php-cgi. 39 | # 40 | #FCGI_PROGRAM=/usr/bin/php-cgi 41 | #FCGI_PROGRAM=/usr/bin/fcgi-cgi 42 | FCGI_PROGRAM=/usr/sbin/fcgiwrap 43 | # 44 | # If multiwatch is used to supervice CGI children uncomment the following: 45 | FCGI_PROGRAM="/usr/bin/multiwatch -f ${FCGI_CHILDREN} -- ${FCGI_PROGRAM}" 46 | 47 | # If you want to run your application inside a chroot then specify the 48 | # directory here. Leave this blank otherwise. 49 | # 50 | FCGI_CHROOT= 51 | 52 | # If you want to run your application from a specific directiory specify 53 | # it here. Leave this blank otherwise. 54 | # 55 | FCGI_CHDIR= 56 | 57 | # The user and group to run your application as. If you do not specify these, 58 | # the application will be run as root:root. 59 | # 60 | #FCGI_USER=nginx 61 | #FCGI_GROUP=nginx 62 | 63 | # If your application requires additional environment variables, you may 64 | # specify them here. See PHP example below. 65 | # 66 | ALLOWED_ENV="PATH" 67 | 68 | # PHP ONLY :: These two options are specific to PHP. The first is the number 69 | # of child processes to spawn. The second is the number of requests to be 70 | # served by a single PHP process before it is restarted. 71 | # 72 | #PHP_FCGI_CHILDREN=5 73 | #PHP_FCGI_MAX_REQUESTS=500 74 | # 75 | # For this to work you would set 76 | # ALLOWED_ENV="${ALLOWED_ENV} PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS" 77 | 78 | # 79 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 80 | # 81 | -------------------------------------------------------------------------------- /sv/spawn-fcgi.nginx/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/spawn-fcgi.nginx/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/sshd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/sshd Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SSH_CONFDIR=/etc/ssh 7 | SVC_CONFIGFILE=${SSH_CONFDIR}/sshd_config 8 | SVC_CMD=/usr/sbin/sshd 9 | SVC_OPTS='${SSHD_OPTS} -D -f "${SVC_CONFIGFILE}"' 10 | SVC_USE='logger dns' 11 | SVC_COMMANDS=check_config 12 | 13 | start_pre() 14 | { 15 | [ -z "${SVC_LOGFILE}" ] || SVC_OPTS="${SVC_OPTS} -E ${SVC_LOGFILE}" 16 | } 17 | 18 | check_config() 19 | { 20 | ssh-keygen -A || return 2 21 | [ -f "${SVC_CONFIGFILE}" ] || return 1 22 | eval ${SVC_CMD} -t ${SVC_OPTS} || return 3 23 | } 24 | 25 | # 26 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 27 | # 28 | -------------------------------------------------------------------------------- /sv/sshd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/sshd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/sulogin/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/sulogin Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | : ${SULOGIN_TTY:=/dev/tty8} 7 | SVC_CMD=/sbin/sulogin 8 | SVC_OPTS="-p ${SULOGIN_TTY}" 9 | PRE_CMD=/usr/bin/setsid 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/sulogin/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/sulogin/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/swaps: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/swaps Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: Copyright (c) 2007-2008 Roy Marples Exp $ 6 | # 7 | 8 | description="Set up swap(file)s" 9 | SVC_KEYWORD="docker jail lxc openvz prefix supervision systemd-nspawn uml vserver" 10 | if [ "${SVC_NAME}" = swapfiles ]; then 11 | SVC_AFTER='localfs' 12 | fi 13 | 14 | start() 15 | { 16 | local swap_opts 17 | if [ "${SV_UNAME}" = Linux ]; then 18 | swap_opts='-e' 19 | fi 20 | case "${SV_UNAME}" in 21 | (OpenBSD|NetBSD) swapctl -A -t noblk >${NULL} 2>&1;; 22 | (*) swapon -a ${swap_opts} >${NULL} 2>&1;; 23 | esac 24 | } 25 | stop() 26 | { 27 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 28 | case "${SV_UNAME}" in 29 | (OpenBSD|NetBSD) swapctl -U -t noblk >${NULL} 2>&1;; 30 | (*) swapoff -a >${NULL} 2>&1;; 31 | esac 32 | } 33 | 34 | # 35 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 36 | # 37 | -------------------------------------------------------------------------------- /sv/sysctl: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/sysctl Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | SVC_BEFORE="miscfs logger" 8 | SVC_KEYWORD="docker prefix shutdown supervision systemd-nspawn vserver" 9 | SVC_CONFIGFILE="/etc/sysctl.conf" 10 | #SVC_CONFIGDIRS="/etc/sysctl.d" 11 | 12 | OpenBSD_start() 13 | { 14 | local v x z 15 | for x in ${SVC_CONFIGFILE} ${SVC_CONFIGDIRS}/*.conf; do 16 | [ -r ${x} ] || continue 17 | begin "Applying \`${x}' configuration file" 18 | while read v z; do 19 | case "${v}" in 20 | ([a-zA-Z]*) sysctl -q "${v}";; 21 | esac 22 | done <${x} 23 | end "${?}" 24 | done 25 | } 26 | FreeBSD_start() 27 | { 28 | local v x z 29 | for x in ${SVC_CONFIGFILE} ${SVC_CONFIGDIRS}/*.conf; do 30 | [ -r ${x} ] || continue 31 | begin "Applying \`${x}' configuration file" 32 | sysctl -q -f ${x} 33 | end "${?}" 34 | done 35 | } 36 | NetBSD_start() 37 | { 38 | FreeBSD_start 39 | } 40 | DragonFly_start() 41 | { 42 | OpenBSD_start 43 | } 44 | Linux_start() 45 | { 46 | sysctl --quiet --system 47 | } 48 | 49 | start() 50 | { 51 | if command -v ${SV_UNAME/\//_}_start >${NULL} 2>&1; then 52 | ${SV_UNAME/\//_}_start 53 | else 54 | error "There is nothing to do for this ${SV_NAME} OS!!!" 55 | error "Define a \`${SV_UNAME/\//_}_start ' function for this OS!" 56 | return 1 57 | fi 58 | } 59 | 60 | # 61 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 62 | # 63 | -------------------------------------------------------------------------------- /sv/sysfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/sysfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | : ${__CGROUP_ROOT__:=/sys/fs/cgroup} 8 | : ${SYSFS_OPTS:=nodev,nosuid,noexec} 9 | 10 | description='Set up /sys/MISCELLANEOUS filesystems' 11 | SVC_STARTED_COMMANDS=mount_cgroup 12 | SVC_KEYWORD="docker lxc prefix supervision systemd-nspawn uml vserver" 13 | 14 | mount_cgroup() 15 | { 16 | cgroup_start_sys 17 | } 18 | mount_sys() 19 | { 20 | mountinfo --quiet /sys && return 0 21 | grep -Eq "[[:space:]]sysfs$" /proc/filesystems || return 1 22 | 23 | if ! mkdir -m 0755 -p /sys; then 24 | warn "Cannot create /sys" 25 | return 2 26 | fi 27 | begin "Mounting /sys" 28 | if mountinfo --quiet /sys; then 29 | mount ${arg} -o remount,${SYSFS_OPTS} /sys >${NULL} 2>&1 30 | else 31 | fstabinfo --quiet --mount /sys || 32 | mount ${arg} -t sysfs -o ${SYSFS_OPTS} sys /sys >${NULL} 2>&1 33 | fi 34 | end "${?}" 35 | } 36 | 37 | mount_sysfs() 38 | { 39 | for fs in \ 40 | '/sys/kernel/config configfs' \ 41 | '/sys/kernel/debug debugfs' \ 42 | '/sys/firmware/efi/efivars efivars' \ 43 | '/sys/fs/fuse/connections fusectl' \ 44 | '/sys/kernel/security securityfs' 45 | do 46 | set -- ${fs} 47 | [ -d ${1} ] && grep -q ${2} /proc/filesystems || continue 48 | mountinfo --quiet ${1} && continue 49 | begin "Mounting ${1}" 50 | mount ${arg} -t ${2} -o ${SYSFS_OPTS} ${2} ${1} >${NULL} 2>&1 51 | end ${?} 52 | done 53 | } 54 | 55 | start() 56 | { 57 | local arg fs ret 58 | [ -w /etc/mtab ] || arg=-n 59 | 60 | mount_sys 61 | mount_sysfs 62 | ret="${?}" 63 | if mount_cgroup; then 64 | SV_CGROUP=ENABLE 65 | ENV_SVC SV_CGROUP 66 | fi 67 | return ${ret} 68 | } 69 | 70 | # 71 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 72 | # 73 | -------------------------------------------------------------------------------- /sv/syslog/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/syslog/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | SVC_USE='clock' 7 | SVC_NEED='hostname' 8 | SVC_PROVIDE='logger' 9 | # 10 | # Set a default system logger {syslog-ng,socklog,rsyslog} 11 | # or... default to socklog 12 | # 13 | #name=syslog-ng 14 | if [ "${SVC_NAME%-*}" = "socklog" ]; then 15 | name=socklog 16 | fi 17 | 18 | # 19 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 20 | # 21 | -------------------------------------------------------------------------------- /sv/syslog/OPTIONS.rsyslog: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/rsyslog/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | description="Rocket-fast system log precessing daemon" 7 | name=rsyslog 8 | 9 | SVC_CONFIGFILE="/etc/${name}.conf" 10 | SVC_PIDFILE="/var/run/${name}.pid" 11 | SVC_CMD="/usr/sbin/rsyslogd" 12 | SVC_OPTS="-f ${SVC_CONFIGFILE} -n ${RSL_OPTS} -i ${SVC_PIDFILE}" 13 | SVC_USE=net 14 | RSL_LEVEL= 15 | 16 | check_config() 17 | { 18 | eval ${SVC_CMD} -f "${SVC_CONFIGFILE}" -N ${RSL_LEVEL:-1} 19 | } 20 | 21 | # 22 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 23 | # 24 | -------------------------------------------------------------------------------- /sv/syslog/OPTIONS.socklog: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/socklog/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | name=socklog 7 | 8 | SVC_CMD=/usr/sbin/socklog 9 | if [ "${SVC_NAME}" = "syslog" -o "${SVC_NAME}" = "socklog" -o "${SVC_NAME}" = "socklog-unix" ]; then 10 | SVC_PROVIDE=logger 11 | else 12 | SVC_PROVIDE= 13 | fi 14 | 15 | start_pre() 16 | { 17 | case "${SVC_NAME}" in 18 | (*-inet) 19 | : ${PORT:=514} 20 | : ${IP:=0} 21 | [ "${PORT}" -le 1024 -a ! "${SVC_USER}" != "root" ] && 22 | { error "Super-User priviledge required"; return 1; } 23 | : ${SVC_OPTS:=inet ${IP}:${PORT}} 24 | : ${SOCK_LOGDIR:=/var/log/socklog-inet} 25 | ;; 26 | (*-ucspi) 27 | : ${SVC_OPTS:=ucspi ${UCSPI_OPTS}} 28 | : ${SOCK_LOGDIR:=/var/log/socklog-ucspi-tcp} 29 | ;; 30 | (*-unix|*) 31 | : ${SVC_OPTS:=unix /dev/log} 32 | : ${SOCK_LOGDIR:=/var/log/socklog} 33 | ;; 34 | esac 35 | 36 | if [ -n "${SVC_USER}" ]; then 37 | checkpath -q -d -o ${SVC_USER}${SVC_GROUP:+:$SVC_GROUP} ${SOCK_LOGDIR} 38 | else 39 | return 0 40 | fi 41 | } 42 | 43 | # 44 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 45 | # 46 | -------------------------------------------------------------------------------- /sv/syslog/OPTIONS.syslog-ng: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/syslog-ng/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD Exp $ 4 | # 5 | 6 | name=syslog-ng 7 | 8 | SVC_CONFIGFILE="/etc/${name}/${name}.conf" 9 | SVC_STATEFILE_DIR="/var/lib/${name}" 10 | SVC_STATEFILE="${SVC_STATEFILE_DIR}/${name}.persist" 11 | 12 | SVC_CMD="/usr/sbin/${name}" 13 | SVC_PIDFILE="/var/run/${name}.pid" 14 | SVC_OPTS="--cfgfile ${SVC_CONFIGFILE} --foreground --persist-file ${SVC_STATEFILE} --pidfile ${SVC_PIDFILE}" 15 | SVC_STARTED_COMMANDS=reload 16 | 17 | start_pre() 18 | { 19 | if [ -n "${SVC_USER}" ]; then 20 | checkpath -q -d -m 0700 -o "${SVC_USER}${SVC_GROUP:+:$SVC_GROUP}" \ 21 | "${SVC_STATEFILE_DIR}" 22 | else 23 | return 0; 24 | fi 25 | } 26 | 27 | check_config() 28 | { 29 | eval ${SVC_CMD} --syntax-only --cfgfile "${SVC_CONFIGFILE}" 30 | } 31 | 32 | reload() 33 | { 34 | svc_sig HUP 35 | } 36 | 37 | # 38 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 39 | # 40 | -------------------------------------------------------------------------------- /sv/syslog/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/syslog/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/syslog/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/syslog/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/tmpdirs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/tmpdirs 0.22.0 2016/06/06 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: (c) 2012-2016 tokiclover Exp $ 6 | # 7 | 8 | description="Set up temporary directories/filesystems (with optional backup)" 9 | description_restore="Restore temporary directories" 10 | description_save="Archive temporary directories" 11 | SVC_COMMANDS="restore" 12 | SVC_STARTED_COMMANDS="save" 13 | 14 | : ${compressor:=lz4 -1} 15 | : ${extension:=.tar.${compressor%% *}} 16 | mount="$(command -v mount 2>${NULL})" 17 | umount="$(command -v umount 2>${NULL})" 18 | 19 | if yesno ${use_zram}; then 20 | SVC_NEED=zramfs 21 | fi 22 | SVC_BEFORE=logger 23 | 24 | start() 25 | { 26 | local DIR IFS=":${IFS}" dir 27 | 28 | for dir in ${tmpdir_saved} ${tmpdir_unsaved}; do 29 | DIR="${tmpdir_root}${dir}" 30 | mountinfo --quiet "${DIR}" && continue 31 | mkdir -p "${DIR}" 32 | begin "Mounting ${DIR}" 33 | ${mount} --bind "${DIR}" "${dir}" >${NULL} 2>&1 34 | end "${?}" 35 | done 36 | restore 37 | return 0 38 | } 39 | 40 | stop() 41 | { 42 | save 43 | local IFS=":${IFS}" dir 44 | for dir in ${tmpdir_saved} ${tmpdir_unsaved}; do 45 | case "${dir}" in 46 | (*/log|*/run|*/tmp) continue;; 47 | esac 48 | mountinfo --quiet "${dir}" || continue 49 | begin "Unmounting ${dir}" 50 | ${umount} -l "${dir}" >${NULL} 2>&1 51 | end "${?}" 52 | done 53 | return 0 54 | } 55 | 56 | start_pre() 57 | { 58 | local IFS=":${IFS}" ret 59 | for dir in ${tmpdir_saved}; do 60 | [ -e "${dir}${extension}" ] && continue 61 | [ -d "${dir}" ] && save "${dir}" || mkdir -p "${dir}" 62 | done 63 | 64 | mountinfo --quiet "${tmpdir_root}" && return 65 | yesno ${use_zram} && warn "No suitable (zram) root-dir found" 66 | mkdir -p "${tmpdir_root}" 67 | 68 | begin "Mounting ${tmpdir_root}" 69 | ${mount} -o rw,nodev,relatime,mode=0755,size=${tmpdir_size:-20%} \ 70 | -t tmpfs tmp "${tmpdir_root}" || { end 1; return 2; } 71 | end "${?}" 72 | } 73 | 74 | restart() 75 | { 76 | start 77 | } 78 | 79 | restore() 80 | { 81 | local IFS=":${IFS}" decompress swd tarball 82 | decompress="${compressor%% *}" swd="${PWD}" 83 | 84 | for dir in ${@:-${tmpdir_saved}}; do 85 | cd "${dir%/*}" >${NULL} 2>&1 || continue 86 | 87 | if [ -f "${dir}${extension}" ]; then 88 | : tarball="${dir}${extension}" 89 | elif [ -f "${dir}.old${extension}" ]; then 90 | : tarball="${dir}.old${extension}" 91 | else 92 | warn "No tarball found for ${dir}" 93 | continue 94 | fi 95 | begin "Restoring ${dir}" 96 | tar -xpf "${tarball}" -I "${compressor}" 97 | end "${?}" 98 | done 99 | cd "${swd}" >${NULL} 2>&1 100 | } 101 | 102 | save() 103 | { 104 | local IFS=":${IFS}" swd="${PWD}" 105 | 106 | for dir in ${@:-${tmpdir_saved}}; do 107 | cd "${dir%/*}" >${NULL} 2>&1 || continue 108 | if [ -f "${dir}${extension}" ]; then 109 | mv -f "${dir}${extension}" "${dir}.old${extension}" 110 | fi 111 | begin "Saving ${dir}" 112 | tar -cpf "${dir}${extension}" -I "${compressor}" ${dir##*/} 113 | end "${?}" 114 | done 115 | cd "${swd}" >${NULL} 2>&1 116 | } 117 | 118 | # 119 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 120 | # 121 | -------------------------------------------------------------------------------- /sv/tmpfiles.dev: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/tmpfiles.dev Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up tmpfiles.d entries" 8 | 9 | if [ "${SVC_NAME}" = tmpfiles.dev ]; then 10 | SVC_OPTS='--prefix=/dev' 11 | SVC_USE=devfs 12 | SVC_BEFORE=dev 13 | SVC_OPTS='--prefix=/dev' 14 | SVC_KEYWORD="docker prefix vserver" 15 | else 16 | SVC_OPTS='--exclude-prefix=/dev --remove' 17 | SVC_NEED=localfs 18 | fi 19 | 20 | start() 21 | { 22 | ${SV_LIBDIR}/sh/tmpfiles --create --boot ${SVC_OPTS} 23 | return 0 24 | } 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv/tmpfiles.setup: -------------------------------------------------------------------------------- 1 | tmpfiles.dev -------------------------------------------------------------------------------- /sv/udev-monitor/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/udev-monitor/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | SVC_CMD=/sbin/udevadm 7 | SVC_OPTS='monitor >/tmp/udevmonitor.log 2>&1' 8 | SVC_NEED='udev' 9 | SVC_KEYWORD="lxc supervision vserver" 10 | 11 | # 12 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 13 | # 14 | -------------------------------------------------------------------------------- /sv/udev-monitor/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/udev-monitor/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/udev/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/udev/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/urandom: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/urandom 2019/03/16 Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # $C$: Copyright (c) 2015-2019 tokiclover Exp $ 6 | # 7 | 8 | 9 | : ${URANDOM_SEED:=/var/lib/misc/random-seed} 10 | description="Random generator initialization" 11 | 12 | SVC_AFTER="clock" 13 | SVC_NEED="localmount" 14 | SVC_KEYWORD="docker jail lxc openvz prefix supervision systemd-nspawn" 15 | 16 | save_seed() 17 | { 18 | local psiz=1 19 | 20 | if [ -e /proc/sys/kernel/random/poolsize ]; then 21 | read psiz ${NULL};) 26 | } 27 | 28 | start() 29 | { 30 | [ -c /dev/urandom ] || return 31 | if [ -r "${URANDOM_SEED}" ]; then 32 | cat ${URANDOM_SEED} >/dev/urandom 33 | fi 34 | stop 35 | } 36 | 37 | stop() 38 | { 39 | save_seed 40 | } 41 | 42 | # 43 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 44 | # 45 | -------------------------------------------------------------------------------- /sv/virtlockd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/virtlockd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="libvirt virtual machine lock manager" 7 | SVC_PIDFILE="/var/run/virtlockd.pid" 8 | SVC_CMD="/usr/sbin/virtlockd" 9 | SVC_OPTS="--pid-file ${SVC_PIDFILE}" 10 | SVC_CONFIGFILE="/etc/libvirt/virtlockd.conf" 11 | SVC_STARTED_COMMANDS="reload" 12 | description_reload="reload the daemon, while maintaining locks and clients" 13 | SVC_AFTER="ntp-client ntp nfs nfsmount corosync" 14 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 15 | 16 | reload() 17 | { 18 | svc_sig SIGUSR1 19 | } 20 | 21 | # 22 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 23 | # 24 | -------------------------------------------------------------------------------- /sv/virtlockd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlockd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlockd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlockd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlogd/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/virtlogd/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description="libvirt virtual machine logging manager" 7 | SVC_PIDFILE="/var/run/virtlogd.pid" 8 | SVC_CMD=/usr/sbin/virtlogd 9 | SVC_OPTS="--pid-file ${SVC_PIDFILE}" 10 | SVC_STARTED_COMMANDS="reload" 11 | description_reload="reload the daemon, while maintaining open connections" 12 | SVC_AFTER="ntp-client ntp nfs nfsmount corosync" 13 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 14 | 15 | reload() 16 | { 17 | svc_sig SIGUSR1 18 | } 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /sv/virtlogd/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlogd/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlogd/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/virtlogd/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/vmware: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/vmware Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | SVC_NEED=localfs 8 | SVC_USE=net 9 | SVC_KEYWORD="docker jail openvz prefix systemd-nspawn timeout uml vserver xenu lxc" 10 | vmware_modules="vmw_vsock_vmci_transport vmmon vsock vmblock vmnet vmxnet3 \ 11 | vmwgfx vmw_pvscsi vmw_balloon i2c-piix4 virtio_balloon mptspi e1000 e1000e" 12 | 13 | start() 14 | { 15 | begin "Starting VMware USB Arbitrator" 16 | /opt/vmware/bin/vmware-usbarbitrator 17 | end "$?" 18 | begin "Starting VMware services" 19 | modprobe -q vmci 2>${NULL} || modprobe -q vmw_vmci 20 | end "$?" "vmci" 21 | modprobe -a ${vmware_modules} 2>${NULL} 22 | end "$?" "kernel modules" 23 | /opt/vmware/bin/vmware-networks --start 24 | end "$?" "network" 25 | } 26 | 27 | stop() 28 | { 29 | begin "Stopping VMware USB Arbitrator" 30 | killall --wait /opt/vmware/bin/vmware-usbarbitrator 31 | end "$?" 32 | /opt/vmware/bin/vmware-networks --stop 33 | end "$?" "network" 34 | begin "Stopping VMware services" 35 | modprobe -ra ${vmware_modules} 36 | end "$?" 37 | modprobe -rq vmci 2>${NULL} || modprobe -rq vmw_vmci 38 | end "$?" "vmci" 39 | } 40 | 41 | # 42 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 43 | # 44 | -------------------------------------------------------------------------------- /sv/wpa_supplicant/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/wpa_supplicant/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='Wi-Fi Protected Access client and IEEE 802.1X supplicant' 7 | # 8 | # support instance for interface 9 | # 10 | SVC_BEFORE='dhcp net' 11 | SVC_KEYWORD="shutdown" 12 | 13 | case "${SVC_NAME}" in 14 | (*.*) 15 | WPA_IFACE="${SVC_NAME#*.}" 16 | SVC_BEFORE="${SVC_BEFORE} net.${WPA_IFACE} dhcp.${WPA_IFACE}" 17 | ;; 18 | esac 19 | 20 | name=wpa_supplicant 21 | SVC_CONFIGFILE=/etc/${name}/${name}.conf 22 | SVC_PIDFILE=/var/run/${name}.pid 23 | SVC_CMD=/usr/sbin/wpa_supplicant 24 | SVC_OPTS="${WPA_OPTS} -c ${SVC_CONFIGFILE} ${WPA_IFACE:+-i} -P ${SVC_PIDFILE} ${WPA_IFACE}" 25 | case "${SVC_OPTS}" in 26 | (*-s*) SVC_USE=logger;; 27 | esac 28 | 29 | start_pre() 30 | { 31 | [ -n "${WPA_IFACE}" ] || find_iface 32 | } 33 | 34 | find_iface() 35 | { 36 | local iface 37 | if [ "${SV_UNAME}" = "Linux" ]; then 38 | for iface in /sys/class/net/*; do 39 | [ -e "${iface}"/wireless -o -e "${iface}"/phy80211 ] && 40 | WPA_IFACE="${WPA_IFACE} -i ${iface##*/}" 41 | done 42 | else 43 | for iface in /dev/net/* $(ifconfig -s | tail -n+2 | awk '{print $1}' 2>${NULL}); do 44 | ifconfig ${iface} 2>${NULL} | grep -iq '*ssid' && 45 | WPA_IF="${WPA_IFACE} -i ${iface##*/}" 46 | done 47 | fi 48 | [ -n "${WPA_IFACE}" ] 49 | } 50 | 51 | # 52 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 53 | # 54 | -------------------------------------------------------------------------------- /sv/wpa_supplicant/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/wpa_supplicant/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/wpa_supplicant/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/wpa_supplicant/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/xdm/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/xdm/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | # Setup a particular display manager and virtual terminal 7 | name="xdm" 8 | CHECKVT="7" 9 | description="Set up display manager" 10 | 11 | # 12 | # XXX: WARN: 13 | # * should start after getty otherwise xdm would start on VT-2, and 14 | # * then getty would grab keyboard input causing a "dead" keyboard; 15 | # * {autofs,ypbind} for network authentication; 16 | # * lirc to be able to use lirc mouse as input device; 17 | # * console (display corruption, keymaps issues); 18 | # * gdm-3 need dbus; 19 | # * quota for a readable home; 20 | # 21 | SVC_AFTER="console getty.tty1 getty.tty2 getty.tty3 getty.tty4 getty.tty5 getty.tty6 gpm openvpn" 22 | SVC_BEFORE="alsasound" 23 | SVC_USE="autofs consolekit dbus lircmd quota ybind xfs" 24 | SVC_CMD="/usr/bin/xdm" 25 | SVC_OPTS="-nodaemon" 26 | 27 | case "${name}" in 28 | (gdm) SVC_NEED="dbus";; 29 | (lightdm) 30 | PRE_CMD="fghack" 31 | ;; 32 | (entrance|slim) 33 | SVC_OPTS= 34 | ;; 35 | esac 36 | 37 | checkvt() 38 | { 39 | if [ -d "${SV_RUNDIR}/getty.tty1" ]; then 40 | [ -d "${SV_RUNDIR}/getty.tty${1}" ] 41 | elif [ -f /etc/inittab ]; then 42 | grep -Eq "^c${1}:.* tty${1} " /etc/inittab 43 | elif [ -f /etc/ttys ]; then 44 | grep -q "^ttyv$((${1}-1)) " /etc/ttys 45 | else 46 | return 1 47 | fi 48 | } 49 | 50 | start_pre() 51 | { 52 | case "${name}" in 53 | (entrance|kdm|gdm|wdm|gpe-dm|lxdm|lightdm|sddm|slim|xdm) 54 | ;; 55 | (*) 56 | error "Unsupported display manager" 57 | return 1 58 | ;; 59 | esac 60 | : ${SVC_CMD:=$(command -v "${name:-xdm}" 2>${NULL})} 61 | 62 | if yesno "${CHECKVT:+1}"; then 63 | if checkvt "${CHECKVT}"; then 64 | error "Something is already using ${CHECKVT} virtual terminal" 65 | return 1 66 | fi 67 | fi 68 | [ -n "${SVC_CMD}" ] && [ ! -f /etc/.noxdm ] 69 | } 70 | 71 | # 72 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 73 | # 74 | -------------------------------------------------------------------------------- /sv/xdm/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/xdm/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/xdm/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/xdm/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/zed/OPTIONS: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: @(#) /etc/sv/zed/OPTIONS Exp $ 3 | # $L$: 2-clause/new/simplified BSD License Exp $ 4 | # 5 | 6 | description='ZFS Event Daemon' 7 | SVC_PIDFILE=/var/run/zed.pid 8 | SVC_AFTER='localfs' 9 | SVC_NEED='zfs' 10 | SVC_CMD=/sbin/zed 11 | SVC_OPTS="-F -p ${SVC_PIDFILE}" 12 | 13 | # 14 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 15 | # 16 | -------------------------------------------------------------------------------- /sv/zed/finish: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/zed/log/finish: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/zed/log/run: -------------------------------------------------------------------------------- 1 | ../../../lib/sh/run -------------------------------------------------------------------------------- /sv/zed/run: -------------------------------------------------------------------------------- 1 | ../../lib/sh/run -------------------------------------------------------------------------------- /sv/zfs: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/zfs Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up zpools and zfs volumes" 8 | SVC_AFTER="checkfs dev mdev udev" 9 | SVC_BEFORE="logger" 10 | SVC_NEED="zpool" 11 | SVC_KEYWORD="docker lxc openvz supervision prefix systemd-nspawn uml vserver" 12 | 13 | if mountinfo -q -t zfs /; then 14 | SVC_BEFORE="${SVC_BEFORE} localfs rootfs" 15 | else 16 | SVC_AFTER="${SVC_AFTER} localfs rootfs" 17 | SVC_NEED="${SVC_NEED} mtab" 18 | fi 19 | 20 | zfs="$(command -v zfs 2>${NULL})" 21 | 22 | start() 23 | { 24 | local zfs_opts 25 | ${zfs} mount -a ${ZFS_MOUNT_ARGS} 26 | } 27 | 28 | stop() 29 | { 30 | [ "${SV_INITLEVEL}" = "${SV_SHUTDOWN_LEVEL}" ] || return 31 | local zfs_opts 32 | ${zfs} umount -a ${zfs_opts} ${ZPOOL_EXPORT_ARGS} 33 | } 34 | 35 | # 36 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 37 | # 38 | -------------------------------------------------------------------------------- /sv/zfs-share: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/zfs-share Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up network share zfs volumes" 8 | SVC_AFTER="localfs networkfs zed" 9 | SVC_NEED="net zfs" 10 | SVC_KEYWORD="docker lxc openvz prefix supervision systemd-nspawn uml vserver" 11 | 12 | zfs="$(command -v zfs 2>${NULL})" 13 | 14 | start() 15 | { 16 | local zfs_opts 17 | ${zfs} share -a ${ZFS_SHARE_ARGS} 18 | } 19 | 20 | stop() 21 | { 22 | local zfs_opts 23 | ${zfs} unshare -a ${zfs_opts} ${ZPOOL_UNSHARE_ARGS} 24 | } 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /sv/zpool: -------------------------------------------------------------------------------- 1 | #!/sbin/sv-run 2 | # 3 | # $Id: @(#) /etc/sv/zpool Exp $ 4 | # $L$: 2-clause/new/simplified BSD License Exp $ 5 | # 6 | 7 | description="Set up and import zpools" 8 | SVC_BEFORE="checkfs" 9 | SVC_USE="dmcrypt" 10 | SVC_KEYWORD="docker lxc openvz supervision prefix systemd-nspawn uml vserver" 11 | 12 | zpool="$(command -v zpool 2>${NULL})" 13 | : ${ZPOOL_CACHE:=/etc/zfs/zpool.cache} 14 | 15 | start_pre() 16 | { 17 | if ! device_info zfs; then 18 | if [ -e /proc/modules ]; then 19 | modprobe zfs 2>${NULL} 20 | device_info zfs || 21 | { error "No ZFS kernel support or modules found"; return 1; } 22 | else 23 | error "No ZFS support found for this kernel" 24 | error "No kernel modules loading support" 25 | return 1 26 | fi 27 | fi 28 | } 29 | 30 | start() 31 | { 32 | local zpool_opts zfs_opts 33 | if [ -f "${ZPOOL_CACHE}" ]; then 34 | zpool_opts="${zpool_opts} -c ${ZPOOL_CACHE}" 35 | fi 36 | ${zpool} import -N -a ${zpool_opts} ${ZPOOL_IMPORT_ARGS} 37 | } 38 | 39 | stop() 40 | { 41 | local zpool_opts 42 | ${zpool} export -a ${zpool_opts} ${ZFS_UMOUNT_ARGS} 43 | } 44 | 45 | # 46 | # vim:fenc=utf-8:ft=sv:ci:pi:sts=0:sw=4:ts=4: 47 | # 48 | -------------------------------------------------------------------------------- /t/README.md: -------------------------------------------------------------------------------- 1 | Some of theses test, but t0000-basic.sh, shall be run as super user; and then, 2 | in GIT_DIR directory because a no priviledged user cannot start/stop services. 3 | -------------------------------------------------------------------------------- /t/t0000-functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SV_LIBDIR=lib 4 | : ${SVC_NAME:=atd} 5 | . $SV_LIBDIR/sh/runscript-functions 6 | 7 | svc_status -f 8 | retval="$?" 9 | echo "retval=$retval" 10 | if [ "$retval" = "0" ]; then 11 | svc_status --del -f 12 | svc_status -f 13 | retval="$?" 14 | echo "retval=$retval" 15 | fi 16 | svc_status -s 17 | retval="$?" 18 | echo "retval=$retval" 19 | if [ "$retval" = "0" ]; then 20 | svc_status --del -s 21 | svc_status -s 22 | retval="$?" 23 | echo "retval=$retval" 24 | fi 25 | svc_status -d 26 | retval="$?" 27 | if [ "$retval" = "0" ]; then 28 | svc_status --del -d 29 | svc_status -d 30 | retval="$?" 31 | echo "retval=$retval" 32 | fi 33 | svc_status -p 34 | retval="$?" 35 | echo "retval=$retval" 36 | retval="$?" 37 | svc_status -w 38 | echo "retval=$retval" 39 | 40 | 41 | -------------------------------------------------------------------------------- /t/t0000-service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ln -fs src/sv-run lib/sbin/service 4 | lib/sbin/service sysfs status 5 | sv/sysfs start 6 | sv/atd/run status 7 | 8 | printf "bogus usage\n" 9 | src/sv-run stage 10 | printf "\n" 11 | 12 | ln -fs sv-run src/sv-rc 13 | src/sv-rc --default status 14 | -------------------------------------------------------------------------------- /t/t0000-shutdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | [ -x src/sv-shutdown ] || exit 4 | src/sv-shutdown 5 | [ -L src/halt ] || ln -s sv-shutdown src/halt || exit 6 | src/halt -c 7 | [ -L src/reboot ] || ln -s sv-shutdown src/reboot || exit 8 | src/reboot -m 'test this and that' 'to see wht happen' 9 | [ -L src/shutdown ] || ln -s sv-shutdown src/shutdown || exit 10 | src/shutdown -m 'test this and that' 'to see wht happen' 11 | -------------------------------------------------------------------------------- /t/t0000-utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -n "${ZSH_VERSION}" ]; then 4 | emulate sh 5 | NULLCMD=: 6 | setopt NO_GLOB_SUBST SH_WORD_SPLIT 7 | disable -r end 8 | fi 9 | 10 | name="${0##*/}" 11 | SV_LIBDIR=lib 12 | [ -L src/checkpath ] || ln -s ../src/checkpath $SV_LIBDIR/bin 13 | [ -L src/fstabinfo ] || ln -s ../src/fstabinfo $SV_LIBDIR/bin 14 | [ -L src/mountinfo ] || ln -s ../src/mountinfo $SV_LIBDIR/bin 15 | SV_LIBDIR=$SV_LIBDIR . $SV_LIBDIR/sh/runscript-functions 16 | 17 | if yesno Enable; then 18 | eval_colors 256 19 | printf "$color_bld${bg_8}$name$color_rst$color_ita${color_fg_18}test$color_rst\n" 20 | fi 21 | 22 | begin "making /tmp/$name.XXXXXX" 23 | testdir="$(checkpath -d -m0700 -p /tmp $name.XXXXXXX)" 24 | end "$?" 25 | checkpath -d -m0770 -g cdrom $testdir && 26 | ls -d -l $testdir && 27 | rmdir $testdir 28 | 29 | device_info -a rtc && info "rtc device found" || warn "no rtc device found" 30 | 31 | mountinfo -P '^/(tmp|run)$' -T '^(tmpfs|cgroup|sysfs)$' 32 | mountinfo /tmp || error "/tmp is not mounted" && end "$?" /tmp 33 | info "/ mount arguments: $(fstabinfo -a /)" 34 | 35 | case "$(uname -s)" in 36 | [Ll]inux) 37 | echo BOOT_IMAGE=$(get_boot_option BOOT_IMAGE) 38 | ;; 39 | esac 40 | --------------------------------------------------------------------------------