apnar Posted January 5, 2016 Posted January 5, 2016 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
Xathros Posted January 5, 2016 Posted January 5, 2016 Very nice. Thank you. I will be changing mine over to this method. -Xathros
danbutter Posted June 1, 2016 Posted June 1, 2016 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?
apnar Posted June 1, 2016 Author Posted June 1, 2016 ~ 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
danbutter Posted June 1, 2016 Posted June 1, 2016 Ahh ok. That did it! I was confused about the directory structure. Thanks for the help!
builderb Posted January 9, 2017 Posted January 9, 2017 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.
shbatm Posted October 24, 2017 Posted October 24, 2017 @apnar Thanks for sharing this! I wish I would have thought to search this forum before creating my own version. Dropping this version here in case anyone is interested: https://gist.github.com/shbatm/7d539dc53fdc9023e4a19bda192ab70d The biggest difference is mine has a small script to install the service based on whatever directory you happen to put the NodeLink.exe file in.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.