CLion Full Remote Mode with FreeBSD as the remote host - c++

Currently, the Full Remote Mode of CLion only supports Linux as a remote host OS. Is it possible to have a FreeBSD remote host?

Yes, you can!
However, note that I'm recalling these steps retrospectively, so probably I have missed one step or two. Should you encounter any problem, please feel free to leave a comment below.
Rent a FreeBSD server, of course :)
Update your system to the latest release. Otherwise, you may get weird errors like "libdl.so.1" not found when installing packages. The one I'm using is FreeBSD 12.0-RELEASE-p3.
Create a user account. Don't forget to make it a member of wheel, and uncomment the %wheel ALL=(ALL) ALL line in /usr/local/etc/sudoers.
Set up SSH. This step is especially tricky, because we need to use both public-key and password authentication.
Due to a known bug, in some cases, the remote host must use password authentication, or you'll get an error when setting up the toolchain. You can enable password authentication by setting PasswordAuthentication yes in /etc/ssh/sshd_config, followed by a sudo /etc/rc.d/sshd restart.
It appears that CLion synchronizes files between the local and remote host with rsync and SSH. For some reasons I cannot explain, this process will hang forever if the host server doesn't support passphrase-less SSH key login. Follow this answer to create an SSH key as an additional way of authentication.
CLion assumes the remote host OS to be Linux, so we must fix some incompatibilities between GNU/Linux and FreeBSD.
Install GNU utilities with sudo pkg install coreutils.
Rename the BSD utility stat with sudo mv /usr/bin/stat /usr/bin/_stat.
Create a "new" file /usr/bin/stat with the content in Snippet 1. This hack exploits the fact that CLion sets the environment variable JETBRAINS_REMOTE_RUN to 1 before running commands on the remote server.
Do sudo chmod a+x /usr/bin/stat to make it executable.
Again, rename the BSD utility ls with sudo mv /bin/ls /bin/_ls.
Create a "new" file /bin/ls with the content in Snippet 2, like before.
Lastly, sudo chmod a+x /bin/ls.
Install the dependencies with sudo pkg install rsync cmake gcc gdb gmake.
Now you can follow the official instructions, and connect to your shiny FreeBSD host!
Snippet 1
#!/bin/sh
if [ -z "$JETBRAINS_REMOTE_RUN" ]
then
exec "/usr/bin/_stat" "$#"
else
exec "/usr/local/bin/gnustat" "$#"
fi
Snippet 2
#!/bin/sh
if [ -z "$JETBRAINS_REMOTE_RUN" ]
then
exec "/bin/_ls" "$#"
else
exec "/usr/local/bin/gls" "$#"
fi

Additionally you need to fix one more incompatibility between GNU/Linux and FreeBSD.
Check gtar is installed if no pkg install gtar
Rename the BSD utility tar with mv /usr/bin/tar /usr/bin/_tar
Create a "new" file /usr/bin/tar with the content in Snippet 3, like before.
Lastly, sudo chmod a+x /usr/bin/tar
Snippet 3
#!/bin/sh
if [ -z "$JETBRAINS_REMOTE_RUN" ]
then
exec "/usr/bin/_tar" "$#"
else
exec "/usr/local/bin/gtar" "$#"
fi

