Widy/Startup Services: Difference between revisions
From charlesreid1
(Created page with "Here's a great page with information about the Widy slider switch, LEDs, etc: https://wiki.openwrt.org/toh/tp-link/tl-mr3040") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Here's a great page with information about the Widy slider switch, LEDs, etc: https://wiki.openwrt.org/toh/tp-link/tl-mr3040 | Here's a great page with information about the Widy slider switch, LEDs, etc: https://wiki.openwrt.org/toh/tp-link/tl-mr3040 | ||
=Creating Startup Services= | |||
The OpenWrt operating system uses the <code>/etc/init.d/</code> directory to store a bunch of scripts to run on boot. You can also find a sample startup script | |||
==Where Startup Services Go== | |||
If you want something to run on the Widy on boot, you can put it in <code>/etc/init.d/</code>. | |||
You will see, when you look inside that directory, that there are already a bunch of scripts: | |||
<pre> | |||
root@OpenWrt:/etc/init.d# ls -l | |||
-rwxr-xr-x 1 root root 1411 Sep 20 2014 boot | |||
-rwxr-xr-x 1 root root 729 Oct 1 2014 cron | |||
-rwxr-xr-x 1 root root 14350 Oct 1 2014 dnsmasq | |||
-rwxr-xr-x 1 root root 252 Sep 20 2014 done | |||
-rwxr-xr-x 1 root root 4153 Oct 1 2014 dropbear | |||
-rwxr-xr-x 1 root root 997 Oct 1 2014 firewall | |||
-rwxr-xr-x 1 root root 341 Sep 20 2014 fstab | |||
-rwxr-xr-x 1 root root 2025 Sep 20 2014 led | |||
-rwxr-xr-x 1 root root 2169 Oct 1 2014 log | |||
-rwxr-xr-x 1 root root 2742 Sep 20 2014 network | |||
-rwxr-xr-x 1 root root 244 Oct 1 2014 odhcpd | |||
-rwxr-xr-x 1 root root 422 Sep 23 2014 snort | |||
-rwxr-xr-x 1 root root 125 Sep 20 2014 sysctl | |||
-rwxr-xr-x 1 root root 247 Sep 20 2014 sysfixtime | |||
-rwxr-xr-x 1 root root 770 Oct 1 2014 sysntpd | |||
-rwxr-xr-x 1 root root 1025 Sep 20 2014 system | |||
-rwxr-xr-x 1 root root 926 Oct 1 2014 telnet | |||
-rwxr-xr-x 1 root root 3444 Oct 1 2014 uhttpd | |||
-rwxr-xr-x 1 root root 106 Sep 20 2014 umount | |||
</pre> | |||
==Sample Startup Script== | |||
There's a nice sample startup script in <code>/etc/rc.common</code>: | |||
{{Scrollbox| | |||
<pre> | |||
#!/bin/sh | |||
# Copyright (C) 2006-2012 OpenWrt.org | |||
. $IPKG_INSTROOT/lib/functions.sh | |||
. $IPKG_INSTROOT/lib/functions/service.sh | |||
initscript=$1 | |||
action=${2:-help} | |||
shift 2 | |||
start() { | |||
return 0 | |||
} | |||
stop() { | |||
return 0 | |||
} | |||
reload() { | |||
return 1 | |||
} | |||
restart() { | |||
trap '' TERM | |||
stop "$@" | |||
start "$@" | |||
} | |||
boot() { | |||
start "$@" | |||
} | |||
shutdown() { | |||
stop | |||
} | |||
disable() { | |||
name="$(basename "${initscript}")" | |||
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name | |||
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name | |||
} | |||
enable() { | |||
name="$(basename "${initscript}")" | |||
disable | |||
[ -n "$START" -o -n "$STOP" ] || { | |||
echo "/etc/init.d/$name does not have a START or STOP value" | |||
return 1 | |||
} | |||
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" | |||
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" | |||
} | |||
enabled() { | |||
name="$(basename "${initscript}")" | |||
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ] | |||
} | |||
depends() { | |||
return 0 | |||
} | |||
help() { | |||
cat <<EOF | |||
Syntax: $initscript [command] | |||
Available commands: | |||
start Start the service | |||
stop Stop the service | |||
restart Restart the service | |||
reload Reload configuration files (or restart if that fails) | |||
enable Enable service autostart | |||
disable Disable service autostart | |||
$EXTRA_HELP | |||
EOF | |||
} | |||
# for procd | |||
start_service() { | |||
return 0 | |||
} | |||
stop_service() { | |||
return 0 | |||
} | |||
service_triggers() { | |||
return 0 | |||
} | |||
service_running() { | |||
return 0 | |||
} | |||
${INIT_TRACE:+set -x} | |||
. "$initscript" | |||
[ -n "$USE_PROCD" ] && { | |||
EXTRA_COMMANDS="${EXTRA_COMMANDS} running" | |||
. $IPKG_INSTROOT/lib/functions/procd.sh | |||
basescript=$(readlink "$initscript") | |||
rc_procd() { | |||
procd_open_service "$(basename ${basescript:-$initscript})" "$initscript" | |||
"$@" | |||
procd_close_service | |||
} | |||
start() { | |||
rc_procd start_service "$@" | |||
if eval "type service_started" 2>/dev/null >/dev/null; then | |||
service_started | |||
fi | |||
} | |||
stop() { | |||
stop_service "$@" | |||
procd_kill "$(basename ${basescript:-$initscript})" "$1" | |||
} | |||
reload() { | |||
if eval "type reload_service" 2>/dev/null >/dev/null; then | |||
reload_service "$@" | |||
else | |||
start | |||
fi | |||
} | |||
running() { | |||
service_running "$@" | |||
} | |||
} | |||
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}" | |||
list_contains ALL_COMMANDS "$action" || action=help | |||
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :' | |||
$action "$@" | |||
</pre> | |||
}} | |||
=Flags= | |||
{{WidyFlag}} | |||
Latest revision as of 18:36, 21 June 2016
Here's a great page with information about the Widy slider switch, LEDs, etc: https://wiki.openwrt.org/toh/tp-link/tl-mr3040
Creating Startup Services
The OpenWrt operating system uses the /etc/init.d/ directory to store a bunch of scripts to run on boot. You can also find a sample startup script
Where Startup Services Go
If you want something to run on the Widy on boot, you can put it in /etc/init.d/.
You will see, when you look inside that directory, that there are already a bunch of scripts:
root@OpenWrt:/etc/init.d# ls -l -rwxr-xr-x 1 root root 1411 Sep 20 2014 boot -rwxr-xr-x 1 root root 729 Oct 1 2014 cron -rwxr-xr-x 1 root root 14350 Oct 1 2014 dnsmasq -rwxr-xr-x 1 root root 252 Sep 20 2014 done -rwxr-xr-x 1 root root 4153 Oct 1 2014 dropbear -rwxr-xr-x 1 root root 997 Oct 1 2014 firewall -rwxr-xr-x 1 root root 341 Sep 20 2014 fstab -rwxr-xr-x 1 root root 2025 Sep 20 2014 led -rwxr-xr-x 1 root root 2169 Oct 1 2014 log -rwxr-xr-x 1 root root 2742 Sep 20 2014 network -rwxr-xr-x 1 root root 244 Oct 1 2014 odhcpd -rwxr-xr-x 1 root root 422 Sep 23 2014 snort -rwxr-xr-x 1 root root 125 Sep 20 2014 sysctl -rwxr-xr-x 1 root root 247 Sep 20 2014 sysfixtime -rwxr-xr-x 1 root root 770 Oct 1 2014 sysntpd -rwxr-xr-x 1 root root 1025 Sep 20 2014 system -rwxr-xr-x 1 root root 926 Oct 1 2014 telnet -rwxr-xr-x 1 root root 3444 Oct 1 2014 uhttpd -rwxr-xr-x 1 root root 106 Sep 20 2014 umount
Sample Startup Script
There's a nice sample startup script in /etc/rc.common:
#!/bin/sh
# Copyright (C) 2006-2012 OpenWrt.org
. $IPKG_INSTROOT/lib/functions.sh
. $IPKG_INSTROOT/lib/functions/service.sh
initscript=$1
action=${2:-help}
shift 2
start() {
return 0
}
stop() {
return 0
}
reload() {
return 1
}
restart() {
trap '' TERM
stop "$@"
start "$@"
}
boot() {
start "$@"
}
shutdown() {
stop
}
disable() {
name="$(basename "${initscript}")"
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
}
enable() {
name="$(basename "${initscript}")"
disable
[ -n "$START" -o -n "$STOP" ] || {
echo "/etc/init.d/$name does not have a START or STOP value"
return 1
}
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
}
enabled() {
name="$(basename "${initscript}")"
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
}
depends() {
return 0
}
help() {
cat <<EOF
Syntax: $initscript [command]
Available commands:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if that fails)
enable Enable service autostart
disable Disable service autostart
$EXTRA_HELP
EOF
}
# for procd
start_service() {
return 0
}
stop_service() {
return 0
}
service_triggers() {
return 0
}
service_running() {
return 0
}
${INIT_TRACE:+set -x}
. "$initscript"
[ -n "$USE_PROCD" ] && {
EXTRA_COMMANDS="${EXTRA_COMMANDS} running"
. $IPKG_INSTROOT/lib/functions/procd.sh
basescript=$(readlink "$initscript")
rc_procd() {
procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
"$@"
procd_close_service
}
start() {
rc_procd start_service "$@"
if eval "type service_started" 2>/dev/null >/dev/null; then
service_started
fi
}
stop() {
stop_service "$@"
procd_kill "$(basename ${basescript:-$initscript})" "$1"
}
reload() {
if eval "type reload_service" 2>/dev/null >/dev/null; then
reload_service "$@"
else
start
fi
}
running() {
service_running "$@"
}
}
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
list_contains ALL_COMMANDS "$action" || action=help
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
$action "$@"
|
Flags
| Widy running OpenWRT on a router to make it into a wearable wireless ear
The Widy Device: Widy installation: Widy/Installing · Widy/Redux Widy Wireless Internet Gateway: Widy/Wireless Gateway Widy Ethernet Internet Gateway: Widy/Ethernet Gateway Widy post-installation: Widy/Post-Install Widy configuration: Widy/Configuration
Using tools on the Widy: Widy/Toolbox Using tcpdump on Widy: Widy/Tcpdump Using aircrack on Widy: Widy/Aircrack Python/Scapy on Widy: Widy/Scapy
Scripting the slider button on the Widy: Widy/Configuration#Slider Button Configuration Using widy as a wireless access point: Widy/Access_Point Debugging some SSH problems: Widy/Access_Point/SSH Bridging widy wireless and ethernet connections: Widy/Bridging Widy startup services: Widy/Startup Services Create a hard-wired serial/TTL connection: Widy/Serial
|