Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

name: unrecognized service under CentOS 6.5 #49

Closed
nifflin opened this issue Apr 17, 2017 · 19 comments
Closed

name: unrecognized service under CentOS 6.5 #49

nifflin opened this issue Apr 17, 2017 · 19 comments

Comments

@nifflin
Copy link

nifflin commented Apr 17, 2017

I use simplest example in README

https://github.com/takama/daemon#examples

After running the demo, I tried to stop this service with "service name stop", but returns error: "name: unrecognized service"

@takama
Copy link
Owner

takama commented Apr 17, 2017

Hi,
Did you use command service name start before?
service.Install() just create init.d script, nothing more.

@nifflin
Copy link
Author

nifflin commented Apr 17, 2017

The same error info.

I compiled simplest demo, and run it. And I found the "name.conf" under /etc/init/. But "service name status" or "service name start" still not work.

@takama
Copy link
Owner

takama commented Apr 17, 2017

If your service has been installed in CentoOS 6, it has file /etc/init.d/<service name>.
Do you have that file?

@nifflin
Copy link
Author

nifflin commented Apr 17, 2017

No. Only etc/init/ has name.conf file

@takama
Copy link
Owner

takama commented Apr 17, 2017

It means the service hasn't installed, possible cases:

  1. Permission denied to installation of the service, please use sudo command to start this example.
  2. Check file creation errors during execution of this example.

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

"sudo" still the same. And, the example print error message if error happened, but the app only print service install success message.

@takama
Copy link
Owner

takama commented Apr 18, 2017

The call of service.Install() should create /etc/init.d/<service name> file or return error message. Please look at code snippets:

// Standard service path for systemV daemons
func (linux *systemVRecord) servicePath() string {
	return "/etc/init.d/" + linux.name
}
// Install the service
func (linux *systemVRecord) Install(args ...string) (string, error) {

	srvPath := linux.servicePath()

	file, err := os.Create(srvPath)
	if err != nil {
		return installAction + failed, err
	}
	defer file.Close()

@takama
Copy link
Owner

takama commented Apr 18, 2017

Some questions:

  • Do you have /etc/init.d directory and some files into?
  • Did you compile the binary on linux system?
  • Could you send me result of the command strace -e trace=open <your executable file>?
    (If you don't have strace install it: yum install strace)

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

1、YES
2、NO,on OS X with env GOOS=linux arch=amd64 go build main.go
3、Output of strace -e trace=open ./main

--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=28966, si_status=0, si_utime=0, si_stime=0} ---

Install description: [ OK ]

+++ exited with 0 +++

@takama
Copy link
Owner

takama commented Apr 18, 2017

Sorry, other command strace -e trace=stat,openat ./main or full output of strace ./main

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

Output of strace -e trace=stat,openat ./main

stat("/run/systemd/system", 0xc42006a1d8) = -1 ENOENT (No such file or directory)
stat("/sbin/initctl", {st_mode=S_IFREG|0755, st_size=138784, ...}) = 0
stat("/usr/lib64/qt-3.3/bin/id", 0xc42006a378) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/id", 0xc42006a448) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/id", 0xc42006a518) = -1 ENOENT (No such file or directory)
stat("/sbin/id", 0xc42006a5e8) = -1 ENOENT (No such file or directory)
stat("/bin/id", 0xc42006a6b8) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/id", 0xc42006a788) = -1 ENOENT (No such file or directory)
stat("/usr/bin/id", {st_mode=S_IFREG|0755, st_size=32696, ...}) = 0
openat(AT_FDCWD, "/dev/null", O_RDONLY|O_CLOEXEC) = 3
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29572, si_status=0, si_utime=0, si_stime=0} ---
stat("/etc/init/main.conf", 0xc4200b0038) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/init/main.conf", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
stat("/usr/lib64/qt-3.3/bin/main", 0xc4200b0108) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/main", 0xc4200b01d8) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/main", 0xc4200b02a8) = -1 ENOENT (No such file or directory)
stat("/sbin/main", 0xc4200b0378) = -1 ENOENT (No such file or directory)
stat("/bin/main", 0xc4200b0448) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/main", 0xc4200b0518) = -1 ENOENT (No such file or directory)
stat("/usr/bin/main", 0xc4200b05e8) = -1 ENOENT (No such file or directory)
stat("/root/bin/main", 0xc4200b06b8) = -1 ENOENT (No such file or directory)
Install description: [ OK ]
+++ exited with 0 +++

Should I move main file to "/usr/local/sbin/" before running it?

And, there is a /etc/init/ usage, is this right?

return "/etc/init/" + linux.name + ".conf"

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

After moving main file to /usr/local/sbin/, output of strace -e trace=stat,openat main

stat("/run/systemd/system", 0xc42008a108) = -1 ENOENT (No such file or directory)
stat("/sbin/initctl", {st_mode=S_IFREG|0755, st_size=138784, ...}) = 0
stat("/usr/lib64/qt-3.3/bin/id", 0xc42008a2a8) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/id", 0xc42008a378) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/id", 0xc42008a448) = -1 ENOENT (No such file or directory)
stat("/sbin/id", 0xc42008a518) = -1 ENOENT (No such file or directory)
stat("/bin/id", 0xc42008a5e8) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/id", 0xc42008a6b8) = -1 ENOENT (No such file or directory)
stat("/usr/bin/id", {st_mode=S_IFREG|0755, st_size=32696, ...}) = 0
openat(AT_FDCWD, "/dev/null", O_RDONLY|O_CLOEXEC) = 3
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29665, si_status=0, si_utime=0, si_stime=0} ---
stat("/etc/init/main.conf", 0xc42008a858) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/init/main.conf", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
stat("/usr/lib64/qt-3.3/bin/main", 0xc42008a928) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/main", {st_mode=S_IFREG|0755, st_size=3313416, ...}) = 0
stat("/usr/local/sbin/main", {st_mode=S_IFREG|0755, st_size=3313416, ...}) = 0
Install description: [ OK ]
+++ exited with 0 +++

@takama
Copy link
Owner

takama commented Apr 18, 2017

Do you have upstart system installed on your VM?

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

It's a physical machine. CentOS release 6.5 (Final). Text UI.
I am not sure whether upstart installed or not. Is initctl version the correct way to check it?
Output of initctl version
init (upstart 0.6.5)

@takama
Copy link
Owner

takama commented Apr 18, 2017

In this case you should use initctl start <job> or initctl stop <job> instead of service <name> start or service <name> stop.
Another advantage is using of second example with integrated commands install, start, stop, remove. You could use <your executable> install, <your executable> start, etc

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

initctl start main works. But there are many .conf files under /etc/init.d, and almost all others services (like MySQL, iptables ...) can be managed by service start/stop/restart/status $SERVICE-NAME on this centos release. I think it's better to make service command working for my service.

If you need, I'd like to send you a temp CentOS 6.* vps account to check this issue.

@takama
Copy link
Owner

takama commented Apr 18, 2017

I see two solutions here:
Structural: adding possibility to prioritise of systems which installed from executable command line.
Quick: fork the daemon service, disable upstart module, recompile.

Can I close the ticket?

@nifflin
Copy link
Author

nifflin commented Apr 18, 2017

OK, if I really need a library like this repo, I will fork a new version and try to fix it. Thank you.

@nifflin nifflin closed this as completed Apr 18, 2017
@takama
Copy link
Owner

takama commented Apr 18, 2017

I have created the new issue #50 with label enhancement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants