Jump to content

NodeLink systemd start script for Pi


apnar

Recommended Posts

Posted

I whipped up the config file below for those that would like to integrate NodeLink into the systemd service management framework on their Pis as opposed to just adding it to rc.local.  There are a few advantages to doing it this way including:

 

- be sure network is up before process starts

- can easily start/stop and get status of service

- can use same commands to interact with the service as other system services

- automatically restart the service if it dies for some reason

 

I put NodeLink.exe in /opt/nodelink, adjust the file accordingly if you use a different location.  Also be sure to remove any old lines you have in rc.local and kill any currently running NodeLink processes.

 

Here is the config file which you should name /etc/systemd/system/nodelink.service:

[Unit]
Description=NodeLink Server
Documentation=http://automationshack.com/nodelink.html
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /opt/nodelink/NodeLink.exe
Restart=always

[Install]
WantedBy=multi-user.target

With the file there you then enable the service with this command:

systemctl enable nodelink.service

From here you can start/stop/restart/status with similar commands:

systemctl start nodelink

systemctl stop nodelink

systemctl restart nodelink

systemctl status nodelink

For those not as technical you can simply copy and paste the below text into your terminal as root and be good to go (assuming you have NodeLink.exe in /opt/nodelink):

cat > /etc/systemd/system/nodelink.service <<EOF
[Unit]
Description=NodeLink Server
Documentation=http://automationshack.com/nodelink.html
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /opt/nodelink/NodeLink.exe
Restart=always

[Install]
WantedBy=multi-user.target
EOF

systemctl enable nodelink.service
systemctl start nodelink

Posted

Very nice.  Thank you.  I will be changing mine over to this method.

 

-Xathros

  • 3 weeks later...
  • 4 months later...
Posted

I've tried to do this (the less technical version as I'm just starting with the pi) and I can't get it to work.

I keep getting access denied.  tried to put sudo before it as I don't know how else to get root on the pi.

 

I followed the setup doc here: http://automationshack.com/Files/Raspbian_Setup_V5.pdf

so I have use "mono ~/node/NodeLink.exe" to start the program.

Won't work without the ~.

So I tried to modify your script to use the same, but still access denied.

 

Anybody have any clue what I'm doing wrong?

Posted

~ is a shortcut that means "current users home directory" so you usually avoid them in system level scripts since the user who starts things at boot is rarely the same as the user who would run the command by hand.  Try replacing the " ~/node/NodeLink.exe" with "/home/pi/node/NodeLink.exe".

 

Specifically you can type this out (differs from above in that it uses "/home/pi/node" instead of "/opt/nodelink" for directory):

sudo su -
[enter your password]

# everything below this you should be able to copy/paste

cat > /etc/systemd/system/nodelink.service <<EOF
[Unit]
Description=NodeLink Server
Documentation=http://automationshack.com/nodelink.html
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /home/pi/node/NodeLink.exe
Restart=always

[Install]
WantedBy=multi-user.target
EOF

systemctl enable nodelink.service
systemctl start nodelink
  • 4 weeks later...
  • 6 months later...
Posted

I had occasion today to install OWFS on a new Pi. When it came time to write the init script, I realized I should update from init.d to systemd, and this script came to mind. I first tried simply replacing the ExecStart call in this script with the OWFS command, but it failed. However, after a little digging, I discovered that by changing the service Type from Simple to Forking, it worked (apparently OWFS forks the process, then the initial process dies but the second process remains as the service -- there are 2 PIDs if you "sudo systemctl owfs status" -- and a Simple service type can't deal with multiple processes).

 

In any case, here's the script: 

 

sudo nano /etc/systemd/system/owfs.service (Name it anything you want, just put ".service" at the end. I chose owfs.)

[Unit]
Description=OneWireFileSystem
Documentation=http://owfs.org
After=network-online.target

[Service]
Type=forking
ExecStart=/opt/owfs/bin/owfs -F --i2c=ALL:ALL --allow_other /mnt/1Wire
Restart=always

[Install]
WantedBy=multi-user.target

sudo chmod 664 /etc/systemd/system/owfs.service

 

sudo systemctl daemon-reload

 

sudo systemctl start owfs

 

That should bring your OWFS startup script to the new systemd standard.

  • 9 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...