sudo lshw -C network
and look for the line logical name: enp3s0
sudo nano /etc/network/interfaces
(nano - this little text editor) # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # My local network. allow-hotplug enp3s0 iface enp3s0 inet static address 172.16.55.1 netmask 255.255.255.0 gateway 172.16.55.1
service networking restart
sudo nano /etc/default/isc-dhcp-server
find the line INTERFACES=""
Is the interface name for the DHCP server. In our case it should be like this: INTERFACES="enp3s0"
sudo nano /etc/dhcp/dhcpd.conf
need to add subnet 172.16.55.0 netmask 255.255.255.0{ range 172.16.55.2 172.16.55.100; }
Within this subnet, the DHCP server will issue addresses in the range from 2 to 100. sudo nano /etc/hosts
should be spelled pc name and ip. Perhaps there is a more convenient way to get your own IP, but I did not succumb to it. 127.0.0.1 localhost 172.16.55.1 ubuntu
sudo cat /etc/hostname
and a million more ways. service networking restart
d:\"Program Files"\PuTTY\pscp.exe ubuntu@172.16.55.1:/home/ubuntu/tool/* "F:/WORK/SERVER/tool/"
d:\"Program Files"\PuTTY\pscp.exe "F:/WORK/SERVER/tool/*" ubuntu@172.16.55.1:/home/ubuntu/tool/
tar -xvf d3xx-linux-i686-0.5.0.tar.bz2
cd linux-i686 sudo rm -f /usr/lib/libftd3xx.so sudo cp -f libftd3xx.so /usr/lib sudo cp -f libftd3xx.so.0.5.0 /usr/lib sudo cp -f 51-ftd3xx.rules /etc/udev/rules.d sudo udevadm control --reload-rules
CC=g++ UNAME := $(shell uname) ifeq ($(UNAME), Darwin) DEPENDENCIES := -lpthread -ldl -lobjc -framework IOKit -framework CoreFoundation else DEPENDENCIES := -lpthread -ldl -lrt endif CFLAGS=$(DEPENDENCIES) -Wall -Wextra -std=c++11 STATLIB=libftd3xx.a APP = prgr all: $(APP) $(APP): main.o $(CC) -o $(APP) main.o $(STATLIB) $(CFLAGS) main.o: main.cpp $(CC) -c -o main.o main.cpp $(CFLAGS) clean: rm -f *.o ; rm $(APP)
make
ps -el
You will see a list of running programs with their PID. PID is a mandatory identifier of a running program, which the OS monitors for this program. In an extreme situation, you can bang the program on this PID from the terminal - write kill and PID (it can be useful for debugging). void SetPidFile(char* Filename) { FILE* f; f = fopen(Filename, "w+"); if (f) { fprintf(f, "%u", getpid()); fclose(f); } } int main( int argc, char** argv ) { char toolfile[32]; char folder[32]; intptr_t ret; FILE* logfile; if( argc!=3 ) { printf( "Write address of the program and name: /home/ubuntu/tool/ tool\n"); return -1; } pid_t pid, sid; pid = fork(); if (pid < 0) { sleep(1); return -1; } //We got a good pid, Close the Parent Process if (pid > 0) { return 0; } //Create a new Signature Id for our child sid = setsid(); if (sid < 0) { return -1; } //Change File Mask umask(0); //Save PID memcpy( toolfile, argv[0], strlen(argv[0]) ); memcpy( toolfile + strlen(argv[0]), ".log", 4 ); memset( toolfile + strlen(argv[0]) + 4, 0, 1 ); printf( "Daemon:: log to:%s\n", toolfile ); logfile = fopen( toolfile, "w" ); fprintf( logfile, "Daemon:: started with 0=%s 1=%s 2=%s\n", argv[0], argv[1], argv[2] ); memset( toolfile, 0, 32 ); memcpy( toolfile, argv[0], strlen(argv[0]) ); memcpy( toolfile + strlen(argv[0]), ".pid", 4 ); memset( toolfile + strlen(argv[0]) + 4, 0, 1 ); SetPidFile( toolfile ); fprintf( logfile, "Daemon:: PID=%u saved in the %s\n", getpid(), toolfile ); memset( folder, 0, 32 ); memcpy( folder, argv[1], strlen(argv[1]) ); fflush ( logfile ); memset( toolfile, 0, 32 ); memcpy( toolfile, folder, strlen(argv[1]) ); memset( toolfile + strlen(argv[1]), '/', 1 ); memcpy( toolfile + strlen(argv[1]) + 1, argv[2], strlen(argv[2]) ); //Change Directory //If we cant find the directory we exit with failure. if ((chdir(folder)) < 0) { fprintf( logfile, "Daemon:: Program folder was not found:%s\n", folder ); fclose( logfile ); return -1; } //Close Standard File Descriptors close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); fprintf( logfile, "Daemon:: Program started\n" ); fflush ( logfile ); ret = execl( toolfile, folder, NULL ); if( ret==-1 ) { fprintf( logfile, "Daemon:: execl error: %s. File=%s Folder=%s\n", strerror(errno), toolfile, folder ); fclose( logfile ); return -1; } fprintf( logfile, "Daemon:: closed\n" ); fclose( logfile ); return 0; }
sudo chmod 755 ./tool sudo chmod 755 ./daemon
sudo nano /etc/systemd/system/mydaemon.service
and write our script there. [Unit] Description=my service After=network.target After=isc-dhcp-server.service [Service] Type=forking PIDFile=/home/ubuntu/daemon/daemon.pid ExecStartPre=/bin/sh /home/ubuntu/daemon/prgr.strt ExecStart=/home/ubuntu/daemon/daemon /home/ubuntu/daemon/prgr prgr ExecStop=/bin/sh /home/ubuntu/daemon/prgr.stop Restart=always TimeoutSec=5 [Install] WantedBy=multi-user.target
systemctl daemon-reload systemctl status mydaemon
systemctl start mydaemon
systemctl enable mydaemon
Source: https://habr.com/ru/post/335042/
All Articles