Answer the question
In order to leave comments, you need to log in
Why are scripts loaded twice on load?
Good afternoon.
There is a computer whose task is to execute only a certain program in java.
I wrote a simple script to run it:
[email protected]:~# cat /etc/init.d/bggate
#! /bin/sh
### BEGIN INIT INFO
# Provides: bggate
# Required-Start: sshd
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
echo `date`: 0:$0 1:$1 2:$2 3:$3 4:$4 RL:`runlevel` >> /root/runlog
case "$1" in
start)
sudo -H -u root nohup /opt/jdk/bin/java -jar /opt/bggate/BGGate.jar 1>/root/log 2>&1 &
;;
stop)
pkill java
;;
status)
ps -f -C java
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/bggate {start|stop|status|restart}"
exit 1
;;
esac
exit 0
echo `date`: 0:$0 1:$1 2:$2 3:$3 4:$4 RL:`runlevel` >> /root/runlog
):[email protected]:~# cat /root/runlog
Mon Sep 26 17:19:38 MSK 2016: 0:/etc/rc6.d/K20bggate 1:stop 2: 3: 4: RL:2 6
Mon Sep 26 17:20:14 MSK 2016: 0:/etc/rc2.d/S20bggate 1:start 2: 3: 4: RL:N 2
Mon Sep 26 17:22:15 MSK 2016: 0:/etc/rc2.d/S20bggate 1:start 2: 3: 4: RL:N 2
[email protected]:~# uname -a
Linux BGGate 3.4.39-01-lobo #1 SMP PREEMPT Sun Oct 25 14:51:50 CET 2015 armv7l armv7l armv7l GNU/Linux
[email protected]:~# cat /proc/version
Linux version 3.4.39-01-lobo ([email protected]) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NG linaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #1 SMP PREEMPT Sun Oct 25 14:51:50 CET 2015
[email protected]:~# ls -l /etc/rc2.d
total 4
-rw-r--r-- 1 root root 677 Feb 17 2016 README
lrwxrwxrwx 1 root root 17 Aug 31 13:51 S16openvpn -> ../init.d/openvpn
lrwxrwxrwx 1 root root 16 Sep 26 16:29 S20bggate -> ../init.d/bggate
lrwxrwxrwx 1 root root 15 Sep 8 16:31 S20osspd -> ../init.d/osspd
lrwxrwxrwx 1 root root 15 Aug 28 2015 S20rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root 24 Sep 8 21:27 S20screen-cleanup -> ../init.d/screen-cleanup
lrwxrwxrwx 1 root root 13 Aug 28 2015 S23ntp -> ../init.d/ntp
lrwxrwxrwx 1 root root 16 Sep 8 19:56 S60motion -> ../init.d/motion
lrwxrwxrwx 1 root root 18 Aug 28 2015 S99ondemand -> ../init.d/ondemand
lrwxrwxrwx 1 root root 18 Aug 28 2015 S99rc.local -> ../init.d/rc.local
[email protected]:~# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# ** Overclock to 1.728 GHz
#echo 1728000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo 0 > /proc/sys/kernel/hung_task_timeout_secs
#sudo -H -u root nohup /opt/jdk/bin/java -jar /opt/bggate/BGGate.jar 1>/root/log 2>&1 &
dmesg -n 1
exit 0
Answer the question
In order to leave comments, you need to log in
Maybe it's worth implementing a check if the program is running?
in init.d - directories for each runlevel are used - most likely you have two symlinks per script in rc.2 , with different call numbers.
According to the rules, you yourself must check whether the script is running, since you have abandoned the start-stop-daemon daemon manager .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question