Running user script problem.

144 views
Skip to first unread message

Ram Set

unread,
May 24, 2017, 4:53:20 PM5/24/17
to al...@googlegroups.com
I am trying to run the following script via /mnt/sda2/boot.sh (loaded under user)

#!/bin/sh

sleep 90
/mnt/sda2/Alt-F/opt/sbin/apcupsd /opt/etc/apcupsd/apcupsd.conf



however after reboot, the command is not in the PS list... not even sure it actually starts.

I do see the user service as showing Running though ...

What am I doing wrong ?

I need to run that one daemon only.

Happening on Alt-F 0.1RC6
Message has been deleted

João Cardoso

unread,
May 25, 2017, 11:59:15 AM5/25/17
to Alt-F
The user boot script should be added using the webUI, and is executed when the filesystem where it is saved is found, not when the user initscript is executed.


The RC6 snapshot announcement says:

-When using Services->System->User, Submit, the error "user_proc.cgi: line 30: syntax error:..."


On Wednesday, 24 May 2017 21:53:20 UTC+1, Ram Set wrote:
I am trying to run the following script via /mnt/sda2/boot.sh (loaded under user)

#!/bin/sh

sleep 90
/mnt/sda2/Alt-F/opt/sbin/apcupsd /opt/etc/apcupsd/apcupsd.conf


Sure that 'apcupsd' works fine? Does it generates a log that you can examine?

Start with a simpler command, such
echo "Yes, it works" > /tmp/foobar

The default webUI (after fixed) script redirects script output a file:

#!/bin/sh

# Script to execute as the root user at boot time.
# You can loose your data or make the system inaccessible
# if using the wrong commands. You have been warned!
 
exec >> /var/log/user.log 2>&1

case "$1" in
start)
echo "Starting $0"
;;
stop)
echo "Stopping $0"
;;
esac

Ram Set

unread,
May 25, 2017, 12:22:02 PM5/25/17
to Alt-F

It does seem that the user script is executing at boot however apcupsd is buggy and won't execute, so that, puts the project to a halt.

thank you.

João Cardoso

unread,
May 25, 2017, 1:00:15 PM5/25/17
to Alt-F


On Thursday, 25 May 2017 17:22:02 UTC+1, Ram Set wrote:

It does seem that the user script is executing at boot however apcupsd is buggy and won't execute, so that, puts the project to a halt.

doesn't  "nuts" (Network UPS Tools is a collection of programs for monitoring and administering UPS, PDU and SCD hardware) works? It is an Alt-F package, but I couldn't test it however


thank you.

Ram Set

unread,
May 25, 2017, 1:14:53 PM5/25/17
to Alt-F
the whole UPS monitoring scenario is a little more complex.

I monitor 2 UPS units via a raspberry and the pi is publishing real time stats to a web interface.

i chose to use a frame from the alt-f index.html to display my stats (published by the raspberry) and it ended up looking like this:


Now the thing is that the pi, is using APCUPSD to monitor them (due to various APC only related parameters). I did try to configure nut for it on the pi but the whole password and username requirement was something i wasn't looking to set-up. I have a ton of users and passwords that i already memorized, i don't need 2 more ...
apcupsd though, running on Alt-f, is able to network connect to the UPS on the pi via the IP and the port. 

I'm sure nut is also able to do that but that whole user/password combo just threw me off big time.

In my case apcupsd was a minimal configuration required daemon that I ended up using.

What i wanted to do, is to monitor for UPS events via the Alt-F and send notifications from the alt-f itself.

I dropped it because I ended up splitting the configurations on the raspberry so that I have 2 daemons running, each with it's own configuration and notification settings.

Ram Set

unread,
May 25, 2017, 7:33:18 PM5/25/17
to al...@googlegroups.com

I decided to give NUT another spin. The Alf-F package (nuts) is missing a lot of dependecies and the driver for the apcupsd. 

