I want to let the sslocal start auto since PC boot. Then I append a line of command to /etc/profile as follows /usr/local/bin/sslocal -c /etc/config.json -d start. But when I reboot, error occurs: Permission denied:/var/run/shadowsocks.pid.I know the script I appended needs the root privilege. Because sslocal will write a new file named shadowsocks.pid in the directory of /var/run/, and when I execute the script by root user in the terminal directly, it goes well. It seems that there is not enough privilege after I append it to the /etc/profile.So, how can I let the script automatic run since boot? Someone suggested that I edit the /etc/rc.local, but it doesn't work. My system is Ubuntu 16.04 and here are the contents of /etc/rc.local (with file permissions of 755).#!/bin/dash -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will exit 0 on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.sudo /usr/local/bin/sslocal -c /etc/shadowsocks.json -d startexit 0
Errors when trying to start a program at bootup
linux;ubuntu;terminal
I was trying to install shadow-sockets to my PC. The problem I encountered is how to let the shadow-socket's service run auto when my PC is start. The service start command is sudo /usr/local/bin/sslocal -c /etc/shadowsocks.json -d start (Because the command will write a new file in the directory /var/run/, which result in its sudo privilege).SolutionThe easiest way of making a script run auto with PC start is to write it into /etc/profile. So, like the content of problem's description, I added the whole command line along with sudo above the exit 0 line. Check if it worksAfter you rebooted your computer, enter the following command in terminal sudo systemctl status rc-local.service.If your sslocal command works then you will get this ouput:>rc-local.service - /etc/rc.local CompatibilityLoaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2015-11-27 03:19:25 CST; 2min 39s agoProcess: 881 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)CGroup: /system.slice/rc-local.service 887 watch -n 60 su matrix -c ibam1112 /usr/bin/python /usr/local/bin/sslocal -c /etc/shadowsocks....As you can see from the last line, the sslocal command created a process whose pid is 1112 on my machine. It means shadow-socks client is running smoothly. 