Launch ./start.sh on startup , or like a service ?
-
Hello, i would like to know how to lauch MyContoller on startup , like a service or another way.
Thanks ,
Best regards. -
which OS are you using?, if it is linux, you can add the startup script to the startup scripts env in /etc.
I will have a look and keep you posted..
-
Sorry, on linux.
Should i use something like thissudo cp start.sh /etc/init.d
sudo chmod +x /etc/init.d/start.sh
sudo update-rc.d start.sh defaultsTo start
sudo /etc/init.d/start.sh start
To stop
sudo /etc/init.d/start.sh stop
Maybe rename start.sh to mycontroller.sh ?
Is there no probleme with user and path to find mycontroller ?
Thanks .
-
Here is how i got all working.
- Start your favorite editor (nano or vi) and make a file called mycontroller in /etc/init.d
sudo vi /etc/init.d/mycontroller
- copy the following text into the file (Make sure to get the path to mycontroller right!! in my case i used /home/user/mycontroller)
#! /bin/sh # /etc/init.d/mycontroller ### BEGIN INIT INFO # Provides: mycontroller # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO # The following part always gets executed. # echo " Mycontroller rocks!!" # The following part carries out specific functions depending on arguments. case "$1" in start) echo "Starting Mycontroller" /home/user/mycontroller/bin/start.sh ;; stop) echo "Stopping Mycontroller" /home/user/mycontroller/bin/stop.sh ;; *) echo "Usage: /etc/init.d/mycontroller {start|stop}" exit 1 ;; esac exit 0
- Make the file executable:
sudo chmod 755 /etc/init.d/mycontroller
- Now add the script to the initd environment:
sudo update-rc.d mycontroller defaults
- Test the script with the commands below:
sudo /etc/init.d/mycontroller start
and after mycontroller has started successfully:
sudo /etc/init.d/mycontroller stop
If troubleshooting is required/ search for mycontroller in /var/log/syslog this is the file where all output massages will appear.
That should do the trick, depending on your version of linux, (in mycase armbian) it might be that a different startup mechanism is used.
Tested all on an OrangPI Zero running armbian (Jesse) and RaspberryPI running Ubuntu Mate 15.10 both mycontroller applications are "up" after a reboot.
-
@Tag Wonderfull !
Just had this error :
insserv: warning: script 'mycontroller' missing LSB tags and overrides
I had to add this at the beginning :
### BEGIN INIT INFO # Provides: MyController domotique # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO
-
Yes i saw that one to, it can be safely ignored, but will add it to the install steps.
Thanks for reminding! -
@Tag
Finally does not start at boot , missing something or, INIT is not correctly set.
chkconfig -l display this :mountnfs.sh 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on mycontroller 0:off 1:off 2:on 3:on 4:on 5:on 6:off network-manager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
have a look later .
Best regards -
What is your current runlevel? , check with the command
runlevel
Mycontroller is only started in runlevel 2-5 so if you enter runlevel 0,1 or 6 mycontroller is stopped. (make the changes in the top of the script..)
Another issue might be that the cript itself in incorrect.... make sure that the startup script starts with
#!/bin/sh
This is really important.
So the complete file should look like this:
#! /bin/sh # /etc/init.d/mycontroller ### BEGIN INIT INFO # Provides: mycontroller # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO # The following part always gets executed. #echo "This part always gets executed" # The following part carries out specific functions depending on arguments. case "$1" in start) echo "Starting Mycontroller" /home/user/mycontroller/bin/start.sh ;; stop) echo "Stopping Mycontroller" /home/user/mycontroller/bin/stop.sh ;; *) echo "Usage: /etc/init.d/mycontroller {start|stop}" exit 1 ;; esac exit 0
If you execute the following command,
grep -i mycontroller /var/log/syslog
what is the output?
(if no output, look into an older file like i.e syslog.1)In my case the output is:
root@orangepizero:~# grep -i mycontroller /var/log/syslog.1 Feb 25 11:27:40 localhost mycontroller[474]: Starting Mycontroller Feb 25 11:27:40 localhost mycontroller[474]: /usr/bin/java Feb 25 11:27:43 localhost mycontroller[474]: java version: 1.8.0_121 Feb 25 11:27:43 localhost mycontroller[474]: Start issued for Mycontroller
-
@Tag said:
Another issue might be that the cript itself in incorrect.... make sure that the startup script starts with
#!/bin/sh
This is really important.Yes , it was that !
Got also Orange Pi Zero
-
Great!! good luck!, orangepizero is really great, and is powerfull enough to run mycontroller