I was able however to connect the Entware-ng nut packge (2.7.4-4) with the  apcupsd driver (nut-driver-apcupsd-ups 2.7.4-4) and after configuring it, i was able to read the raspberry pi apcups network output (thus establishing a UPS monitor on the Alt-F).

I am however facing the same issue with the user script.

It fails to execute the daemons for some reason.

here is my current script


 #!/bin/sh

# Script to execute as the root user at boot time.
# You can loose your data or make the system inaccessible
# if using the wrong commands. You have been warned!

upsdrvctl start
sleep 5
upsd


apcupsd was another package that i installed from the same source.

João Cardoso

unread,
May 26, 2017, 2:08:55 PM5/26/17
to Alt-F


On Friday, 26 May 2017 00:33:18 UTC+1, Ram Set wrote:

I decided to give NUT another spin. The Alf-F package (nuts) is missing a lot of dependecies

What do you mean?
 
and the driver for the apcupsd.  
 

I was able however to connect the Entware-ng nut packge (2.7.4-4) with the  apcupsd driver (nut-driver-apcupsd-ups 2.7.4-4) and after configuring it, i was able to read the raspberry pi apcups network output (thus establishing a UPS monitor on the Alt-F).

I am however facing the same issue with the user script.

It fails to execute the daemons for some reason.

here is my current script


 #!/bin/sh

You have to create a log to see what is wrong. Add here

exec >> /var/log/user.log 2>&1

and watch in /var/log/user.log the script output.


# Script to execute as the root user at boot time.
# You can loose your data or make the system inaccessible
# if using the wrong commands. You have been warned!


Use the full path for binaries. It might not be enough,  prepend the new packages path to the PATH:
PATH=/opt/bin:/opt/sbin:$PATH

That is done when entware-ng is started in the webUI. Are you using the webUI or the command line? 

Have you setup entware-ng initscript to start the needed services and set it to be started? That should be enough, and you wouldn't need the user boot script anymore. 

Anyway, it's and alien Alt-F package.

Ram Set

unread,
Jun 5, 2017, 2:19:58 PM6/5/17
to al...@googlegroups.com
I decided to give it one more try to see exactly how this works and IF it works.

I have it enabled, with the following code inside:

#!/bin/sh

# Script to execute as the root user at boot time.
# You can loose your data or make the system inaccessible
# if using the wrong commands. You have been warned!
 
exec >> /var/log/user.log 2>&1
case "$1" in
start)
/etc/IOSpush.pl -apikeyfile=/etc/api_key.txt -event="MezelNAS2" -notification="Powered on and ready."

;;
stop)
echo "Stopping $0"
;;
esac

Now, the notification works, i always receive it reboot/shutdown regardless on how i do it. Either via the webpage or console. As soon as I issue the command, the user script gets triggered and it sends me the notification. 
It never happens on boot. 

It seems that the user script is triggered the other way around ... Can someone confirm ?

L.E. log states that the file is not found. 
I even placed the direct path to the file. 

/mnt/sda2/boot.sh: line 16: /mnt/sda2/Alt-F/etc/IOSpush.pl: not found
/mnt/sda2/boot.sh: line 16: /etc/IOSpush.pl: not found

L.E.

added a delay. All working  now :)

João Cardoso

unread,
Jun 6, 2017, 2:40:15 PM6/6/17
to Alt-F


On Monday, 5 June 2017 19:19:58 UTC+1, Ram Set wrote:
I decided to give it one more try to see exactly how this works and IF it works.

Of course it works.
 

I have it enabled, with the following code inside:

#!/bin/sh
# Script to execute as the root user at boot time.
# You can loose your data or make the system inaccessible
# if using the wrong commands. You have been warned!
 
exec >> /var/log/user.log 2>&1
case "$1" in
start)
/etc/IOSpush.pl -apikeyfile=/etc/api_key.txt -event="MezelNAS2" -notification="Powered on and ready."
;;
stop)
echo "Stopping $0"
;;
esac

Now, the notification works, i always receive it reboot/shutdown regardless on how i do it. Either via the webpage or console. As soon as I issue the command, the user script gets triggered and it sends me the notification. 
It never happens on boot. 