Starting CLion 2020.1 the instruction regarding gnustat and "ls" is not relevant anymore. Because CLion 2020.1 includes the proper fixes in jsch-nio library (https://github.com/lucastheisen/jsch-nio/commit/410cf5cbb489114b5da38c7c05237f6417b9125b)
Starting CLion 2020.2 doesn't use tar --dereference option, so the instruction regarding gtar (gnutar) is also not relevant anymore.

Related

How to use sys/mount to mount a NFS system?

So, I am trying to connect two Ubuntu computers using a NFS connection
On the server, I made the following
Install NFS Server on Ubuntu
$ sudo apt-get install nfs-kernel-server portmap
Export shares over NFS
$ sudo mkdir /opt/share
$ sudo chown nobody:nogroup /opt/share
Edit the NFS server exports configuration file
$ sudo gedit /etc/exports
Add the following settings
/home 192.168.0.0/24(rw,sync,no_root_squash,no_subtree_check)
/opt/share 192.168.0.0/24(rw,sync,no_subtree_check)
Apply the new settings by running the following command. This will export all directories listed in /etc/exports file
$ sudo exportfs -a
On the client side, I tried to use the sys/mount library to make the NFS connection
if(mount(":/mnt/share","/opt/share","nfs",0,"nolock,addr=192.168.0.101") == -1)
{
printf("NFS ERROR: mount failed: %s \n",strerror(errno));
}
else
{
printf("NFS connected\n");
}
But it returns
m#m-ThinkPad-L15-Gen-2:~/Desktop/teste$ sudo ./mountnfs
NFS ERROR: mount failed: Permission denied
Does anybody have any clue of what is happening?
According to the documentation:
Linux: the CAP_SYS_ADMIN capability is required to mount file systems.
And according to this page, you can add that capability to your program using something along the lines of the following command (each time after you build it, probably):
sudo setcap CAP_SYS_ADMIN+ep /path/to/your/binary
That's the gist of it anyway, but you might need to a bit more digging to find the optimal solution - in which case you can answer your own question.
Also, what's that leading : doing in your source parameter? Most likely I just don't understand the syntax, but it looks a bit weird to me.

How to use screen in google cloud startup script?

So I decided to follow this minecraft server guide, and I'm stuck on the part linked "Automate startup and shutdown procedures". It doesn't start the server. I have tried by replacing code with a simple mkdir, which works. So I know it is being executed.
Yet I can't connect to the screen screen -list, (both when going into sudo and my own user). I checked the /run/screen/ folder and there's no other user.
It means it's safe to say that it fails, and not something I set up wrong.
The code I am using is the exact copy without the mounting nor the backup.
#!/bin/bash
sudo su
cd /home/minecraft
screen -d -m -S mc java -Xms3G -Xmx7G -d64 -jar paper.jar nogui
Shouldn't this work?
EDIT: It works and I pasted the exact code I used. NOTE: I do use PaperMC, and a upgraded machine.
I tried minecraft server guide myself and its worked properly.
At the first time, I didnt find my mcs screen with screen -list but I remembered that GCE always executes startup scripts as root after the network is available.
So my next step was simply to change my user for root with the command sudo su and from this point, my mcs screen was available with screen -list.
note that you can also use sudo screen -list
I hope that will help, if not, what is your command output when its executed on your shell?:
screen -d -m -S mc java -Xms1G -Xmx3G -d64 -jar server.jar nogui

How to start odoo server automatically when system is ON

Haii everyone
How to start Odoo server automatically when system is ON.
Normally i searched in google i had found a link " http://www.serpentcs.com/serpentcs-odoo-auto-startup-script-322 "
i follow the each and every step and i started the odoo-server
ps -ax | grep python
5202 ? Sl 0:01 python /home/tejaswini/Odoo_workspace/workspace_8/odoo8/openerp-server --config /etc/odoo-server.conf --logfile /var/log/odoo-server.log
it is showing the server path also
but when i run 0.0.0.0:8069/localhost:8069 in browser it is running
shows This site can’t be reached
please any one help me
Thanks in advance
To start a service automatically when the system turns on, you need to put that service into init script. Try below command
sudo update-rc.d <service_name> defaults
In your case,
sudo update-rc.d odoo-server defaults
Hope it will help you.
For the final step we need to install a script which will be used to start-up and shut down the server automatically and also run the application as the correct user. There is a script you can use in /opt/odoo/debian/init but this will need a few small modifications to work with the system installed the way I have described above. here is the link
Similar to the configuration file, you need to either copy it or paste the contents of this script to a file in /etc/init.d/ and call it odoo-server. Once it is in the right place you will need to make it executable and owned by root:
sudo chmod 755 /etc/init.d/odoo-server
sudo chown root: /etc/init.d/odoo-server
In the configuration file there’s an entry for the server’s log file. We need to create that directory first so that the server has somewhere to log to and also we must make it writeable by the openerp user:
sudo mkdir /var/log/odoo
sudo chown odoo:root /var/log/odoo
reference

Startup script logs location

In Google Cloud Platform's Ubuntu 16.04.1 instance, the output of my startup script was written to /var/log/startupscript.log.
Since they upgraded to 16.04.02 I can't find the logs anymore.
Any idea?
UPDATE from the official documentation:
Startup script output is written to the following log files:
CentOS and RHEL: /var/log/messages
Debian: /var/log/daemon.log
Ubuntu 14.04, 16.04, and 16.10: /var/log/syslog
SLES 11 and 12: /var/log/messages
The correct answer (by now) is to use journalctl:
sudo journalctl -u google-startup-scripts.service
You can re-run a startup script like this:
sudo google_metadata_script_runner startup
See also: https://cloud.google.com/compute/docs/instances/startup-scripts/linux
There are two ways to search for the log file probably a lot more but i know the below.
locate -i startupscript.log - you may need to update your indexes periodically for this option to be optimal.
From root find / -iname startupscript.log -print .

Run sudo command in Qt QProcess

I am developing a software in Qt in which I created a terminal. I run different commands through QProcess in that but when I run root commands it ask for password in terminal. I tried to run via sudo but it only accepts password in terminal. Is there any way to give password from another source like pop up widget or a text file?
I have created a QProcess with "bash" as program.
Then just write to it:
echo mypassword | sudo -S ifconfig eth0 192.168.1.123\n
You could try
Running your application as root (which is really a very bad idea, actually!)
Edit sudoers file and add the commands you want to run to this file. Then you can run these commands like sudo run_x_cmd with no password i.e, your QProcess can run these commands and you won't be asked for password.
Adding a password to a text file in order to source input for the command is a very bad idea, as it weakens security.
Version 1.8 of sudo provides a plugin architecture, which would allow you to link to it from your application and may provide a solution for you.
The SDK for the sudo plugin API can be found in the documentation .