0

I am trying to make a backup restore of gitlab and it kind of works but th command line always says that the restore of the repositories failed. I think I found the conditional statement in the code which responsible for the [failed] statement. Has someone a clue what this is doing or know a direction in which I should go to find my mistake?

 if Kernel.system("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1")
puts "[DONE]".green                                                                                                                                                               
          else                                                                                                                                                                                
            puts "[FAILED]".red                                                                                                                                                               
          end 
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
M. Petersen
  • 67
  • 1
  • 7

2 Answers2

1

Kernel.system calls the given shell command. When it fails it return a false value.

In your case it means git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1 fails.

You can check why it fails when you execute this command on the command line by hand without > /dev/null 2>&1 .

To get the command you can at a debug print before the command

if Kernel.system(pp("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1"))

slowjack2k
  • 2,566
  • 1
  • 15
  • 23
  • If I check with /dev/null 2>&1. I get the output: -bash: /dev/null: Permission denied I tried to change the chmod and chown of the dev/null and repo. But I still get the persmission denied message. What am I doing wrong? – M. Petersen Aug 10 '16 at 09:45
  • Is your host a bare metal machine or some kind of vm or container? It looks like your user has no write permission to /dev/null. Which OS do you use? – slowjack2k Aug 10 '16 at 09:48
  • I use a vm (shell in a box) – M. Petersen Aug 10 '16 at 09:49
  • I don't know your vm you can try `ls -l /dev/null` to check if this device exists. When it exists you don't have the permission to use. You have to ask your admin or the docs how to fix this issue. `>/dev/null 2>&1` is not realy important. It should only silence the comment. – slowjack2k Aug 10 '16 at 09:54
  • If chmod does not work, maybe you don't have the permission to change the permissions or some thing like apparmor prevents you from accessing this device. You can use `uname -a` to get more informations about your system. `ps -ef` can also tell some thing about whats going on on your vm. – slowjack2k Aug 10 '16 at 10:00
  • What do you mean with silence the comment? – M. Petersen Aug 10 '16 at 10:01
  • When you execute a command it often send some status informations to stdout or stderr. What you can see in the console. When you execute a command via script you don't need this aoutput, so you send it to "nirvana" aka `/dev/null`. You can replace `/dev/null` with every file you want for later use in your case, for instance `/tmp/output.txt` you only need sufficent write permissions for this file and enough free disk space. But keep in mind that you can leak confidential informations when you write data to a tmp folder. – slowjack2k Aug 10 '16 at 10:05
1

From the docs:

system returns true if the command gives zero exit status, false for non zero exit status. Returns nil if command execution fails. An error status is available in $?.

That said: Falling into constantly in the failing state means that the system command returned false or nil. You might want to check $? for the reason:

command = Kernel.system("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1")
if command
  puts "[DONE]".green
else
  puts "[FAILED]".red
  puts "Reason:"
  puts $?
end 
spickermann
  • 100,941
  • 9
  • 101
  • 131
  • If I do this I get the ouput: pid 7169(every pid has a diffrent number) exit 128 (all exits have the same number) – M. Petersen Aug 10 '16 at 10:03
  • When you get error code 128 [this question and the answers](https://stackoverflow.com/questions/9617336/how-to-resolve-git-did-not-exit-cleanly-exit-code-128-error-on-tortoisegit) might be of interest for you. – spickermann Aug 10 '16 at 10:39