Problem
I need to send a message to a a server via a TCP socket during computer startup. We are using Ubuntu 14.04 and therefore, by default, must use Upstart as the system initialization. (We also have other computers running Ubuntu 16.04 that can use systemd, so I'm trying to keep the shell scripts separate from the system initialization file)
Current Solution
Currently I'm using two files for the clients: an upstart .conf file and a shell script file.
Upstart file
The upstart file (we will call it foo.conf) has the following contents:
#!upstart
description "Send Message on Startup"
start on (local-filesystems
and net-device-up
and runlevel [2345])
exec /opt/foo/foo.sh
Shell File
The shell file (we will call it foo.sh) has the following contents
#!/bin/bash
echo "Sending update message..."
echo "Message" | nc server-hostname 9999
echo "Completed sending update message."
Symptoms
When I reboot the computer that has these files, I get the following in the log file:
Sending update message...
Completed sending update message.
However, the server never receives the message.
The Question
Currently, this solution is not working. I'm looking for suggestions on either how to get this solution to work or other suggestions to accomplish the same task.
UPDATE: systemd file
Here are the details of the systemd service unit file that I have deployed on Ubuntu 16.04 box. This one works on every reboot.
[Unit]
Description=Send Message on Startup
After=network-online.target
[Service]
Type=oneshot
ExecStart=/opt/foo/foo.sh
[Install]
WantedBy=multi-user.target