Page 1 of 1

perl script mixed in with a service

Posted: Fri Apr 08, 2016 9:50 am
by vk4tec
Hello

I have a service in /etc/init.d

I want to tag on a perl script to run in the "start" condition of a script

Like service dump1090 start

This starts up dump1090 plus the perl script. Do I just add the perl script in the start section of

/etc/init.d/dump1090?

I think u need sudo for "service" ?

Andrew

Re: perl script mixed in with a service

Posted: Fri Apr 08, 2016 1:54 pm
by solar3000
just make the file executable and name it somefile.pl
it should run like any script.

Re: perl script mixed in with a service

Posted: Sat Apr 09, 2016 12:42 pm
by DougieLawson
solar3000 wrote:just make the file executable and name it somefile.pl
it should run like any script.
The file name doesn't matter. somefile or somefile.pl or some.file.with.a.made-up.suffix.xyzzy will all execute in exactly the same way.

The crucial part of getting a perl program running is the shebang (#!) line at the top of the file and giving the file the executable permission bits.

Code: Select all

#!/usr/bin/perl
or

Code: Select all

#!/usr/bin/env perl
both work.

Re: perl script mixed in with a service

Posted: Sat Apr 09, 2016 12:57 pm
by DougieLawson
vk4tec wrote: Do I just add the perl script in the start section of

/etc/init.d/dump1090?
1. Everything run as an init.d script runs as root until your program changes it. You don't need sudo.
2. The stuff in /etc/init.d/xxx is a bash script that gets your real program running as a service
3. Do NOT add your perl program in your /etc/init.d script, store your perl program in /usr/local/bin
4. With Raspbian Jessie and Ubuntu MATE stop using /etc/init.d, write a systemd service file and get that starting your service. It's a whole bunch easier that init.d anyway (once you've got your first service running).

https://www.digitalocean.com/community/ ... he-journal
https://www.digitalocean.com/community/ ... unit-files