I developed a crawler in PHP that parse an URL with specific headers and put all URLs of content in the queue. It works fine.
I developed this code in a ubuntu 14.04 and I put a .conf file in /etc/init folder with this content:
# Info
description "Warm the varnish to get the list of products"
author "Juanjo Aguilella"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
respawn limit 100 5
# Run the script
# Note, in this example, if your PHP script return
# the string "ERROR", the daemon will stop itself.
script
[ $(exec /usr/bin/php -f /var/www/crawler.php) = 'ERROR' ] && ( stop; exit 1; )
end script
It works fine in Ubuntu 14.04 and I can start and stop the daemon using "sudo service crawler start" and "sudo service crawler stop"
Now in production environment I have a Ubuntu 16.04 server and I put the same code on the same folder but when I try to start the service I receive the message "Failed to start crawler.service. Unit crawler.service not found"
Can you give me any help about it?
Regards
Adding to @Juanjo Aguilella Marés answer, and once you have copied/linked your script to
/etc/systemd/system
, you may want to automatically start it when the server starts:Source Digital Ocean
It is also a good idea not to run it as root. Just change the
user
line on your script:I solved the problem:
a) Create a file crawler.service in /etc/systemd/system with this code:
my bash file contains a diferent executations on parallel to the same php file with this code:
the sleep between execitions es necessary to save the problem about the execution so fast of the service.
If you have any suggestion about the solution, please comment, I dont have a lot of experience in bash files and systemd files, but at the moment works fine.
The init system for 14.04 is upstart. The init system for 16.04 is systemd. You should convert your upstart script to a systemd unit file. There are plenty of other resources available too.
1]. To create a service go to /etc/systemd/system/
2]. Create a file of serviceName e.g chatSocket.service
3]. Put content to file as given bellow
4]. Reload configuration by hitting:
sudo systemctl daemon-reload
5]. Enable service by default so when system start service will automatically start:
sudo systemctl enable my_service.service
6]. Start your service by using command below:
sudo systemctl start my_service.service