wbp
New Member
Posts: 26
|
Post by wbp on Oct 14, 2019 10:45:27 GMT -8
I've always used a script in /etc/init.d for things that need to be run at boot, rather than making changes to /etc/rc.boot. There are some advantages to doing it this way. For example, you can enter this command to start SkyWeather: sudo /etc/init.d/skyweather start and this command to stop it: sudo /etc/init.d/skyweather stop
In my startup script I also gave the output file a name with the date in it. This way there is a new file each time SkyWeather is started, and you can easily purge the older ones. You *really* do NOT want to let nohup.out get so big it fills up the file system - it can be a real pain dealing with a Linux system where the file system is completely full.
Here's how to do this:
1) It's easier to do this if you modify SkyWeather.py so it can be run without typing "python". Insert this as the first line:
#!/usr/bin/python
Then make it executable:
sudo chmod +x SkyWeather.py
2) Now create a new script in /etc/init.d
sudo nano /etc/init.d/skyweather
#! /bin/sh # /etc/init.d/skyweather
### BEGIN INIT INFO # Provides: SkyWeather # Required-Start: $local_fs $remote_fs $syslog $time # Required-Stop: $local_fs $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start SkyWeather from boot # Description: A simple script which will start a program from boot and stop upon shut-down ### END INIT INFO
# Put any commands you always want to run here.
TIME=`date +"%y%m%d.%H%M"` # get a date/timestamp DATE=`date +"%y%m%d"` # get a datestamp echo $TIME case "$1" in start) echo "Starting SkyWeather" # run the program you want to start cd /home/pi/SDL_Pi_SkyWeather pigpiod ./SkyWeather.py >> skyweather.$DATE.log & chgrp pi skyweather.$DATE.log ;; stop) echo "Stopping SkyWeather" # end the program you want to stop killall "SkyWeather.py" ;; *) echo "Usage: /etc/init.d/skyweather {start|stop}" exit 1 ;; esac
3) Make the script executable: sudo chmod +x /etc/init.d/skyweather 4) Tell the init system about it: sudo update-rc.d skyweather defaults
That's it! Don't forget to remove the changes from /etc/rc.boot.
|
|
|
Post by SDL on Oct 14, 2019 14:05:34 GMT -8
Very nice! I like the notion of SkyWeather as a service.
BP
|
|
|
Post by topher2880 on Oct 22, 2019 16:48:50 GMT -8
Hi Will
Ive used your edits for a few days, until auto reboot, now I cant get the script up and running again.
I have entered sudo /etc/init.d/skyweather stop to stop the script, but my issue seems to be pigpio and a sudo killall pigpio doesnt seem to want to stop it running.
Is there a quick and easy way to stop STEP 4 from running on reboot, so that I can go back to the /etc/rc.local bootup option?
|
|
wbp
New Member
Posts: 26
|
Post by wbp on Oct 22, 2019 21:48:45 GMT -8
Hmmm - what happened with auto reboot that the script doesn't run? I've gone thru several now and it starts SkyWeather each time. In any case, just chmod -x the script in /etc/init.d and it won't run.
(what is it with this bulletin board system that it keeps adding crap to this post that I did NOT type???)
|
|
wbp
New Member
Posts: 26
|
Post by wbp on Oct 22, 2019 22:29:44 GMT -8
FWIW - there is no harm in running pigpiod multiple times. All it does is start the daemon. If it's already running, it will give an error message about not being able to lock the pid file, but that doesn't hurt anything. You don't need to stop it. if you enter "man update-rc.d" you will see the documentation on that command, which will tell you that to remove a script, you can enter:
sudo update-rc.d skyweather remove
and this will stop the /etc/init.d/skyweather script from being run at boot.
|
|
|
Post by topher2880 on Oct 22, 2019 23:59:59 GMT -8
Thanks for the reply Will, I just wanted to stop it running, so that I could do some debugging. I really like the multiple log files and its so much easier to locate issues... This is whats happening after I run my script now Before, I couldnt get to that point, so at least now, I have somethig to go on As for the forum posting what youre not typing, you get used to it.. eventually hahaha
|
|
blackcrow
New Member
Posts: 7
Raspberry Pi: Yes
|
Post by blackcrow on Apr 11, 2020 4:20:38 GMT -8
I implemented the script but am not able to get it running.
getting:
sudo /etc/inti.d/skyweather start sudo: /etc/inti.d/skyweather: command not found
checked permissions, I know it is something simple, I set permissions 666 on the file...I am a linux basic user
|
|
smurphy
Full Member
Posts: 169
Raspberry Pi: Yes
Other Device: many ...
|
Post by smurphy on Apr 12, 2020 1:17:24 GMT -8
You need to set the permisions to 755 - set the executable bit. What you did is set the mode to everyone (user, group and world) writable. This means everyone (even anonymous users) could change/modify your script at will.
NEVER - EVER - user mode 666. This is the curse of Microsoft applied to unix type systems.
|
|
|
Post by doxidad on Apr 12, 2020 5:39:53 GMT -8
I implemented the script but am not able to get it running. getting: sudo /etc/inti.d/skyweather start sudo: /etc/inti.d/skyweather: command not found checked permissions, I know it is something simple, I set permissions 666 on the file...I am a linux basic user Also, beside permissions (need 755) look at your path it should be /etc/init.d not /etc/inti.d
|
|
blackcrow
New Member
Posts: 7
Raspberry Pi: Yes
|
Post by blackcrow on Apr 12, 2020 11:11:29 GMT -8
You need to set the permisions to 755 - set the executable bit. What you did is set the mode to everyone (user, group and world) writable. This means everyone (even anonymous users) could change/modify your script at will. NEVER - EVER - user mode 666. This is the curse of Microsoft applied to unix type systems. Yea, I wasn't intending to leave it there, just ensuring it wasn't a permissions issue! Thank you, I just changed back to 755 I checked again, same issue when attempting to execute /etc/init.d $ ls alsa-utils dphys-swapfile nfs-common splunk apache2 fake-hwclock paxctld ssh apache-htcacheclean haveged plymouth sudo avahi-daemon hostapd plymouth-log triggerhappy bluetooth hwclock.sh procps udev console-setup.sh keyboard-setup.sh raspi-config x11-common cron kmod rpcbind xrdp dbus lightdm rsync dhcpcd mysql rsyslog dnsmasq networking skyweather file is there, just not executing...I checked the path in the Python also, seems right, im missing something somewhere.
|
|
smurphy
Full Member
Posts: 169
Raspberry Pi: Yes
Other Device: many ...
|
Post by smurphy on Apr 13, 2020 5:23:45 GMT -8
Can you past here the content of the log-file -> skyweather.$DATE.log ? Should be in the same directory as the script itself. Also - if it still does not work - execut it like this: ` ~# /bin/sh -x /etc/init.d/skyweather ` and post the result here. It puts the script in debug mode.
|
|
blackcrow
New Member
Posts: 7
Raspberry Pi: Yes
|
Post by blackcrow on Apr 13, 2020 6:41:49 GMT -8
pi@CRWEATHER:~/SDL_Pi_SkyWeather $ /bin/sh -x /etc/init.d/skyweather start + : not found/skyweather: 3: /etc/init.d/skyweather: + : not found/skyweather: 13: /etc/init.d/skyweather: + : not found/skyweather: 15: /etc/init.d/skyweather: + date +%y%m%d.%H%M + TIME=200413.0940 + date +%y%m%d + DATE=200413 + echo 200413.0940 200413.0940 /etc/init.d/skyweather: 19: /etc/init.d/skyweather: Syntax error: word unexpected (expecting "in") pi@CRWEATHER:~/SDL_Pi_SkyWeather $
|
|
smurphy
Full Member
Posts: 169
Raspberry Pi: Yes
Other Device: many ...
|
Post by smurphy on Apr 13, 2020 10:01:20 GMT -8
Could it be that you copied the code from Windows? Windows will change the charact-set and break the actual code. What seems to be wrong is something around the
case "$1" in I suspect the " signs to have been converted bad by the copy&paste you probably did under Windows. Could also be other parts/chars that are broken (badly converted)
Last but not least, make sure the shell /bin/sh is really sh or bash. If it is "dash" it will be an issue.
|
|
blackcrow
New Member
Posts: 7
Raspberry Pi: Yes
|
Post by blackcrow on Apr 13, 2020 12:45:23 GMT -8
Could it be that you copied the code from Windows? Windows will change the charact-set and break the actual code. What seems to be wrong is something around the case "$1" in I suspect the " signs to have been converted bad by the copy&paste you probably did under Windows. Could also be other parts/chars that are broken (badly converted) Last but not least, make sure the shell /bin/sh is really sh or bash. If it is "dash" it will be an issue. I don't run Windows, i did it on Mac, but I will check again in brackets, I did copy from the webpage, maybe characters got jumbled
|
|
|
Post by Powderjockey on Apr 30, 2020 7:26:14 GMT -8
|
|