It seems that the user script is triggered the other way around ... Can someone confirm ?

The script is executed when the filesystem where it is stored is discovered, checked and  mounted. If it refers to commands or files located on filesystems that are not yet mounted, than those commands will fail (if it is stored in sda2 and refers to command which are on sdb2 or md1, e.g.)
The script must be created thought the webUI and "settings saved", and a "lock" file will be created to not start it again 
[root@DNS-325]# ls -l /tmp/lock/userscript 
-rw-r--r--    1 root     root             0 May 18 18:40 /tmp/lock/userscript

so  "rcuser status" will show that it has been already started.

If your script refers to commands on filesystems that are not yet mounted at boot time it will have to wait for them (or saved there). An example of a customized script I use:

[root@DNS-325]# grep USER_SCRIP /etc/misc.conf 
USER_SCRIPT="/mnt/sda4/startup.sh"


#!/bin/sh


exec >> /var/log/user.log 2>&1

case "$1" in
start
)


waitfor
="md1 sda4 sdb3"    

for i in $waitfor; do
    echo
-n "waiting for $i:"
   
while ! mountpoint -q /mnt/$i; do
        echo
-n '.'
        sleep
5
   
done
    echo OK
done

echo
-n "Waiting for aufs.sh to finish:"
while ! aufs.sh -s >& /dev/null; do
        echo
-n '.'
        sleep
1
done

# FIXME: full path with /Alt-F/ might be needed
#if test $(uname -r) = 3.18.28; then
#       ethtool -K eth0 tso off
#fi

cp
-a /mnt/sda4/.ssh /root

echo OK
;;
end)
;;
esac


and the user log (/var/log/user.log) shows:

waiting for md1:OK
waiting for sda4:OK
waiting for sdb3:OK
Waiting for aufs.sh to finish:OK

 

L.E. log states that the file is not found. 
I even placed the direct path to the file. 

/mnt/sda2/boot.sh: line 16: /mnt/sda2/Alt-F/etc/IOSpush.pl: not found
/mnt/sda2/boot.sh: line 16: /etc/IOSpush.pl: not found

perl (which is installed on disk under aufs control) does not seems to be available when your script runs. 
When you test the script at run time everything looks OK, but at boot time not everything might be setup. You have to wait for aufs. And *DONT* use/change anything under the Alt-F directory -- that's a README on there! >Everything under Alt-F will appear at its normal/expected location, so
 /mnt/sda2/Alt-F/etc/IOSpush.pl: will appear as /etc/IOSpush.pl -- read the wiki on how to customize the firmware

Ram Set

unread,
Jun 6, 2017, 3:06:02 PM6/6/17
to Alt-F

I used the 

while ! aufs.sh -s >& /dev/null; do
        echo
-n '.'
        sleep
1
done

So much cleaner than a timer.

Thank you. Everything works now as expected.

João Cardoso

unread,
Jun 6, 2017, 5:12:58 PM6/6/17
to Alt-F


On Tuesday, 6 June 2017 20:06:02 UTC+1, Ram Set wrote:

I used the 

while ! aufs.sh -s >& /dev/null; do
        echo
-n '.'
        sleep
1
done

So much cleaner than a timer.

yes, it's cleaner but will never ends if  aufs doesn't  get ready. A simpler "sleep" might be safer.
Or, alternatively, just for fun:

#!/bin/sh

# this script will terminate after 10 seconds maximum
# or earlier when the tasks terminate

TMOUT=10

mainpid=$$
(sleep $TMOUT; kill -USR1 $mainpid) &
watchdogpid=$!

reason () {
    echo "sorry, timeout"
    exit 1
}

trap reason USR1

# a count loop, replace by your tasks:    
cnt=15 # replace with 5 to terminate with success
while test $((--cnt)) != 0; do
    echo $cnt
    sleep 1
done
# end of tasks

kill $watchdogpid

echo "job done"
exit 0





Reply all
Reply to author
Forward
0 new messages