I have an IoT device with a barebones Linux distro on it. No crontab
, chkconfig
, or update-rc
.
How would I go about running a script when the device has started, after everything on the device has been loaded? I thought I could just add the script to /etc/init.d
but nothing seems to happen. This is the script I'm using.
#! /bin/sh -e
# /etc/init.d/camstart
. /etc/init.d/functions.sh
start() {
/usr/local/packages/application/myapp
}
stop() {
kill `pidof myapp`
kill `pidof myappinternal`
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pidof myapp
pidof myappinternal
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
My other idea was to use /etc/rc.local
, but the device does not have that file. It has rc?.d
folders ranging from 1-6 and S. Placing scripts in any of them doesn't seem to have any affect.
Any suggestions?
EDIT: I'm not sure what Linux distro it is, but checking /etc/*release
tells me that it is based on Poky from the Yocto Project. From /proc/version
it's Linux version 4.9.62.
As far as I can tell, it uses systemctl
to start systemd
services.
EDIT2: Forgot to mention. I've tried writing a systemd
service for my script and starting it using systemctl start app
but it exits immediately with exit code 0
.
app.server:
[Unit]
Description=app
After=acap-pre.target
Requires=acap-pre.target
[Service]
Slice=extension-acap.slice
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/init.d/app start
ExecStop=/etc/init.d/app stop
FINAL EDIT: Got it to work after looking at How to write startup script for systemd and saw that my systemd service
was missing
[Install]
WantedBy=multi-user.target