<commit_before>#!/bin/sh
# /etc/init.d/subnodes_ap
# starts up node.js app, ap0 interface, hostapd, and dnsmasq for broadcasting a wireless network with captive portal

NAME=subnodes_ap
DESC="Brings up wireless access point for connecting to web server running on the device."
DAEMON_PATH="/home/pi/subnodes"
DAEMONOPTS="sudo NODE_ENV=production PORT=80 nodemon subnode.js"
PIDFILE=/var/run/$NAME.pid
PHY="phy1"

	case "$1" in
		start)
			echo "Starting $NAME access point..."

			# associate the ap0 interface to a physical devices
			WLAN1=`iw dev | awk '/Interface/ { print $2}' | grep wlan1`
			if [ -n "$WLAN1" ] ; then
				ifconfig $WLAN1 down
				iw $WLAN1 del

				# assign ap0 to the hardware device found
				iw phy $PHY interface add ap0 type __ap
			fi

			# bring up ap0 wireless access point interface
			ifconfig ap0 up

			# start the hostapd and dnsmasq services
			service dnsmasq start
			#service hostapd start
			hostapd -B /etc/hostapd/hostapd.conf

			# start the node.js chat application
			cd $DAEMON_PATH
			PID=`$DAEMONOPTS > /dev/null 2>&1 & echo $!`
			#echo "Saving PID" $PID " to " $PIDFILE
				if [ -z $PID ]; then
					printf "%s\n" "Fail"
				else
					echo $PID > $PIDFILE
					printf "%s\n" "Ok"
				fi
			;;
		status)
			printf "%-50s" "Checking $NAME..."
			if [ -f $PIDFILE ]; then
				PID=`cat $PIDFILE`
				if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
					printf "%s\n" "Process dead but pidfile exists"
				else
					echo "Running"
				fi
			else
				printf "%s\n" "Service not running"
			fi
		;;
		stop)
			printf "%-50s" "Shutting down $NAME..."
				PID=`cat $PIDFILE`
				cd $DAEMON_PATH
			if [ -f $PIDFILE ]; then
				kill -HUP $PID
				printf "%s\n" "Ok"
				rm -f $PIDFILE
			else
				printf "%s\n" "pidfile not found"
			fi

			ifconfig ap0 down

			service hostapd stop
            service dnsmasq stop
		;;

		restart)
			$0 stop
			$0 start
		;;

*)
		echo "Usage: $0 {status|start|stop|restart}"
		exit 1
esac<commit_msg>stopping hostapd via init.d script<commit_after>#!/bin/sh
# /etc/init.d/subnodes_ap
# starts up node.js app, ap0 interface, hostapd, and dnsmasq for broadcasting a wireless network with captive portal

NAME=subnodes_ap
DESC="Brings up wireless access point for connecting to web server running on the device."
DAEMON_PATH="/home/pi/subnodes"
DAEMONOPTS="sudo NODE_ENV=production PORT=80 nodemon subnode.js"
PIDFILE=/var/run/$NAME.pid
PHY="phy1"

	case "$1" in
		start)
			echo "Starting $NAME access point..."

			# associate the ap0 interface to a physical devices
			WLAN1=`iw dev | awk '/Interface/ { print $2}' | grep wlan1`
			if [ -n "$WLAN1" ] ; then
				ifconfig $WLAN1 down
				iw $WLAN1 del

				# assign ap0 to the hardware device found
				iw phy $PHY interface add ap0 type __ap
			fi

			# bring up ap0 wireless access point interface
			ifconfig ap0 up

			# start the hostapd and dnsmasq services
			service dnsmasq start
			#service hostapd start
			hostapd -B /etc/hostapd/hostapd.conf

			# start the node.js chat application
			cd $DAEMON_PATH
			PID=`$DAEMONOPTS > /dev/null 2>&1 & echo $!`
			#echo "Saving PID" $PID " to " $PIDFILE
				if [ -z $PID ]; then
					printf "%s\n" "Fail"
				else
					echo $PID > $PIDFILE
					printf "%s\n" "Ok"
				fi
			;;
		status)
			printf "%-50s" "Checking $NAME..."
			if [ -f $PIDFILE ]; then
				PID=`cat $PIDFILE`
				if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
					printf "%s\n" "Process dead but pidfile exists"
				else
					echo "Running"
				fi
			else
				printf "%s\n" "Service not running"
			fi
		;;
		stop)
			printf "%-50s" "Shutting down $NAME..."
				PID=`cat $PIDFILE`
				cd $DAEMON_PATH
			if [ -f $PIDFILE ]; then
				kill -HUP $PID
				printf "%s\n" "Ok"
				rm -f $PIDFILE
			else
				printf "%s\n" "pidfile not found"
			fi

			ifconfig ap0 down

			/etc/init.d/hostapd stop
            service dnsmasq stop
		;;

		restart)
			$0 stop
			$0 start
		;;

*)
		echo "Usage: $0 {status|start|stop|restart}"
		exit 1
esac
{'fraction_non_alphanumeric': 0.11822044488877781, 'fraction_numerical': 0.013496625843539115, 'mean_word_length': 2.6282864913871262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7112832', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1431, 'n_words': 482}