Mattermost, Inc.

Custom plugin failed to start

I have success upload my plugin to mattermost server(version 5.9.6,Installed on ubuntu16.04).And It shows a error message after I click upload,which goes like :This plugin failed to start. Check your system logs for errors.
the server log error is:
{“level”:“error”,“ts”:1576483016.174209,“caller”:“app/plugin.go:97”,“msg”:“Unable to activate plugin”,“plugin_id”:“mymattermostplugin”,“error”:“unable to start plugin: mymattermostplugin: fork/exec plugins/mymattermostplugin/plugin: permission denied”,“errorVerbose”:“fork/exec plugins/mymattermostplugin/plugin: permission denied\nunable to start plugin: mymattermostplugin\ngithub.com/mattermost/mattermost-server/plugin.(*Environment).Activate\n\t/go/src/github.com/mattermost/mattermost-server/plugin/environment.go:216\ngithub.com/mattermost/mattermost-server/app.(*App).SyncPluginsActiveState\n\t/go/src/github.com/mattermost/mattermost-server/app/plugin.go:95\ngithub.com/mattermost/mattermost-server/app.(*App).InitPlugins\n\t/go/src/github.com/mattermost/mattermost-server/app/plugin.go:126\ngithub.com/mattermost/mattermost-server/app.(*Server).RunOldAppInitalization.func6\n\t/go/src/github.com/mattermost/mattermost-server/app/server_app_adapters.go:143\ngithub.com/mattermost/mattermost-server/app.(*Server).InvokeConfigListeners\n\t/go/src/github.com/mattermost/mattermost-server/app/config.go:169\ngithub.com/mattermost/mattermost-server/app.(*Server).UpdateConfig\n\t/go/src/github.com/mattermost/mattermost-server/app/config.go:58\ngithub.com/mattermost/mattermost-server/app.(*App).UpdateConfig\n\t/go/src/github.com/mattermost/mattermost-server/app/config.go:62\ngithub.com/mattermost/mattermost-server/app.(*App).EnablePlugin\n\t/go/src/github.com/mattermost/mattermost-server/app/plugin.go:245\ngithub.com/mattermost/mattermost-server/api4.enablePlugin\n\t/go/src/github.com/mattermost/mattermost-server/api4/plugin.go:187\ngithub.com/mattermost/mattermost-server/web.Handler.ServeHTTP\n\t/go/src/github.com/mattermost/mattermost-server/web/handlers.go:151\ngithub.com/mattermost/mattermost-server/web.(*Handler).ServeHTTP\n\t:1\ngithub.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux.(*Router).ServeHTTP\n\t/go/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/mux/mux.go:162\ngithub.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.recoveryHandler.ServeHTTP\n\t/go/src/github.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers/recovery.go:78\ngithub.com/mattermost/mattermost-server/vendor/github.com/gorilla/handlers.(*recoveryHandler).ServeHTTP\n\t:1\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2741\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1847\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1333”}

Can someone help me please.

My plugin code is:

package main
import (
    "fmt"
    "io"
    "net/http"
    "github.com/mattermost/mattermost-server/model"
    "github.com/mattermost/mattermost-server/plugin"
)

type HelloWorldPlugin struct {
    plugin.MattermostPlugin
}
func (P *HelloWorldPlugin) ServerHttp(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello World!")
}
func (P *HelloWorldPlugin) FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string) {
    flag1 := info.Extension == "jpg"
    flag2 := info.Extension == "png"
    if flag1 == false && flag2 == false {
        s := "server only receiver jpg or png file"
        return nil, s
    }
    return nil, ""
}
func main() {
    plugin.ClientMain(&HelloWorldPlugin{})
}

my plugin.json is:

{

    "id": "MyMattermostPlugin",

    "name": "FileTest",

    "server": {

        "executable": "plugin"

    }

}

I craft the code in Windows10,And I build it like this:

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build -o plugin

Hi, @xiagao

The error that we are seeing here is related to permission denied when the server tries to activate the plugin:

“level”:“error”,“ts”:1576483016.174209,“caller”:“app/plugin.go:97”,“msg”:“Unable to activate plugin”,“plugin_id”:“mymattermostplugin”,“error”:“unable to start plugin: mymattermostplugin: fork/exec plugins/mymattermostplugin/plugin: permission denied”,“errorVerbose”:“fork/exec plugins/mymattermostplugin/plugin: permission denied\nunable to start plugin: mymattermostplugin

May I know how the permissions look like on your plugins directory? Please run the ls -lAh /opt/mattermost/plugins/ /opt/mattermost/prepackaged_plugins/ and provide the output here. For example, this is how it looks like on my end:

ahmaddanial@mattermost:/home/ubuntu# ls -lAh /opt/mattermost/plugins/ /opt/mattermost/prepackaged_plugins/
/opt/mattermost/plugins/:
total 48K
drwxr--r-- 3 mattermost mattermost 4.0K Nov 27 16:54 antivirus
drwxr--r-- 5 mattermost mattermost 4.0K Nov 27 16:54 com.github.manland.mattermost-plugin-gitlab
drwxr--r-- 3 mattermost mattermost 4.0K Nov 27 16:54 com.mattermost.aws-sns
drwxr--r-- 4 mattermost mattermost 4.0K Nov 27 16:54 com.mattermost.custom-attributes
drwxr--r-- 5 mattermost mattermost 4.0K Nov 27 16:54 com.mattermost.nps
drwxr--r-- 3 mattermost mattermost 4.0K Nov 27 16:54 com.mattermost.welcomebot
drwxr--r-- 5 mattermost mattermost 4.0K Nov 27 16:54 github
drwxr--r-- 4 mattermost mattermost 4.0K Nov 27 16:54 jenkins
drwxr--r-- 5 mattermost mattermost 4.0K Nov 27 16:54 jira
drwxr--r-- 4 mattermost mattermost 4.0K Dec 11 02:42 jitsi
drwxr--r-- 3 mattermost mattermost 4.0K Nov 27 16:54 mattermost-autolink
drwxr--r-- 5 mattermost mattermost 4.0K Nov 27 16:54 zoom

/opt/mattermost/prepackaged_plugins/:
total 99M
-rw-rw-r-- 1 mattermost mattermost 8.6M Nov 25 17:43 mattermost-plugin-antivirus-v0.1.1.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.6M Nov 25 17:42 mattermost-plugin-autolink-v1.1.1.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.8M Nov 25 17:43 mattermost-plugin-aws-SNS-v1.0.2.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.9M Nov 25 17:43 mattermost-plugin-custom-attributes-v1.0.2.tar.gz
-rw-rw-r-- 1 mattermost mattermost 9.7M Nov 25 17:43 mattermost-plugin-github-v0.11.0.tar.gz
-rw-rw-r-- 1 mattermost mattermost 9.4M Nov 25 17:43 mattermost-plugin-gitlab-v1.0.1.tar.gz
-rw-rw-r-- 1 mattermost mattermost 9.0M Nov 25 17:43 mattermost-plugin-jenkins-v1.0.0.tar.gz
-rw-rw-r-- 1 mattermost mattermost 9.7M Nov 25 17:43 mattermost-plugin-jira-v2.2.2.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.7M Nov 25 17:42 mattermost-plugin-nps-v1.0.3.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.6M Nov 25 17:43 mattermost-plugin-welcomebot-v1.1.1.tar.gz
-rw-rw-r-- 1 mattermost mattermost 8.8M Nov 25 17:42 mattermost-plugin-zoom-v1.1.2.tar.gz

Thans for your reply.
when I run ls -lAh /opt/mattermost/plugins /opt/mattermost/prepackaged_plugins/,the output is:

/opt/mattermost/plugins:
ls: cannot access '/opt/mattermost/plugins/jira': Permission denied
ls: cannot access '/opt/mattermost/plugins/mymattermostplugin': Permission denied
ls: cannot access '/opt/mattermost/plugins/zoom': Permission denied
total 0
d????????? ? ? ? ?             ? jira
d????????? ? ? ? ?             ? mymattermostplugin
d????????? ? ? ? ?             ? zoom

/opt/mattermost/prepackaged_plugins/:
total 54M
-rw-rw-r-- 1 mattermost mattermost 28M 10月 14 21:18 jira-2.2.2.tar.gz
-rw-rw-r-- 1 mattermost mattermost 26M 10月  3 04:55 zoom-1.1.1.tar.gz

And I try to run sudo ls -lAh /opt/mattermost/plugins /opt/mattermost/prepackaged_plugins/,the output is:

/opt/mattermost/plugins:
total 12K
drwxr--r-- 5 mattermost mattermost 4.0K 12月 17 09:21 jira
drwx------ 2 mattermost mattermost 4.0K 12月 16 15:53 mymattermostplugin
drwxr--r-- 5 mattermost mattermost 4.0K 12月 17 09:21 zoom

/opt/mattermost/prepackaged_plugins/:
total 54M
-rw-rw-r-- 1 mattermost mattermost 28M 10月 14 21:18 jira-2.2.2.tar.gz
-rw-rw-r-- 1 mattermost mattermost 26M 10月  3 04:55 zoom-1.1.1.tar.gz

I run these command in the ubuntu,and the user I login is an admin but isn’t a root user.And when I upload the plugin to the server,because I craft the code in my own windows10,so I directly login mattermost webapp in my windows10 and upload it via mattermost system console.Maybe that’s why I don’t have enough permission?

Hello, @xiagao

Based on the result you shared, we can see the different permission between mymattermostplugin and jira for example:

drwxr--r-- 5 mattermost mattermost 4.0K 12月 17 09:21 jira
drwx------ 2 mattermost mattermost 4.0K 12月 16 15:53 mymattermostplugin

Can you please adjust the permission accordingly and then verify that it is the same as jira and zoom before activating again?

sudo chmod g+r, o+r mymattermostplugin

Eventually, we should have something like this:

drwxr--r-- 5 mattermost mattermost 4.0K 12月 17 09:21 jira
drwxr--r-- 2 mattermost mattermost 4.0K 12月 16 15:53 mymattermostplugin

Please check on the Plugin Uploads Fail Even Though Uploads are Enabled article as well for further troubleshooting.

Thank you very much!! @ahmaddanial
I think my plugin is working after I add some permission to the plugin directory and mymattermostplugin directory and plugin exectuable file.

1 Like

Hi, @xiagao

You are most welcome. Shout out to @jasonblais for the assist as well!