LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 03-12-2006, 01:58 PM   #16
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30

are you running this as a user or as root?

/var/run where the pids are stored is owned by root so as a user you cant write there

Last edited by skog; 03-12-2006 at 02:06 PM.
 
Old 03-12-2006, 02:32 PM   #17
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
I run this script always as root and don't get any pid files,

but maybe this helps:
this other suse script crate a pid file:
Code:
#! /bin/bash

# Check for missing binaries (stale symlinks should not happen)
powersaved_BIN=/usr/sbin/powersaved
powersave_BIN=/usr/bin/powersave
ACPID_BIN=/usr/sbin/acpid
# this is the default set of acpi modules loaded if nothing is configured
DEFAULT_ACPI_MODULES="ac battery button fan processor thermal"

test -x $powersaved_BIN || exit 5
# Check for existence of needed config file and read it

# ToDo set it on the real directory 
CONFIG=/etc/sysconfig/powersave

test -r $CONFIG || exit 6
. $CONFIG/common
. $CONFIG/cpufreq
. $CONFIG/thermal
if test -e /etc/sysconfig/security; then
 . /etc/sysconfig/security
fi

LOGGER="/bin/logger -t rcpowersaved"
# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_status -s     display "skipped" and exit with status 3
#      rc_status -u     display "unused" and exit with status 3
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
#      rc_active	checks whether a service is activated by symlinks
#      rc_splash arg    sets the boot splash screen to arg (if active)
. /etc/rc.status

# Reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0	  - success
# 1       - generic or unspecified error
# 2       - invalid or excess argument(s)
# 3       - unimplemented feature (e.g. "reload")
# 4       - user had insufficient privileges
# 5       - program is not installed
# 6       - program is not configured
# 7       - program is not running
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signaling is not supported) are
# considered a success.


# maybe I could check for apm, acpi and cpufreq
# if nothing is there it makes no sense to start the program
# but this is nasty because of different kernel
# implementations and therefore different file locations

OPTS=""
SYSFS_PATH="/sys/devices/system/cpu/cpu0/cpufreq"

function load_governors()
{
    if [ ! -r $SYSFS_PATH ];then
	$LOGGER Cannot load cpufreq governors - No cpufreq driver available
	return 1
    fi
    read govs < $SYSFS_PATH/scaling_available_governors
    case "$govs" in
	*powersave*) 
	    ;;
	*) 
	    modprobe -q cpufreq_powersave >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER powersave cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*performance*) 
	    ;;
	*) 
	    modprobe -q cpufreq_performance >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER perfromance cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*userspace*) 
	    ;;
	*) 
	    modprobe -q cpufreq_userspace >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER userspace cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*ondemand*)
	    ;;
	*) 
	    modprobe -q cpufreq_ondemand >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER ondemand cpufreq governor could not be loaded
	    ;;
    esac
    return 0
}

case "$1" in
        start)
		checkproc $powersaved_BIN
		if [ $? = 0 ]; then
		    echo -n "daemon already running"
		    rc_status -v
		    rc_exit
		elif [ -e /var/run/powersaved.pid ];then 
		    rm -f  /var/run/powersaved.pid&> /dev/null
		fi;
		checkproc "cpufreqd" &>/dev/null
		if [ $? = 0 ]; then
		    echo -n "cpufreqd already running, stop it first and restart service"
		    rc_status -s
		    rc_exit
		fi

		ACPI_APM=`$powersave_BIN --apm-acpi`
		if [ "$ACPI_APM" = "ACPI" ]; then
	        # set thermal polling frequency
	        # this should be managed by the daemon later
		    if [ "$THERMAL_POLLING_FREQUENCY" != "0" ];then
			[ -z "$THERMAL_POLLING_FREQUENCY" ] && THERMAL_POLLING_FREQUENCY=2
			for x in /proc/acpi/thermal_zone/*; do
			    [ -w $x/polling_frequency ] && echo "$THERMAL_POLLING_FREQUENCY" >$x/polling_frequency
			done
		    fi

		    ACCESS_PROC_EVENTS=" (accessing ACPI events over acpid) "
		    ACPI_EVENT_FILE="/var/run/acpid.socket"

		    pidof $ACPID_BIN >/dev/null
		    ACPID_NOT_RUNNING=$?
		    # if acpid is not there we need access to /proc/acpi/event
		    if [ $ACPID_NOT_RUNNING = 1 ];then
			$LOGGER "WARN: Service powersaved skipped. You have to start acpid before powersaved"
			echo -n "###############################################
# ACPI system but acpid not running.          #
# Start acpid first, then restart powersaved! #
###############################################"
			rc_status -s
			rc_exit
		    fi
		elif [ "$ACPI_APM" = "APM" ]; then
		    # check whether apmd is already running
		    checkproc "apmd" &>/dev/null
		    if [ $? = 0 ];then
			echo -n "APM daemon is already running, stop it first and restart service"
			rc_status -s
			rc_exit
		    fi
		    echo -n "This machine supports APM "
		
		#### when neither APM nor ACPI is found, do still start the powersave daemon
        #### we still provide suspend to disk and possibly cpufreq feature
        #### this is always the case on ppc workstations
#		else
#		    $LOGGER "INFO: Your system does neither support ACPI nor APM. \
#the powersave service does not provide any features for this machine, therefore the service is skipped."
#		    rc_status -s
		fi 

		CPUFREQ_MODULES="speedstep_centrino speedstep_ich powernow_k8 powernow_k7 powernow_k6 longrun longhaul acpi"
		CPUFREQ_MODULES_GREP="^speedstep_centrino\|^speedstep_ich\|^powernow_k8\|^powernow_k7\|^powernow_k6\|^longrun\|^longhaul\|^acpi"

		###### load CPUFREQ modules############
		# module specfied in sysconfig.cpufreq?
		if [ "$CPUFREQD_MODULE" != "off" ]; then
			# test for already loaded modules
			ALREADY_LOADED_MODS=`grep $CPUFREQ_MODULES_GREP /proc/modules`
			if [ "$CPUFREQD_MODULE" ]; then
				modprobe -q $CPUFREQD_MODULE $CPUFREQD_MODULE_OPTS &>/dev/null
				RETVAL=$?
			# try to load one of the modules we know
			elif [ -z "$ALREADY_LOADED_MODS" ] ; then 
				for MODULE in $CPUFREQ_MODULES; do
					modprobe $MODULE &>/dev/null
					RETVAL=$?
					[ "$RETVAL" = 0 ] && break
				done
				# skip if no module could be loaded!
				if [ "$RETVAL" != 0 ]; then
					$LOGGER "CPU frequency scaling is not supported by your processor."
					$LOGGER "enter 'CPUFREQD_MODULE=off' in $CONFIG/cpufreq to avoid this warning."
				else
					$LOGGER "enter '$MODULE' into CPUFREQD_MODULE in $CONFIG/cpufreq."
					$LOGGER "this will speed up starting powersaved and avoid unnecessary warnings in syslog."
				fi
			fi
			# see function above 
                        # -> load powersave,performance,userspace and ondemand governor
			load_governors
			# sleeping should not be necessary, all is processed sequential
                        # usleep 10000
		fi
		###### load CPUFREQ modules############
		echo -ne "Starting powersaved $ACCESS_PROC_EVENTS"
		OPTS="$OPTS -v ${DEBUG:-3}"
		startproc $powersaved_BIN -d ${ACPI_EVENT_FILE:+-f "$ACPI_EVENT_FILE"} $OPTS
		rc_status -v
		;;
	stop)   
		echo -n "Shutting down powersaved "
		killproc -TERM $powersaved_BIN
		rc_status -v
		;;
	try-restart)
	        $0 status
		if test $? = 0; then
			$0 restart
		else
			rc_reset        # Not running is not a failure.
		fi
		rc_status
		;;
	restart)
		$0 stop
		$0 start
		rc_status
		;;
	force-reload|reload)
		echo -n "Reload service powersaved "
		killproc -HUP $powersaved_BIN
		rc_status -v
		;;
	status)
		echo -n "Checking for service powersaved "
		checkproc $powersaved_BIN
		rc_status -v
		;;
	*)
		echo "Usage: $0" \
		     "{start|stop|status|try-restart|restart|force-reload|reload}"
		exit 1
		;;
esac
rc_exit
 
Old 03-12-2006, 02:58 PM   #18
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
try it like this:

start-stop-daemon --start --name wpa_supplicant --oknodo --exec /usr/local/sbin/wpa_supplicant -- -B -w -i ath0 -D madwifi -c /etc/wpa_supplicant.conf -dd

the script you just posted is a LSB compliant script the wpa script is using debians startup/stop/restart method. both should work just a matter of getting it configured properly.

try this too:

startproc -f -p /var/run/wpa_supplicant.pid /usr/local/sbin/wpa_supplicant -w -i ath0 -D madwifi -c /etc/wpa_supplicant.conf -dd

Last edited by skog; 03-12-2006 at 03:01 PM.
 
Old 03-12-2006, 03:22 PM   #19
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
both commands create in /var/run a temporary directory wpa_supplicant
with ath0 file inside, but still no pid files.
 
Old 03-12-2006, 03:52 PM   #20
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
when you ran this from the command line did it create a pid file?
/usr/local/sbin/wpa_supplicant -w -i ath0 -D madwifi -c /etc/wpa_supplicant.conf -dd

see if wpa_supplicant has an option to make the pid file:
/usr/local/sbin/wpa_supplicant --help
 
Old 03-12-2006, 04:08 PM   #21
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
ok i think i found it in the docs

try this:

start-stop-daemon --start --name wpa_supplicant --oknodo --exec /usr/local/sbin/wpa_supplicant -- -B -w -i ath0 -D madwifi -c /etc/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid -dd

Last edited by skog; 03-12-2006 at 04:11 PM.
 
Old 03-12-2006, 04:35 PM   #22
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
thanks a lot for the excellent support !

now the pid file will be created and I can start the WPA without problems,
but cannot stop, reload or restart using this script:
Code:
#!/bin/sh

# Buyer beware! This is really only useful if you have a 
# MiniPCI or other permanent wireless device.

# However, the wpa_supplicant daemon will start, and sit waiting
# for the name interface to come up. Therefore, if you want to use
# this with pcmcia or other nonsense, it may be best to ifrename
# your wireless interface if it has an "ethX" name that is variable.

PATH=/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/local/sbin/wpa_supplicant
PIDFILE="/var/run/wpasupplicant.pid"
CONFIG="/etc/wpa_supplicant.conf"
PNAME="wpa_supplicant"

# insane defaults
OPTIONS="-Bw" # daemonize and wait for interface
ENABLED=0

[ -f /etc/default/wpasupplicant ] && . /etc/default/wpasupplicant

if [ "$ENABLED" = "0" ]; then
	echo "wpasupplicant: disabled, see /etc/default/wpasupplicant"
	exit 0;
fi

[ -f $CONFIG ] || ( echo "No configuration file found, not starting."; \
	exit 1; )

[ -f $DAEMON ] || exit 0

set -e

case "$1" in
	start)
		echo -n "Starting wpasupplicant: "

                start-stop-daemon --start --name $PNAME --oknodo --exec $DAEMON -- -B $OPTIONS -P $PIDFILE -dd
		
		echo "done."
		;;
	stop)
		echo -n "Stopping wpasupplicant: "
		start-stop-daemon --stop --name $PNAME \
			--oknodo 
		echo "done."
		if [ -f $PIDFILE ]; then
			rm -f $PIDFILE;
		fi		
		;;
	reload|force-reload)
		echo -n "Reloading wpasupplicant: "
		start-stop-daemon --stop --signal HUP \
			--name $PNAME 
		echo "done."
		;;
	restart)
		echo -n "Restarting wpasupplicant: "
		start-stop-daemon --stop --name $PNAME \
			--retry 5 --oknodo
		if [ -f $PIDFILE ]; then
			rm -f $PIDFILE;
		fi		
		start-stop-daemon --start --name $PNAME \
			--oknodo --startas $DAEMON -- -B $OPTIONS
		echo "done."
		;;
	*)
		echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
		exit 1
		;;
esac

exit 0
If I try to stop get following error:
Code:
# ./wpa stop
Stopping wpasupplicant: start-stop-daemon: need at least one of --exec, --pidfile or --user
Try `start-stop-daemon --help' for more information.
do you know howto change it ?
 
Old 03-12-2006, 04:41 PM   #23
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
yea, change all the --name options to --exec

like for example change the stop case option:
start-stop-daemon --stop --name $PNAME --oknodo

to:
start-stop-daemon --stop --exec $PNAME --oknodo
 
Old 03-12-2006, 05:04 PM   #24
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
to change all options from --name to --exec doesn't work and I get this error:
Code:
# ./wpa stop
Stopping wpasupplicant: start-stop-daemon: stat wpa_supplicant: No such file or directory
but if I change from:
Code:
stop)
		echo -n "Stopping wpasupplicant: "
		start-stop-daemon --stop --name $PNAME \
			--oknodo 
		echo "done."
to:
Code:
stop)
		echo -n "Stopping wpasupplicant: "
		start-stop-daemon --stop --name $PNAME \
			--oknodo --exec $DAEMON
		echo "done."
then I can stop the wpa_supplicant program without errors, but still cannot reload or restart this script.

Last edited by cccc; 03-12-2006 at 05:05 PM.
 
Old 03-12-2006, 05:24 PM   #25
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
what happens when you try to restart or reload?
 
Old 03-12-2006, 05:46 PM   #26
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
Code:
# ./wpa start
Starting wpasupplicant:  wpa_supplicantdone.
linux:/home/scripts # ./wpa reload
Reloading wpasupplicant: start-stop-daemon: --signal takes a numeric argument
Try `start-stop-daemon --help' for more information.
linux:/home/scripts # ./wpa stop
Stopping wpasupplicant:  wpa_supplicantdone.
linux:/home/scripts # ./wpa restart
Restarting wpasupplicant: start-stop-daemon: unrecognized option `--retry'
Try `start-stop-daemon --help' for more information.
 
Old 03-12-2006, 06:11 PM   #27
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
try this:

echo -n "Reloading wpasupplicant: "
start-stop-daemon --stop --signal 1 --name $PNAME

echo -n "Restarting wpasupplicant: "
start-stop-daemon --stop --name $PNAME --oknodo
 
Old 03-12-2006, 06:58 PM   #28
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
still have errors:
Code:
linux:/home/scripts # ./wpa stop
Stopping wpasupplicant:  wpa_supplicantdone.
linux:/home/scripts # ./wpa start
Starting wpasupplicant:  wpa_supplicantdone.
linux:/home/scripts # ./wpa reload
Reloading wpasupplicant: start-stop-daemon: need at least one of --exec, --pidfile or --user
Try `start-stop-daemon --help' for more information.
linux:/home/scripts # ./wpa restart
Restarting wpasupplicant: start-stop-daemon: need at least one of --exec, --pidfile or --user
Try `start-stop-daemon --help' for more information.
linux:/home/scripts #  start-stop-daemon --stop --name $PNAME --oknodo
start-stop-daemon: need at least one of --exec, --pidfile or --user
Try `start-stop-daemon --help' for more information.
 
Old 03-13-2006, 10:51 AM   #29
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
try this one:

echo -n "Reloading wpasupplicant: "
start-stop-daemon --stop --signal 1 --name $PNAME --exec $DAEMON
 
Old 03-13-2006, 06:06 PM   #30
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
thanks again,

reload it works now, but still have a problem with the restart:
Code:
restart)
		echo -n "Restarting wpasupplicant: "
		 start-stop-daemon --stop --name $PNAME \
			--retry 5 --oknodo --exec $DAEMON
		if [ -f $PIDFILE ]; then
			rm -f $PIDFILE;
		fi		
		start-stop-daemon --start --name $PNAME --oknodo --exec $DAEMON -- -B $OPTIONS -P $PIDFILE 
		echo "done."
		;;
Code:
linux:/home/scripts # ./wpa restart
Restarting wpasupplicant: start-stop-daemon: unrecognized option `--retry'
Try `start-stop-daemon --help' for more information.
do you know which command could exchange the --retry option ?
Code:
linux:/home/scripts # start-stop-daemon --help
start-stop-daemon for Debian Linux - small and fast C version written by
Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.
version 0.3.1, 1996-07-19

Usage:
    start-stop-daemon -S|--start options ... -- arguments ...
    start-stop-daemon -K|--stop options ...
    start-stop-daemon -H|--help
    start-stop-daemon -V|--version

Options (at least one of --exec|--pidfile|--user is required):
    -x|--exec <executable>       program to start/check if it is running
    -p|--pidfile <pid-file>      pid file to check
    -u|--user <username>|<uid>   stop this user's processes
    -n|--name <process-name>     start/stop processes with this name
    -s|--signal <signal>         signal to send (default 15)
    -t|--test                    test mode, don't do anything
    -o|--oknodo                  exit status 0 (not 1) if nothing done
    -q|--quiet  |  -v, --verbose

Exit status:  0 = done  1 = nothing done (=> 0 if --oknodo)  2 = trouble

Last edited by cccc; 03-13-2006 at 06:09 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 09:40 PM
Startup script Larsza SUSE / openSUSE 7 10-21-2005 06:59 AM
Startup Script djinniyah Linux - Newbie 3 09-18-2003 05:20 AM
startup script c0c0deuz Linux - Newbie 3 03-29-2003 03:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration